network: no more polling, fix sidebar toggle enabled state

This commit is contained in:
end-4
2025-08-26 20:56:32 +07:00
parent c579dce2cf
commit 813f02604e
2 changed files with 26 additions and 9 deletions
@@ -10,7 +10,7 @@ import Quickshell.Io
import Quickshell.Hyprland
QuickToggleButton {
toggled: Network.networkName.length > 0 && Network.networkName != "lo"
toggled: Network.wifiEnabled
buttonIcon: Network.materialSymbol
onClicked: {
toggleNetwork.running = true
+25 -8
View File
@@ -13,30 +13,32 @@ Singleton {
property bool wifi: true
property bool ethernet: false
property int updateInterval: 1000
property bool wifiEnabled: false
property string networkName: ""
property int networkStrength
property string materialSymbol: ethernet ? "lan" :
(Network.networkName.length > 0 && Network.networkName != "lo") ? (
wifiEnabled ? (
Network.networkStrength > 80 ? "signal_wifi_4_bar" :
Network.networkStrength > 60 ? "network_wifi_3_bar" :
Network.networkStrength > 40 ? "network_wifi_2_bar" :
Network.networkStrength > 20 ? "network_wifi_1_bar" :
"signal_wifi_0_bar"
) : "signal_wifi_off"
function update() {
updateConnectionType.startCheck();
wifiStatusProcess.running = true
updateNetworkName.running = true;
updateNetworkStrength.running = true;
}
Timer {
interval: 10
Process {
id: subscriber
running: true
repeat: true
onTriggered: {
root.update();
interval = root.updateInterval;
command: ["nmcli", "monitor"]
stdout: SplitParser {
onRead: root.update()
}
}
@@ -90,4 +92,19 @@ Singleton {
}
}
}
Process {
id: wifiStatusProcess
command: ["nmcli", "radio", "wifi"]
Component.onCompleted: running = true
environment: ({
LANG: "C",
LC_ALL: "C"
})
stdout: StdioCollector {
onStreamFinished: {
root.wifiEnabled = text.trim() === "enabled";
}
}
}
}