From 525997f1df5afdea7f1ceffe0f4d57baef104a06 Mon Sep 17 00:00:00 2001 From: GaspardCulis Date: Tue, 5 Mar 2024 19:47:48 +0100 Subject: [PATCH] eww -> bar: Added vpn widget --- bar/eww/bar/style.scss | 4 ++++ bar/eww/bar/widget.yuck | 14 ++++++++++++-- bar/eww/scripts/vpn_status | 26 ++++++++++++++++++++++++++ 3 files changed, 42 insertions(+), 2 deletions(-) create mode 100755 bar/eww/scripts/vpn_status diff --git a/bar/eww/bar/style.scss b/bar/eww/bar/style.scss index f28dd8f..9b96737 100644 --- a/bar/eww/bar/style.scss +++ b/bar/eww/bar/style.scss @@ -21,6 +21,10 @@ color: $orange; } + .vpn.connected { + color: $green; + } + .connectivity { color: $yellow; } diff --git a/bar/eww/bar/widget.yuck b/bar/eww/bar/widget.yuck index 14e4ba5..55b9e45 100644 --- a/bar/eww/bar/widget.yuck +++ b/bar/eww/bar/widget.yuck @@ -3,13 +3,12 @@ (defpoll time :interval "10s" `date +" %H:%M  %a, %b %d"`) - (defpoll power_profile :interval "10s" :initial "" "~/.config/eww/scripts/power_profile") (defpoll gpu_status :initial "active" :interval "2s" "cat /sys/bus/pci/devices/0000:01:00.0/power/runtime_status") (defpoll power_now :initial "active" :interval "5s" "cat /sys/class/power_supply/BAT0/power_now") (defpoll energy_now :initial "active" :interval "5s" "cat /sys/class/power_supply/BAT0/energy_now") (defpoll refresh_rate :interval "10s" :initial "165" "~/.config/eww/scripts/refresh_rate") - +(defpoll vpn_status :interval "60s" :initial '{"connected": false}' "~/.config/eww/scripts/vpn_status") (deflisten connectivity :initial '{"status": "down"}' "~/.config/eww/scripts/get-connectivity wlan0") (deflisten bluetoothinfo :initial '{"count": 0}' "~/.config/eww/scripts/get-bluetooth-info") @@ -33,6 +32,16 @@ :text time) ) +(defwidget vpn [] + (button + :onclick `~/.config/eww/scripts/vpn_status toggle` + :timeout "10s" + (label + :class "vpn ${vpn_status.connected ? "connected" : "disconnected"}" + :text "${vpn_status.connected ? "󰯄 " : "󰦞 "}") + ) +) + (defwidget connectivity [] (eventbox :onclick "bash -c 'iwgtk &> /dev/null &'" @@ -156,6 +165,7 @@ (connectivity) (label :text "") ; Else container spacing rule doesn't apply (bluetooth) + (vpn) ) (container diff --git a/bar/eww/scripts/vpn_status b/bar/eww/scripts/vpn_status new file mode 100755 index 0000000..3e920ea --- /dev/null +++ b/bar/eww/scripts/vpn_status @@ -0,0 +1,26 @@ +#!/bin/dash + +config=OVH + +is_connected (){ + openvpn3 session-stats --config OVH > /dev/null 2>&1 + if [ $? -ne 0 ] ; then + echo "false" + else + echo "true" + fi +} + +connected="$(is_connected)" + +if [ "$1" = "toggle" ]; then + if [ "$connected" = "false" ]; then + openvpn3 session-start --config "$config" > /dev/null + else + openvpn3 session-manage --disconnect --config "$config" > /dev/null + fi + eww update vpn_status="{\"connected\": $(is_connected)}" + exit 0 +fi + +echo "{\"connected\": $(is_connected)}"