diff options
| author | 2 * r + 2 * t <61896496+soramanew@users.noreply.github.com> | 2025-05-01 13:34:37 +1000 |
|---|---|---|
| committer | 2 * r + 2 * t <61896496+soramanew@users.noreply.github.com> | 2025-05-01 13:34:37 +1000 |
| commit | eb367cea43c0937f1b6578196dbb3e5f4800f343 (patch) | |
| tree | 31ff049953038a3c627c53aa7938d1505b45486a /services/Network.qml | |
| parent | bar: workspaces scroll specialws (diff) | |
| download | caelestia-shell-eb367cea43c0937f1b6578196dbb3e5f4800f343.tar.gz caelestia-shell-eb367cea43c0937f1b6578196dbb3e5f4800f343.tar.bz2 caelestia-shell-eb367cea43c0937f1b6578196dbb3e5f4800f343.zip | |
feat: get networks
Also fix bluetooth
Diffstat (limited to 'services/Network.qml')
| -rw-r--r-- | services/Network.qml | 43 |
1 files changed, 34 insertions, 9 deletions
diff --git a/services/Network.qml b/services/Network.qml index a65ab1e..67bcb48 100644 --- a/services/Network.qml +++ b/services/Network.qml @@ -7,9 +7,8 @@ import QtQuick Singleton { id: root - readonly property AccessPoint active: AccessPoint { - active: true - } + readonly property list<AccessPoint> networks: [] + readonly property AccessPoint active: networks.find(n => n.active) ?? null reloadableId: "network" @@ -24,14 +23,34 @@ Singleton { Process { id: getNetworks running: true - command: ["nmcli", "-g", "ACTIVE,SIGNAL,FREQ,SSID", "d", "w"] + command: ["sh", "-c", `nmcli -g ACTIVE,SIGNAL,FREQ,SSID d w | jq -cR '[(inputs / ":") | select(.[3] | length >= 4)]'`] stdout: SplitParser { onRead: data => { - const [active, strength, frequency, ssid] = data.split(":"); - if (active === "yes") { - root.active.ssid = ssid; - root.active.strength = parseInt(strength); - root.active.frequency = parseInt(frequency); + const networks = JSON.parse(data).map(n => [n[0] === "yes", parseInt(n[1]), parseInt(n[2]), n[3]]); + const rNetworks = root.networks; + + const len = rNetworks.length; + for (let i = 0; i < len; i++) { + const network = rNetworks[i]; + if (!networks.find(n => n[2] === network?.frequency && n[3] === network?.ssid)) + rNetworks.splice(i, 1); + } + + for (const network of networks) { + const match = rNetworks.find(n => n.frequency === network[2] && n.ssid === network[3]); + if (match) { + match.active = network[0]; + match.strength = network[1]; + match.frequency = network[2]; + match.ssid = network[3]; + } else { + rNetworks.push(apComp.createObject(root, { + active: network[0], + strength: network[1], + frequency: network[2], + ssid: network[3] + })); + } } } } @@ -43,4 +62,10 @@ Singleton { property int frequency property bool active } + + Component { + id: apComp + + AccessPoint {} + } } |