refactor(eww -> bar): Upgraded "connectivity" widget and script
Yoinked from Ahurac's dotfiles
This commit is contained in:
parent
bb6219ab6d
commit
324035af6d
2 changed files with 76 additions and 15 deletions
|
@ -1,5 +1,15 @@
|
||||||
; Static vars
|
; Static vars
|
||||||
(defvar GIGA 1073741824)
|
(defvar GIGA 1073741824)
|
||||||
|
(defvar network-icon '{
|
||||||
|
"disconnected": "",
|
||||||
|
"ethernet": "",
|
||||||
|
"wifi-terrible": "",
|
||||||
|
"wifi-bad": "",
|
||||||
|
"wifi-mediocre": "",
|
||||||
|
"wifi-good": "",
|
||||||
|
"wifi-excellent": "",
|
||||||
|
"tethering": ""
|
||||||
|
}')
|
||||||
|
|
||||||
(defpoll time :interval "10s"
|
(defpoll time :interval "10s"
|
||||||
`date +" %H:%M %a, %b %d"`)
|
`date +" %H:%M %a, %b %d"`)
|
||||||
|
@ -10,7 +20,7 @@
|
||||||
(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")
|
(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 '{"state": "disconnected"}' "~/.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")
|
||||||
(deflisten hypr :initial '{"spaces": [], "current": 0, "title": ""}' "~/.config/eww/scripts/hypr/hyprstatus")
|
(deflisten hypr :initial '{"spaces": [], "current": 0, "title": ""}' "~/.config/eww/scripts/hypr/hyprstatus")
|
||||||
|
|
||||||
|
@ -47,7 +57,17 @@
|
||||||
:onclick "bash -c 'iwgtk &> /dev/null &'"
|
:onclick "bash -c 'iwgtk &> /dev/null &'"
|
||||||
(label
|
(label
|
||||||
:class "connectivity"
|
:class "connectivity"
|
||||||
:text " ${connectivity.status == "down" ? "down" : connectivity.ssid}"
|
:text "${
|
||||||
|
connectivity.state == "wireless"
|
||||||
|
? network-icon["wifi-${connectivity.wifi.signal}"]
|
||||||
|
: network-icon[connectivity.state]
|
||||||
|
} ${
|
||||||
|
connectivity.state == "disconnected" ? "No network" :
|
||||||
|
connectivity.state == "ethernet" ? "Ethernet" :
|
||||||
|
connectivity.state == "wireless" ? connectivity.wifi.ssid :
|
||||||
|
connectivity.state == "tethering" ? "USB tethering" : ''
|
||||||
|
}"
|
||||||
|
:tooltip "${connectivity.ip.local}"
|
||||||
:limit-width 14)
|
:limit-width 14)
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
|
@ -1,18 +1,59 @@
|
||||||
#!/bin/dash
|
#!/bin/dash
|
||||||
|
|
||||||
if=$1
|
print_state() {
|
||||||
|
case "$1" in
|
||||||
status (){
|
eth*)
|
||||||
status=$(cat /sys/class/net/wlan0/operstate)
|
echo ethernet
|
||||||
|
;;
|
||||||
if [ "$status" != "down" ]; then
|
wlan*)
|
||||||
ssid="$(iw dev wlan0 link | grep SSID | cut -d':' -f2)"
|
echo wireless
|
||||||
fi
|
;;
|
||||||
|
usb*)
|
||||||
echo "{\"status\": \"$status\", \"ssid\": \"$ssid\"}"
|
echo tethering
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
echo disconnected
|
||||||
|
;;
|
||||||
|
esac
|
||||||
}
|
}
|
||||||
|
|
||||||
status
|
wifi_strength() {
|
||||||
iwevent 2> /dev/null | while read -r line; do
|
if [ "$1" -le -80 ]; then echo terrible
|
||||||
status
|
elif [ "$1" -le -70 ]; then echo bad
|
||||||
|
elif [ "$1" -le -60 ]; then echo mediocre
|
||||||
|
elif [ "$1" -le -40 ]; then echo good
|
||||||
|
else echo excellent
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
print_infos() {
|
||||||
|
if [ -n "$1" ]; then
|
||||||
|
route_line=$(ip route show dev "$1" | awk '($1 == "default") { print }')
|
||||||
|
|
||||||
|
printf ',"ip":{"local":"%s","gateway":"%s"}' \
|
||||||
|
"$(echo "$route_line" | awk '{ print $7 }')" \
|
||||||
|
"$(echo "$route_line" | awk '{ print $3 }')"
|
||||||
|
|
||||||
|
if [ "$state" = wireless ]; then
|
||||||
|
signal=$(iw dev "$1" link | awk '($1 == "signal:") { print $2}')
|
||||||
|
printf ',"wifi":{"signal":"%s","ssid":"%s"}' \
|
||||||
|
"$(wifi_strength "$signal")" \
|
||||||
|
"$(iw dev wlan0 info | grep '^\s*ssid ' | xargs | cut -d \ -f 2-)"
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
print_network_status() {
|
||||||
|
device=$(ip route | awk '($1 == "default") { print $5 }')
|
||||||
|
state=$(print_state "$device")
|
||||||
|
|
||||||
|
printf '{"state":"%s"%s}\n' \
|
||||||
|
"$state" \
|
||||||
|
"$(print_infos "$device")"
|
||||||
|
}
|
||||||
|
|
||||||
|
print_network_status
|
||||||
|
tail -f -n 0 /run/dhcpcd/log /var/log/iwd/current | \
|
||||||
|
while read -r _unused; do
|
||||||
|
print_network_status
|
||||||
done
|
done
|
||||||
|
|
Loading…
Reference in a new issue