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 import Quickshell.Hyprland
QuickToggleButton { QuickToggleButton {
toggled: Network.networkName.length > 0 && Network.networkName != "lo" toggled: Network.wifiEnabled
buttonIcon: Network.materialSymbol buttonIcon: Network.materialSymbol
onClicked: { onClicked: {
toggleNetwork.running = true toggleNetwork.running = true
+25 -8
View File
@@ -13,30 +13,32 @@ Singleton {
property bool wifi: true property bool wifi: true
property bool ethernet: false property bool ethernet: false
property int updateInterval: 1000
property bool wifiEnabled: false
property string networkName: "" property string networkName: ""
property int networkStrength property int networkStrength
property string materialSymbol: ethernet ? "lan" : property string materialSymbol: ethernet ? "lan" :
(Network.networkName.length > 0 && Network.networkName != "lo") ? ( wifiEnabled ? (
Network.networkStrength > 80 ? "signal_wifi_4_bar" : Network.networkStrength > 80 ? "signal_wifi_4_bar" :
Network.networkStrength > 60 ? "network_wifi_3_bar" : Network.networkStrength > 60 ? "network_wifi_3_bar" :
Network.networkStrength > 40 ? "network_wifi_2_bar" : Network.networkStrength > 40 ? "network_wifi_2_bar" :
Network.networkStrength > 20 ? "network_wifi_1_bar" : Network.networkStrength > 20 ? "network_wifi_1_bar" :
"signal_wifi_0_bar" "signal_wifi_0_bar"
) : "signal_wifi_off" ) : "signal_wifi_off"
function update() { function update() {
updateConnectionType.startCheck(); updateConnectionType.startCheck();
wifiStatusProcess.running = true
updateNetworkName.running = true; updateNetworkName.running = true;
updateNetworkStrength.running = true; updateNetworkStrength.running = true;
} }
Timer { Process {
interval: 10 id: subscriber
running: true running: true
repeat: true command: ["nmcli", "monitor"]
onTriggered: { stdout: SplitParser {
root.update(); onRead: root.update()
interval = root.updateInterval;
} }
} }
@@ -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";
}
}
}
} }