-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathwifi.lua
36 lines (29 loc) · 879 Bytes
/
wifi.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
-- module: wifi - notify on wifi changes
local m = {}
-- keep track of the previously connected network
local lastNetwork = hs.wifi.currentNetwork()
-- callback called when wifi network changes
local function ssidChangedCallback()
local newNetwork = hs.wifi.currentNetwork()
-- send notification if we're on a different network than we were before
if lastNetwork ~= newNetwork then
hs.notify.new({
title = 'Wi-Fi Status',
subTitle = newNetwork and 'Network:' or 'Disconnected',
informativeText = newNetwork,
contentImage = m.cfg.icon,
autoWithdraw = true,
hasActionButton = false,
}):send()
lastNetwork = newNetwork
end
end
function m.start()
m.watcher = hs.wifi.watcher.new(ssidChangedCallback)
m.watcher:start()
end
function m.stop()
m.watcher:stop()
m.watcher = nil
end
return m