From a2b4f4b6b62f636743300a13e914bacf9c79c2d7 Mon Sep 17 00:00:00 2001 From: JPratama7 Date: Sun, 3 Aug 2025 22:09:08 +0700 Subject: [PATCH] feat: remove quickshell prefix for profilename --- Widgets/Sidebar/Panel/WifiPanel.qml | 73 +++++++++++++++++++++++++++-- 1 file changed, 69 insertions(+), 4 deletions(-) diff --git a/Widgets/Sidebar/Panel/WifiPanel.qml b/Widgets/Sidebar/Panel/WifiPanel.qml index 4fc5b11..b02737b 100644 --- a/Widgets/Sidebar/Panel/WifiPanel.qml +++ b/Widgets/Sidebar/Panel/WifiPanel.qml @@ -56,7 +56,7 @@ Item { continue; } - const ssid = parts[0]; + const ssid = wifiLogic.replaceQuickshell(parts[0]); const type = parts[1]; if (ssid) { @@ -120,6 +120,8 @@ Item { } } } + + wifiLogic.networks = networksMap; scanProcess.existingNetwork = {}; refreshIndicator.running = false; @@ -130,7 +132,7 @@ Item { QtObject { id: wifiLogic - property var networks: [] + property var networks: {} property var anchorItem: null property real anchorX property real anchorY @@ -146,6 +148,28 @@ Item { property string detectedInterface: "" property string actionPanelSsid: "" + function replaceQuickshell(ssid: string): string { + const newName = ssid.replace("quickshell-", ""); + + if (!ssid.startsWith("quickshell-")){ + return newName; + } + + if (newName in wifiLogic.networks){ + console.log(`Quickshell ${newName} already exists, deleting old profile`) + deleteProfileProcess.connName = ssid; + deleteProfileProcess.running = true; + } + + + console.log(`Changing from ${ssid} to ${newName}`) + renameConnectionProcess.oldName = ssid; + renameConnectionProcess.newName = newName; + renameConnectionProcess.running = true; + + return newName; + } + function disconnectNetwork(ssid) { const profileName = ssid; disconnectProfileProcess.connectionName = profileName; @@ -222,6 +246,47 @@ Item { } } + // Process to rename a connection + Process { + id: renameConnectionProcess + running: false + property string oldName: "" + property string newName: "" + command: ["nmcli", "connection", "modify", oldName, "connection.id", newName] + + stdout: StdioCollector { + onStreamFinished: { + console.log("Renamed connection '" + renameConnectionProcess.oldName + "' to '" + renameConnectionProcess.newName + "'"); + } + } + stderr: StdioCollector { + onStreamFinished: { + console.error("Error renaming connection '" + renameConnectionProcess.oldName + "':", text); + } + } + } + + + // Process to rename a connection + Process { + id: deleteProfileProcess + running: false + property string connName: "" + command: ["nmcli", "connection", "delete", `'${connName}'`] + + stdout: StdioCollector { + onStreamFinished: { + console.log("Deleted connection '" + deleteProfileProcess.connName + "'"); + } + } + stderr: StdioCollector { + onStreamFinished: { + console.error("Error deleting connection '" + deleteProfileProcess.connName + "':", text); + } + } + } + + // Handles connecting to a Wi-Fi network, with or without password Process { id: connectProcess @@ -237,9 +302,9 @@ Item { } command: { if (password) { - return ["nmcli", "device", "wifi", "connect", ssid, "password", password]; + return ["nmcli", "device", "wifi", "connect", `'${ssid}'`, "password", password]; } else { - return ["nmcli", "device", "wifi", "connect", ssid]; + return ["nmcli", "device", "wifi", "connect", `'${ssid}'`]; } } stdout: StdioCollector {