eww -> bar: Added vpn widget

This commit is contained in:
GaspardCulis 2024-03-05 19:47:48 +01:00
parent 99366040aa
commit 525997f1df
3 changed files with 42 additions and 2 deletions

View file

@ -21,6 +21,10 @@
color: $orange; color: $orange;
} }
.vpn.connected {
color: $green;
}
.connectivity { .connectivity {
color: $yellow; color: $yellow;
} }

View file

@ -3,13 +3,12 @@
(defpoll time :interval "10s" (defpoll time :interval "10s"
`date +" %H:%M  %a, %b %d"`) `date +" %H:%M  %a, %b %d"`)
(defpoll power_profile :interval "10s" :initial "" "~/.config/eww/scripts/power_profile") (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 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 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 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 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 connectivity :initial '{"status": "down"}' "~/.config/eww/scripts/get-connectivity wlan0")
(deflisten bluetoothinfo :initial '{"count": 0}' "~/.config/eww/scripts/get-bluetooth-info") (deflisten bluetoothinfo :initial '{"count": 0}' "~/.config/eww/scripts/get-bluetooth-info")
@ -33,6 +32,16 @@
:text time) :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 [] (defwidget connectivity []
(eventbox (eventbox
:onclick "bash -c 'iwgtk &> /dev/null &'" :onclick "bash -c 'iwgtk &> /dev/null &'"
@ -156,6 +165,7 @@
(connectivity) (connectivity)
(label :text "") ; Else container spacing rule doesn't apply (label :text "") ; Else container spacing rule doesn't apply
(bluetooth) (bluetooth)
(vpn)
) )
(container (container

26
bar/eww/scripts/vpn_status Executable file
View file

@ -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)}"