feat: get networks
Also fix bluetooth
This commit is contained in:
parent
a38de28e72
commit
eb367cea43
3 changed files with 37 additions and 12 deletions
|
|
@ -18,7 +18,7 @@ StyledRect {
|
||||||
id: network
|
id: network
|
||||||
|
|
||||||
animate: true
|
animate: true
|
||||||
text: Icons.getNetworkIcon(Network.active.strength)
|
text: Icons.getNetworkIcon(Network.active?.strength ?? 0)
|
||||||
color: root.colour
|
color: root.colour
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -40,13 +40,13 @@ Singleton {
|
||||||
command: ["fish", "-c", `for a in (bluetoothctl devices | cut -d ' ' -f 2); bluetoothctl info $a | jq -R 'reduce (inputs / ":") as [$key, $value] ({}; .[$key | ltrimstr("\t")] = ($value | ltrimstr(" ")))' | jq -c --arg addr $a '.Address = $addr'; end | jq -sc`]
|
command: ["fish", "-c", `for a in (bluetoothctl devices | cut -d ' ' -f 2); bluetoothctl info $a | jq -R 'reduce (inputs / ":") as [$key, $value] ({}; .[$key | ltrimstr("\t")] = ($value | ltrimstr(" ")))' | jq -c --arg addr $a '.Address = $addr'; end | jq -sc`]
|
||||||
stdout: SplitParser {
|
stdout: SplitParser {
|
||||||
onRead: data => {
|
onRead: data => {
|
||||||
const devices = JSON.parse(data).filter(d => d.name);
|
const devices = JSON.parse(data).filter(d => d.Name);
|
||||||
const rDevices = root.devices;
|
const rDevices = root.devices;
|
||||||
|
|
||||||
const len = rDevices.length;
|
const len = rDevices.length;
|
||||||
for (let i = 0; i < len; i++) {
|
for (let i = 0; i < len; i++) {
|
||||||
const device = rDevices[i];
|
const device = rDevices[i];
|
||||||
if (!devices.find(d => d.address === device?.Address))
|
if (!devices.find(d => d.Address === device?.address))
|
||||||
rDevices.splice(i, 1);
|
rDevices.splice(i, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -7,9 +7,8 @@ import QtQuick
|
||||||
Singleton {
|
Singleton {
|
||||||
id: root
|
id: root
|
||||||
|
|
||||||
readonly property AccessPoint active: AccessPoint {
|
readonly property list<AccessPoint> networks: []
|
||||||
active: true
|
readonly property AccessPoint active: networks.find(n => n.active) ?? null
|
||||||
}
|
|
||||||
|
|
||||||
reloadableId: "network"
|
reloadableId: "network"
|
||||||
|
|
||||||
|
|
@ -24,14 +23,34 @@ Singleton {
|
||||||
Process {
|
Process {
|
||||||
id: getNetworks
|
id: getNetworks
|
||||||
running: true
|
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 {
|
stdout: SplitParser {
|
||||||
onRead: data => {
|
onRead: data => {
|
||||||
const [active, strength, frequency, ssid] = data.split(":");
|
const networks = JSON.parse(data).map(n => [n[0] === "yes", parseInt(n[1]), parseInt(n[2]), n[3]]);
|
||||||
if (active === "yes") {
|
const rNetworks = root.networks;
|
||||||
root.active.ssid = ssid;
|
|
||||||
root.active.strength = parseInt(strength);
|
const len = rNetworks.length;
|
||||||
root.active.frequency = parseInt(frequency);
|
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 int frequency
|
||||||
property bool active
|
property bool active
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Component {
|
||||||
|
id: apComp
|
||||||
|
|
||||||
|
AccessPoint {}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue