config/eww ahrc-laptop : mise à jour widget réseau

This commit is contained in:
Ahurac 2024-05-30 15:17:59 +02:00
parent 2cfd4c662e
commit d9c824ddff
2 changed files with 16 additions and 9 deletions

View file

@ -19,7 +19,7 @@
) )
(deflisten network (deflisten network
:initial '{"state":"disconnected","infos":{}}' :initial '{"state":"disconnect"}'
"listen/network" "listen/network"
) )
@ -77,7 +77,18 @@
; (defwidget sound [] "") ; (defwidget sound [] "")
(defwidget network [] (defwidget network []
"${network.state == "wireless" ? "${network-icon["wifi-${network.infos.signal}"]} ${network.infos.ssid}" : "${network-icon[network.state]}"}" "${
network.state == "wireless"
? network-icon["wifi-${network.wifi.signal}"]
: network-icon[network.state]
} ${
network.state == "disconnected"
? "no network" :
network.state == "ethernet"
? "wired" :
network.state == "wireless"
? network.wifi.ssid : ''
}"
) )
(defwidget battery [] (defwidget battery []

View file

@ -26,31 +26,27 @@ wifi_strength() {
} }
print_infos() { print_infos() {
printf \{
if [ -n "$1" ]; then if [ -n "$1" ]; then
route_line=$(ip route show dev "$1" | awk '($1 == "default") { print }') route_line=$(ip route show dev "$1" | awk '($1 == "default") { print }')
printf '"ip":"%s","gateway":"%s"' \ printf ',"ip":{"local":"%s","gateway":"%s"}' \
"$(echo "$route_line" | awk '{ print $7 }')" \ "$(echo "$route_line" | awk '{ print $7 }')" \
"$(echo "$route_line" | awk '{ print $3 }')" "$(echo "$route_line" | awk '{ print $3 }')"
if [ "$state" = wireless ]; then if [ "$state" = wireless ]; then
signal=$(iw dev "$1" link | awk '($1 == "signal:") { print $2}') signal=$(iw dev "$1" link | awk '($1 == "signal:") { print $2}')
printf ',"signal":"%s","ssid":"%s"' \ printf ',"wifi":{"signal":"%s","ssid":"%s"}' \
"$(wifi_strength "$signal")" \ "$(wifi_strength "$signal")" \
"$(iw dev wlan0 info | grep '^\s*ssid ' | xargs | cut -d \ -f 2-)" "$(iw dev wlan0 info | grep '^\s*ssid ' | xargs | cut -d \ -f 2-)"
fi fi
fi fi
printf '}\n'
} }
print_network_status() { print_network_status() {
device=$(ip route | awk '($1 == "default") { print $5 }') device=$(ip route | awk '($1 == "default") { print $5 }')
state=$(print_state "$device") state=$(print_state "$device")
printf '{"state":"%s","infos":%s}\n' \ printf '{"state":"%s"%s}\n' \
"$state" \ "$state" \
"$(print_infos "$device")" "$(print_infos "$device")"
} }