network: implement toggling in service

This commit is contained in:
end-4
2025-08-26 21:07:00 +07:00
parent 813f02604e
commit f38c7bffed
2 changed files with 12 additions and 12 deletions
@@ -12,22 +12,11 @@ import Quickshell.Hyprland
QuickToggleButton {
toggled: Network.wifiEnabled
buttonIcon: Network.materialSymbol
onClicked: {
toggleNetwork.running = true
}
onClicked: Network.toggleWifi()
altAction: () => {
Quickshell.execDetached(["bash", "-c", `${Network.ethernet ? Config.options.apps.networkEthernet : Config.options.apps.network}`])
GlobalStates.sidebarRightOpen = false
}
Process {
id: toggleNetwork
command: ["bash", "-c", "nmcli radio wifi | grep -q enabled && nmcli radio wifi off || nmcli radio wifi on"]
onRunningChanged: {
if(!running) {
Network.update()
}
}
}
StyledToolTip {
content: Translation.tr("%1 | Right-click to configure").arg(Network.networkName)
}
@@ -26,6 +26,17 @@ Singleton {
"signal_wifi_0_bar"
) : "signal_wifi_off"
// Control
function toggleWifi(): void {
const cmd = wifiEnabled ? "off" : "on";
enableWifiProc.exec(["nmcli", "radio", "wifi", cmd]);
}
Process {
id: enableWifiProc
}
// Status update
function update() {
updateConnectionType.startCheck();
wifiStatusProcess.running = true