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 vpn_status :interval "60s" :initial '{"connected": false}' "~/.config/eww/scripts/vpn_status")
|
||||
|
||||
(deflisten connectivity :initial '{"state": "disconnected"}' "~/.config/eww/scripts/get-connectivity wlan0")
|
||||
(deflisten bluetoothinfo :initial '{"count": 0}' "~/.config/eww/scripts/get-bluetooth-info")
|
||||
(deflisten connectivity :initial '{"bluetooth": {}, "network": {}}' "~/.config/eww/scripts/get-connectivity-info")
|
||||
(deflisten hypr :initial '{"spaces": [], "current": 0, "title": ""}' "~/.config/eww/scripts/hypr/hyprstatus")
|
||||
|
||||
(deflisten volume :initial "{}" "~/.config/eww/scripts/get-volume")
|
||||
|
@ -58,14 +57,14 @@
|
|||
(label
|
||||
:class "connectivity"
|
||||
:text "${
|
||||
connectivity.state == "wireless"
|
||||
? network-icon["wifi-${connectivity.wifi.signal}"]
|
||||
: network-icon[connectivity.state]
|
||||
connectivity.network.state == "wireless"
|
||||
? network-icon["wifi-${connectivity.network.wifi.signal}"]
|
||||
: network-icon[connectivity.network.state]
|
||||
} ${
|
||||
connectivity.state == "disconnected" ? "No network" :
|
||||
connectivity.state == "ethernet" ? "Ethernet" :
|
||||
connectivity.state == "wireless" ? connectivity.wifi.ssid :
|
||||
connectivity.state == "tethering" ? "USB tethering" : ''
|
||||
connectivity.network.state == "disconnected" ? "No network" :
|
||||
connectivity.network.state == "ethernet" ? "Ethernet" :
|
||||
connectivity.network.state == "wireless" ? connectivity.network.wifi.ssid :
|
||||
connectivity.network.state == "tethering" ? "USB tethering" : ''
|
||||
}"
|
||||
:limit-width 14)
|
||||
)
|
||||
|
@ -76,7 +75,7 @@
|
|||
:onclick "bash -c 'blueman-manager &> /dev/null &'"
|
||||
(label
|
||||
: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 = [
|
||||
pkgs.eww
|
||||
# Script dependencies
|
||||
pkgs.iw
|
||||
pkgs.jq
|
||||
pkgs.dash
|
||||
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
|
||||
|
||||
print_state() {
|
||||
|
||||
print_network_state() {
|
||||
case "$1" in
|
||||
eth*)
|
||||
echo ethernet
|
||||
|
@ -26,7 +27,7 @@ wifi_strength() {
|
|||
fi
|
||||
}
|
||||
|
||||
print_infos() {
|
||||
print_network_infos() {
|
||||
if [ -n "$1" ]; then
|
||||
route_line=$(ip route show dev "$1" | awk '($1 == "default") { print }')
|
||||
|
||||
|
@ -45,15 +46,27 @@ print_infos() {
|
|||
|
||||
print_network_status() {
|
||||
device=$(ip route | awk '($1 == "default") { print $5 }')
|
||||
state=$(print_state "$device")
|
||||
state=$(print_network_state "$device")
|
||||
|
||||
printf '{"state":"%s"%s}\n' \
|
||||
"$state" \
|
||||
"$(print_infos "$device")"
|
||||
"$(print_network_infos "$device")"
|
||||
}
|
||||
|
||||
print_network_status
|
||||
tail -f -n 0 /run/dhcpcd/log /var/log/iwd/current | \
|
||||
while read -r _unused; do
|
||||
print_network_status
|
||||
print_bluetooth_status (){
|
||||
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}\"}"
|
||||
}
|
||||
|
||||
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
|
Loading…
Reference in a new issue