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;
}
.vpn.connected {
color: $green;
}
.connectivity {
color: $yellow;
}

View file

@ -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

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