pragma Singleton import Quickshell import Quickshell.Networking import QtQuick Singleton { id: root property bool active: false readonly property list connectedNetworks: networks.filter(n => n.connected) property Network connectingNetwork readonly property list devices: Networking.devices.values property Network failedNetwork readonly property list knownNetworks: networks.filter(n => n.known && !n.connected) readonly property list networks: { const list = []; for (const d of wifiDevices) { for (const n of d.networks.values) { if (!list.includes(n)) list.push(n); } } return list; } property bool scanning: false readonly property list unknownNetworks: networks.filter(n => !n.known) readonly property list wifiDevices: devices.filter(d => wifiDevice(d)) readonly property bool wifiEnabled: Networking.wifiEnabled signal networkConnected function isSecure(security): bool { return (security === WifiSecurityType.WpaPsk || security === WifiSecurityType.Wpa2Psk || security === WifiSecurityType.Sae); } function requestConnect(network: Network, secret = undefined): void { connectingNetwork = network; if (secret === undefined || secret === "") { network.connect(); } else { (network as WifiNetwork).connectWithPsk(secret); } } function setScan(value: bool): void { for (const d of wifiDevices) { d.scannerEnabled = value; } } function setWifi(value: bool): void { Networking.wifiEnabled = value; } function wifiDevice(dev): bool { return dev.type === DeviceType.Wifi; } onActiveChanged: { for (const d of wifiDevices) d.scannerEnabled = active; } Timer { id: flushFailed interval: 5000 running: root.failedNetwork onTriggered: { root.failedNetwork = null; } } Timer { id: checkConnection interval: 500 repeat: true running: root.connectingNetwork onTriggered: { var completedNetwork; switch (root.connectingNetwork.state) { case ConnectionState.Connecting: break; case ConnectionState.Connected: completedNetwork = root.connectingNetwork; root.networkConnected(); break; case ConnectionState.Disconnected: root.failedNetwork = root.connectingNetwork; completedNetwork = root.connectingNetwork; break; } if (completedNetwork) { root.connectingNetwork = null; } } } Timer { interval: 10000 running: checkConnection.running onTriggered: { root.failedNetwork = root.connectingNetwork; root.connectingNetwork = null; } } }