-
Notifications
You must be signed in to change notification settings - Fork 41
Expand file tree
/
Copy pathinternet.lua
More file actions
76 lines (66 loc) · 2 KB
/
internet.lua
File metadata and controls
76 lines (66 loc) · 2 KB
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
local wibox = require("wibox")
local awful = require("awful")
local beautiful = require("beautiful")
local naughty = require("naughty")
local gears = require("gears")
local module_path = (...):match ("(.+/)[^/]+$") or ""
local theme = beautiful.get()
local internet = {}
local function worker(args)
local args = args or {}
local widget = wibox.container.background()
-- Icons made by http://www.flaticon.com/authors/maxim-basinski from www.flaticon.com
local ICON_DIR = awful.util.getdir("config").."/"..module_path.."/net_widgets/icons/"
local yes_internet = wibox.widget {
{
widget = wibox.widget.imagebox,
image = ICON_DIR.."internet.png",
resize = false,
},
layout = wibox.container.margin(brightness_icon, 0, 0, 2)
}
local no_internet = wibox.widget {
{
widget = wibox.widget.imagebox,
image = ICON_DIR.."internet_na.png",
resize = false,
},
layout = wibox.container.margin(brightness_icon, 0, 0, 2)
}
-- Settings
local timeout = args.timeout or 5
local onclick = args.onclick
local showconnected = args.showconnected or false
local connected = false
widget:set_widget(no_internet)
local function net_update()
connected = false
awful.spawn.easy_async("bash -c \"nc -z 8.8.8.8 53 >/dev/null 2>&1\"",
function(_, _, _, exit_code)
if (exit_code == 0) then
connected = true
end
if connected then
if showconnected then
widget:set_widget(yes_internet)
else
widget:set_widget(nil)
end
else
widget:set_widget(no_internet)
end
end)
return true
end
net_update()
gears.timer.start_new(timeout, net_update)
-- Bind onclick event function
if onclick then
widget:buttons(awful.util.table.join(
awful.button({}, 1, function() awful.util.spawn(onclick) end)
))
end
return widget
end
return setmetatable(internet, {__call = function(_,...) return worker(...) end})
-- vim: set ts=2 sw=2 sts=2: