Merge pull request #9 from PiotrekB416/fix/network-service

Network service fixes
This commit is contained in:
2 * r + 2 * t 2025-06-09 12:47:06 +10:00 committed by GitHub
commit 1f7ce345ad
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 9 additions and 6 deletions

View file

@ -1,4 +1,4 @@
#!/bin/python #!/usr/bin/env python
import pyaudio import pyaudio
import numpy as np import numpy as np

View file

@ -23,29 +23,31 @@ Singleton {
Process { Process {
id: getNetworks id: getNetworks
running: true running: true
command: ["sh", "-c", `nmcli -g ACTIVE,SIGNAL,FREQ,SSID d w | jq -cR '[(inputs / ":") | select(.[3] | length >= 4)]'`] command: ["sh", "-c", `nmcli -g ACTIVE,SIGNAL,FREQ,SSID,BSSID d w | jq -ncR '[(inputs | split("(?<!\\\\\\\\):"; "g")) | select(.[3] | length >= 4)]'`]
stdout: SplitParser { stdout: SplitParser {
onRead: data => { onRead: data => {
const networks = JSON.parse(data).map(n => [n[0] === "yes", parseInt(n[1]), parseInt(n[2]), n[3]]); const networks = JSON.parse(data).map(n => [n[0] === "yes", parseInt(n[1]), parseInt(n[2]), n[3], n[4].replace(/\\/g, "")]);
const rNetworks = root.networks; const rNetworks = root.networks;
const destroyed = rNetworks.filter(rn => !networks.find(n => n[2] === rn.frequency && n[3] === rn.ssid)); const destroyed = rNetworks.filter(rn => !networks.find(n => n[2] === rn.frequency && n[3] === rn.ssid && n[4] === rn.bssid));
for (const network of destroyed) for (const network of destroyed)
rNetworks.splice(rNetworks.indexOf(network), 1).forEach(n => n.destroy()); rNetworks.splice(rNetworks.indexOf(network), 1).forEach(n => n.destroy());
for (const network of networks) { for (const network of networks) {
const match = rNetworks.find(n => n.frequency === network[2] && n.ssid === network[3]); const match = rNetworks.find(n => n.frequency === network[2] && n.ssid === network[3] && n.bssid === network[4]);
if (match) { if (match) {
match.active = network[0]; match.active = network[0];
match.strength = network[1]; match.strength = network[1];
match.frequency = network[2]; match.frequency = network[2];
match.ssid = network[3]; match.ssid = network[3];
match.bssid = network[4];
} else { } else {
rNetworks.push(apComp.createObject(root, { rNetworks.push(apComp.createObject(root, {
active: network[0], active: network[0],
strength: network[1], strength: network[1],
frequency: network[2], frequency: network[2],
ssid: network[3] ssid: network[3],
bssid: network[4]
})); }));
} }
} }
@ -55,6 +57,7 @@ Singleton {
component AccessPoint: QtObject { component AccessPoint: QtObject {
required property string ssid required property string ssid
required property string bssid
required property int strength required property int strength
required property int frequency required property int frequency
required property bool active required property bool active