From 6956f354d1a2bb22927ceeaaa895727f8a13489f Mon Sep 17 00:00:00 2001 From: don philipe Date: Sat, 12 Aug 2023 11:27:15 +0200 Subject: [PATCH] Simple widget to show presence of VPN tun device --- vpn.lua | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 vpn.lua diff --git a/vpn.lua b/vpn.lua new file mode 100644 index 0000000..2caae3b --- /dev/null +++ b/vpn.lua @@ -0,0 +1,40 @@ +local awful = require("awful") +local gears = require("gears") +local wibox = require("wibox") + +local icon_vpn_noconn +local icon_vpn_conn + + +-- Create layout with widgets +local widget = wibox.widget { + { + id = "icon", + widget = wibox.widget.imagebox, + resize = true + }, + layout = wibox.layout.align.horizontal +} + +gears.timer { + timeout = 10, + autostart = true, + callback = function () + awful.spawn.easy_async_with_shell("ifconfig | grep \"tun.*:\"", + function (stdout, _, _, _) + if (stdout == "") then + widget.icon:set_image(icon_vpn_noconn) + else + widget.icon:set_image(icon_vpn_conn) + end + end) + end +} + +-- Widget function that is available from the outside. +function widget.set_icons(vpn_noconn, vpn_conn) + icon_vpn_noconn = vpn_noconn + icon_vpn_conn = vpn_conn +end + +return widget