From 5cd1167b285da92415fc80b1cfda578a45101dce Mon Sep 17 00:00:00 2001 From: bbedward Date: Mon, 3 Nov 2025 14:56:49 -0500 Subject: [PATCH] net: add auto connect option for wifi networks fixes #597 --- .../ControlCenter/Details/NetworkDetail.qml | 38 ++++++++++++++++++- Services/DMSNetworkService.qml | 18 +++++++++ Services/NetworkService.qml | 6 +++ 3 files changed, 61 insertions(+), 1 deletion(-) diff --git a/Modules/ControlCenter/Details/NetworkDetail.qml b/Modules/ControlCenter/Details/NetworkDetail.qml index 0290f4ec..36a13912 100644 --- a/Modules/ControlCenter/Details/NetworkDetail.qml +++ b/Modules/ControlCenter/Details/NetworkDetail.qml @@ -376,6 +376,9 @@ Rectangle { contentHeight: wifiColumn.height clip: true + property var frozenNetworks: [] + property bool menuOpen: false + Column { id: wifiColumn width: parent.width @@ -403,7 +406,7 @@ Rectangle { } Repeater { - model: sortedNetworks + model: wifiContent.menuOpen ? wifiContent.frozenNetworks : sortedNetworks property var sortedNetworks: { const ssid = NetworkService.currentWifiSSID @@ -414,6 +417,9 @@ Rectangle { if (b.ssid === ssid) return 1 return b.signal - a.signal }) + if (!wifiContent.menuOpen) { + wifiContent.frozenNetworks = sorted + } return sorted } delegate: Rectangle { @@ -494,11 +500,13 @@ Rectangle { if (networkContextMenu.visible) { networkContextMenu.close() } else { + wifiContent.menuOpen = true networkContextMenu.currentSSID = modelData.ssid networkContextMenu.currentSecured = modelData.secured networkContextMenu.currentConnected = modelData.ssid === NetworkService.currentWifiSSID networkContextMenu.currentSaved = modelData.saved networkContextMenu.currentSignal = modelData.signal + networkContextMenu.currentAutoconnect = modelData.autoconnect || false networkContextMenu.popup(optionsButton, -networkContextMenu.width + optionsButton.width, optionsButton.height + Theme.spacingXS) } } @@ -541,6 +549,11 @@ Rectangle { property bool currentConnected: false property bool currentSaved: false property int currentSignal: 0 + property bool currentAutoconnect: false + + onClosed: { + wifiContent.menuOpen = false + } background: Rectangle { color: Theme.popupBackground() @@ -606,6 +619,29 @@ Rectangle { } } + MenuItem { + text: networkContextMenu.currentAutoconnect ? I18n.tr("Disable Autoconnect") : I18n.tr("Enable Autoconnect") + height: (networkContextMenu.currentSaved || networkContextMenu.currentConnected) && DMSService.apiVersion > 13 ? 32 : 0 + visible: (networkContextMenu.currentSaved || networkContextMenu.currentConnected) && DMSService.apiVersion > 13 + + contentItem: StyledText { + text: parent.text + font.pixelSize: Theme.fontSizeSmall + color: Theme.surfaceText + leftPadding: Theme.spacingS + verticalAlignment: Text.AlignVCenter + } + + background: Rectangle { + color: parent.hovered ? Qt.rgba(Theme.primary.r, Theme.primary.g, Theme.primary.b, 0.08) : "transparent" + radius: Theme.cornerRadius / 2 + } + + onTriggered: { + NetworkService.setWifiAutoconnect(networkContextMenu.currentSSID, !networkContextMenu.currentAutoconnect) + } + } + MenuItem { text: I18n.tr("Forget Network") height: networkContextMenu.currentSaved || networkContextMenu.currentConnected ? 32 : 0 diff --git a/Services/DMSNetworkService.qml b/Services/DMSNetworkService.qml index b2666fe4..c2af7b6a 100644 --- a/Services/DMSNetworkService.qml +++ b/Services/DMSNetworkService.qml @@ -869,4 +869,22 @@ Singleton { getState() } } + + function setWifiAutoconnect(ssid, autoconnect) { + if (!networkAvailable || DMSService.apiVersion <= 13) return + + const params = { + ssid: ssid, + autoconnect: autoconnect + } + + DMSService.sendRequest("network.wifi.setAutoconnect", params, response => { + if (response.error) { + ToastService.showError(I18n.tr("Failed to update autoconnect")) + } else { + ToastService.showInfo(autoconnect ? I18n.tr("Autoconnect enabled") : I18n.tr("Autoconnect disabled")) + Qt.callLater(() => getState()) + } + }) + } } diff --git a/Services/NetworkService.qml b/Services/NetworkService.qml index 5af973c3..46863c20 100644 --- a/Services/NetworkService.qml +++ b/Services/NetworkService.qml @@ -283,4 +283,10 @@ Singleton { activeService.cancelCredentials(token) } } + + function setWifiAutoconnect(ssid, autoconnect) { + if (activeService && activeService.setWifiAutoconnect) { + activeService.setWifiAutoconnect(ssid, autoconnect) + } + } }