summaryrefslogtreecommitdiff
path: root/services
diff options
context:
space:
mode:
authorNikhil Sharma <48005807+ThEditor@users.noreply.github.com>2025-07-26 09:00:59 +0530
committerGitHub <noreply@github.com>2025-07-26 13:30:59 +1000
commitc3a47f24e80c9ce31cd73c7d913f89caf841e628 (patch)
tree12ac044d4a3bd36c54a86f7be66f4e693b175c29 /services
parentbrightness: debounce ddc changes (diff)
downloadcaelestia-shell-c3a47f24e80c9ce31cd73c7d913f89caf841e628.tar.gz
caelestia-shell-c3a47f24e80c9ce31cd73c7d913f89caf841e628.tar.bz2
caelestia-shell-c3a47f24e80c9ce31cd73c7d913f89caf841e628.zip
feat: improve network popout (#268)
* feat: network popout (saved networks only) * fix: rem unfinished forget network * network: some fixes --------- Co-authored-by: 2 * r + 2 * t <61896496+soramanew@users.noreply.github.com>
Diffstat (limited to 'services')
-rw-r--r--services/Network.qml123
1 files changed, 119 insertions, 4 deletions
diff --git a/services/Network.qml b/services/Network.qml
index 8515ef5..74b05dc 100644
--- a/services/Network.qml
+++ b/services/Network.qml
@@ -9,9 +9,45 @@ Singleton {
readonly property list<AccessPoint> networks: []
readonly property AccessPoint active: networks.find(n => n.active) ?? null
+ property bool wifiEnabled: true
+ property bool scanning: false
reloadableId: "network"
+ function enableWifi(enabled: bool): void {
+ const cmd = enabled ? "on" : "off";
+ enableWifiProcess.command = ["nmcli", "radio", "wifi", cmd];
+ enableWifiProcess.running = true;
+ }
+
+ function toggleWifi(): void {
+ const cmd = wifiEnabled ? "off" : "on";
+ enableWifiProcess.command = ["nmcli", "radio", "wifi", cmd];
+ enableWifiProcess.running = true;
+ }
+
+ function rescanWifi(): void {
+ scanning = true;
+ rescanProcess.running = true;
+ }
+
+ function connectToNetwork(ssid: string, password: string): void {
+ // TODO: Implement password
+ connectProcess.command = ["nmcli", "conn", "up", ssid];
+ connectProcess.running = true;
+ }
+
+ function disconnectFromNetwork(): void {
+ if (active) {
+ disconnectProcess.command = ["nmcli", "connection", "down", active.ssid];
+ disconnectProcess.running = true;
+ }
+ }
+
+ function getWifiStatus(): void {
+ wifiStatusProcess.running = true;
+ }
+
Process {
running: true
command: ["nmcli", "m"]
@@ -21,9 +57,62 @@ Singleton {
}
Process {
+ id: wifiStatusProcess
+ command: ["nmcli", "radio", "wifi"]
+ environment: ({
+ 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;
+ }
+ }
+ }
+
+ Process {
+ id: rescanProcess
+ command: ["nmcli", "dev", "wifi", "list", "--rescan", "yes"]
+ stdout: SplitParser {
+ onRead: {
+ scanning = false;
+ getNetworks.running = true;
+ }
+ }
+ }
+
+ Process {
+ id: connectProcess
+ stdout: SplitParser {
+ onRead: getNetworks.running = true
+ }
+ stderr: SplitParser {
+ onRead: console.warn("Network connection error:", data)
+ }
+ }
+
+ Process {
+ id: disconnectProcess
+ stdout: SplitParser {
+ onRead: getNetworks.running = true
+ }
+ }
+
+ Process {
id: getNetworks
running: true
- command: ["nmcli", "-g", "ACTIVE,SIGNAL,FREQ,SSID,BSSID", "d", "w"]
+ command: ["nmcli", "-g", "ACTIVE,SIGNAL,FREQ,SSID,BSSID,SECURITY", "d", "w"]
environment: ({
LANG: "C",
LC_ALL: "C"
@@ -34,16 +123,40 @@ Singleton {
const rep = new RegExp("\\\\:", "g");
const rep2 = new RegExp(PLACEHOLDER, "g");
- const networks = text.trim().split("\n").map(n => {
+ const allNetworks = text.trim().split("\n").map(n => {
const net = n.replace(rep, PLACEHOLDER).split(":");
return {
active: net[0] === "yes",
strength: parseInt(net[1]),
frequency: parseInt(net[2]),
ssid: net[3],
- bssid: net[4]?.replace(rep2, ":") ?? ""
+ bssid: net[4]?.replace(rep2, ":") ?? "",
+ 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) {
+ const existing = networkMap.get(network.ssid);
+ if (!existing) {
+ networkMap.set(network.ssid, network);
+ } else {
+ // Prioritize active/connected networks
+ if (network.active && !existing.active) {
+ networkMap.set(network.ssid, network);
+ } else if (!network.active && !existing.active) {
+ // If both are inactive, keep the one with better signal
+ if (network.strength > existing.strength) {
+ networkMap.set(network.ssid, network);
+ }
+ }
+ // 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));
@@ -71,6 +184,8 @@ Singleton {
readonly property int strength: lastIpcObject.strength
readonly property int frequency: lastIpcObject.frequency
readonly property bool active: lastIpcObject.active
+ readonly property string security: lastIpcObject.security
+ readonly property bool isSecure: security.length > 0
}
Component {