internal: format network
Also use exec, onExited and StdioCollector
This commit is contained in:
parent
5405400bd1
commit
1f4ec53f8f
1 changed files with 32 additions and 36 deletions
|
|
@ -10,42 +10,37 @@ Singleton {
|
|||
readonly property list<AccessPoint> networks: []
|
||||
readonly property AccessPoint active: networks.find(n => n.active) ?? null
|
||||
property bool wifiEnabled: true
|
||||
property bool scanning: false
|
||||
readonly property bool scanning: rescanProc.running
|
||||
|
||||
reloadableId: "network"
|
||||
|
||||
function enableWifi(enabled: bool): void {
|
||||
const cmd = enabled ? "on" : "off";
|
||||
enableWifiProcess.command = ["nmcli", "radio", "wifi", cmd];
|
||||
enableWifiProcess.running = true;
|
||||
enableWifiProc.exec(["nmcli", "radio", "wifi", cmd]);
|
||||
}
|
||||
|
||||
function toggleWifi(): void {
|
||||
const cmd = wifiEnabled ? "off" : "on";
|
||||
enableWifiProcess.command = ["nmcli", "radio", "wifi", cmd];
|
||||
enableWifiProcess.running = true;
|
||||
enableWifiProc.exec(["nmcli", "radio", "wifi", cmd]);
|
||||
}
|
||||
|
||||
function rescanWifi(): void {
|
||||
scanning = true;
|
||||
rescanProcess.running = true;
|
||||
rescanProc.running = true;
|
||||
}
|
||||
|
||||
function connectToNetwork(ssid: string, password: string): void {
|
||||
// TODO: Implement password
|
||||
connectProcess.command = ["nmcli", "conn", "up", ssid];
|
||||
connectProcess.running = true;
|
||||
connectProc.exec(["nmcli", "conn", "up", ssid]);
|
||||
}
|
||||
|
||||
function disconnectFromNetwork(): void {
|
||||
if (active) {
|
||||
disconnectProcess.command = ["nmcli", "connection", "down", active.ssid];
|
||||
disconnectProcess.running = true;
|
||||
disconnectProc.exec(["nmcli", "connection", "down", active.ssid]);
|
||||
}
|
||||
}
|
||||
|
||||
function getWifiStatus(): void {
|
||||
wifiStatusProcess.running = true;
|
||||
wifiStatusProc.running = true;
|
||||
}
|
||||
|
||||
Process {
|
||||
|
|
@ -57,53 +52,53 @@ Singleton {
|
|||
}
|
||||
|
||||
Process {
|
||||
id: wifiStatusProcess
|
||||
id: wifiStatusProc
|
||||
|
||||
running: true
|
||||
command: ["nmcli", "radio", "wifi"]
|
||||
environment: ({
|
||||
LANG: "C",
|
||||
LC_ALL: "C"
|
||||
})
|
||||
LANG: "C",
|
||||
LC_ALL: "C"
|
||||
})
|
||||
stdout: StdioCollector {
|
||||
onStreamFinished: {
|
||||
root.wifiEnabled = text.trim() === "enabled";
|
||||
}
|
||||
}
|
||||
Component.onCompleted: running = true
|
||||
}
|
||||
|
||||
Process {
|
||||
id: enableWifiProcess
|
||||
stdout: SplitParser {
|
||||
onRead: {
|
||||
getWifiStatus();
|
||||
getNetworks.running = true;
|
||||
}
|
||||
id: enableWifiProc
|
||||
|
||||
onExited: {
|
||||
root.getWifiStatus();
|
||||
getNetworks.running = true;
|
||||
}
|
||||
}
|
||||
|
||||
Process {
|
||||
id: rescanProcess
|
||||
id: rescanProc
|
||||
|
||||
command: ["nmcli", "dev", "wifi", "list", "--rescan", "yes"]
|
||||
stdout: SplitParser {
|
||||
onRead: {
|
||||
scanning = false;
|
||||
getNetworks.running = true;
|
||||
}
|
||||
onExited: {
|
||||
getNetworks.running = true;
|
||||
}
|
||||
}
|
||||
|
||||
Process {
|
||||
id: connectProcess
|
||||
id: connectProc
|
||||
|
||||
stdout: SplitParser {
|
||||
onRead: getNetworks.running = true
|
||||
}
|
||||
stderr: SplitParser {
|
||||
onRead: console.warn("Network connection error:", data)
|
||||
stderr: StdioCollector {
|
||||
onStreamFinished: console.warn("Network connection error:", text)
|
||||
}
|
||||
}
|
||||
|
||||
Process {
|
||||
id: disconnectProcess
|
||||
id: disconnectProc
|
||||
|
||||
stdout: SplitParser {
|
||||
onRead: getNetworks.running = true
|
||||
}
|
||||
|
|
@ -111,6 +106,7 @@ Singleton {
|
|||
|
||||
Process {
|
||||
id: getNetworks
|
||||
|
||||
running: true
|
||||
command: ["nmcli", "-g", "ACTIVE,SIGNAL,FREQ,SSID,BSSID,SECURITY", "d", "w"]
|
||||
environment: ({
|
||||
|
|
@ -134,7 +130,7 @@ Singleton {
|
|||
security: net[5] || ""
|
||||
};
|
||||
}).filter(n => n.ssid && n.ssid.length > 0);
|
||||
|
||||
|
||||
// Group networks by SSID and prioritize connected ones
|
||||
const networkMap = new Map();
|
||||
for (const network of allNetworks) {
|
||||
|
|
@ -154,9 +150,9 @@ Singleton {
|
|||
// If existing is active and new is not, keep existing
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
const networks = Array.from(networkMap.values());
|
||||
|
||||
|
||||
const rNetworks = root.networks;
|
||||
|
||||
const destroyed = rNetworks.filter(rn => !networks.find(n => n.frequency === rn.frequency && n.ssid === rn.ssid && n.bssid === rn.bssid));
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue