refactor(eww): Merged bluetooth and network scripts into one connectivity script
Fixes issues with dbus monitoring
This commit is contained in:
parent
33143c3e3e
commit
82b06820f2
4 changed files with 31 additions and 30 deletions
|
@ -20,8 +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 '{"state": "disconnected"}' "~/.config/eww/scripts/get-connectivity wlan0")
|
(deflisten connectivity :initial '{"bluetooth": {}, "network": {}}' "~/.config/eww/scripts/get-connectivity-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")
|
||||||
|
|
||||||
(deflisten volume :initial "{}" "~/.config/eww/scripts/get-volume")
|
(deflisten volume :initial "{}" "~/.config/eww/scripts/get-volume")
|
||||||
|
@ -58,14 +57,14 @@
|
||||||
(label
|
(label
|
||||||
:class "connectivity"
|
:class "connectivity"
|
||||||
:text "${
|
:text "${
|
||||||
connectivity.state == "wireless"
|
connectivity.network.state == "wireless"
|
||||||
? network-icon["wifi-${connectivity.wifi.signal}"]
|
? network-icon["wifi-${connectivity.network.wifi.signal}"]
|
||||||
: network-icon[connectivity.state]
|
: network-icon[connectivity.network.state]
|
||||||
} ${
|
} ${
|
||||||
connectivity.state == "disconnected" ? "No network" :
|
connectivity.network.state == "disconnected" ? "No network" :
|
||||||
connectivity.state == "ethernet" ? "Ethernet" :
|
connectivity.network.state == "ethernet" ? "Ethernet" :
|
||||||
connectivity.state == "wireless" ? connectivity.wifi.ssid :
|
connectivity.network.state == "wireless" ? connectivity.network.wifi.ssid :
|
||||||
connectivity.state == "tethering" ? "USB tethering" : ''
|
connectivity.network.state == "tethering" ? "USB tethering" : ''
|
||||||
}"
|
}"
|
||||||
:limit-width 14)
|
:limit-width 14)
|
||||||
)
|
)
|
||||||
|
@ -76,7 +75,7 @@
|
||||||
:onclick "bash -c 'blueman-manager &> /dev/null &'"
|
:onclick "bash -c 'blueman-manager &> /dev/null &'"
|
||||||
(label
|
(label
|
||||||
:class "bluetooth"
|
:class "bluetooth"
|
||||||
:text " ${bluetoothinfo.count > 0 ? bluetoothinfo.count : bluetoothinfo.power}")
|
:text " ${connectivity.bluetooth.count > 0 ? connectivity.bluetooth.count : connectivity.bluetooth.power}")
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
@ -11,6 +11,7 @@
|
||||||
home.packages = [
|
home.packages = [
|
||||||
pkgs.eww
|
pkgs.eww
|
||||||
# Script dependencies
|
# Script dependencies
|
||||||
|
pkgs.iw
|
||||||
pkgs.jq
|
pkgs.jq
|
||||||
pkgs.dash
|
pkgs.dash
|
||||||
pkgs.socat
|
pkgs.socat
|
||||||
|
|
|
@ -1,12 +0,0 @@
|
||||||
#!/usr/bin/env dash
|
|
||||||
|
|
||||||
info (){
|
|
||||||
power=$(bluetoothctl show | grep Powered | awk '{print $2}' | sed 's/yes/on/g; s/no/off/g')
|
|
||||||
count=$(bluetoothctl devices Connected | wc -l)
|
|
||||||
echo "{\"power\": \"${power}\", \"count\": \"${count}\"}"
|
|
||||||
}
|
|
||||||
|
|
||||||
info
|
|
||||||
dbus-monitor --system "sender=:1.3" | while read -r line; do
|
|
||||||
info
|
|
||||||
done
|
|
|
@ -1,6 +1,7 @@
|
||||||
#!/usr/bin/env dash
|
#!/usr/bin/env dash
|
||||||
|
|
||||||
print_state() {
|
|
||||||
|
print_network_state() {
|
||||||
case "$1" in
|
case "$1" in
|
||||||
eth*)
|
eth*)
|
||||||
echo ethernet
|
echo ethernet
|
||||||
|
@ -26,7 +27,7 @@ wifi_strength() {
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
print_infos() {
|
print_network_infos() {
|
||||||
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 }')
|
||||||
|
|
||||||
|
@ -45,15 +46,27 @@ print_infos() {
|
||||||
|
|
||||||
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_network_state "$device")
|
||||||
|
|
||||||
printf '{"state":"%s"%s}\n' \
|
printf '{"state":"%s"%s}\n' \
|
||||||
"$state" \
|
"$state" \
|
||||||
"$(print_infos "$device")"
|
"$(print_network_infos "$device")"
|
||||||
}
|
}
|
||||||
|
|
||||||
print_network_status
|
print_bluetooth_status (){
|
||||||
tail -f -n 0 /run/dhcpcd/log /var/log/iwd/current | \
|
power=$(bluetoothctl show | grep Powered | awk '{print $2}' | sed 's/yes/on/g; s/no/off/g')
|
||||||
while read -r _unused; do
|
count=$(bluetoothctl devices Connected | wc -l)
|
||||||
print_network_status
|
echo "{\"power\": \"${power}\", \"count\": \"${count}\"}"
|
||||||
|
}
|
||||||
|
|
||||||
|
print_connectivity_info () {
|
||||||
|
network="$(print_network_status)"
|
||||||
|
bluetooth="$(print_bluetooth_status)"
|
||||||
|
|
||||||
|
echo "{\"bluetooth\": ${bluetooth}, \"network\": ${network}}"
|
||||||
|
}
|
||||||
|
|
||||||
|
print_connectivity_info
|
||||||
|
dbus-monitor --system "interface=org.freedesktop.DBus.ObjectManager" 2> /dev/null | while read -r line; do
|
||||||
|
print_connectivity_info
|
||||||
done
|
done
|
Loading…
Reference in a new issue