pragma Singleton import QtQuick import Quickshell import Quickshell.Networking Singleton { id: root property var backend: Networking readonly property var devices: backend.devices.values readonly property var wifiDevices: devices.filter(d => d.type === DeviceType.Wifi) readonly property var networks: devices.reduce((all, d) => all.concat(d.networks.values), []) readonly property bool available: backend.backend === NetworkBackendType.NetworkManager && wifiDevices.length > 0 readonly property bool enabled: backend.wifiEnabled readonly property string summary: networks.filter(n => n.connected).map(n => n.name).join(", ") || (devices.some(d => d.connected) ? "Connected" : "Disconnected") property bool scanning: false property var pending: null property string error: "" onScanningChanged: syncScan() onWifiDevicesChanged: syncScan() function syncScan() { wifiDevices.forEach(d => d.scannerEnabled = scanning); } function toggle() { if (!available || !backend.wifiHardwareEnabled) return false; error = ""; backend.wifiEnabled = !enabled; return true; } function connectNetwork(network, password) { if (!network || pending || network.stateChanging) return false; error = ""; pending = network; timeout.restart(); if (network.connected) network.disconnect(); else if (password) network.connectWithPsk(password); else network.connect(); return true; } Connections { target: root.pending function onConnectionFailed(reason) { root.error = ConnectionFailReason.toString(reason); timeout.stop(); root.pending = null; } function onStateChanged() { if (root.pending && !root.pending.stateChanging) { timeout.stop(); root.pending = null; } } } Timer { id: timeout interval: 20000 onTriggered: { root.error = "No connection confirmation received. Check the network manager."; root.pending = null; } } }