mirror of
https://github.com/AvengeMedia/DankMaterialShell.git
synced 2025-12-08 06:25:37 -05:00
net: updates to accomodate iwd + other backends
This commit is contained in:
@@ -76,7 +76,7 @@ Rectangle {
|
||||
DankButtonGroup {
|
||||
id: preferenceControls
|
||||
anchors.verticalCenter: parent.verticalCenter
|
||||
visible: DMSService.apiVersion >= 5
|
||||
visible: DMSService.apiVersion >= 5 && NetworkService.backend !== "iwd"
|
||||
|
||||
model: ["Ethernet", "WiFi"]
|
||||
currentIndex: currentPreferenceIndex
|
||||
|
||||
@@ -11,6 +11,7 @@ Singleton {
|
||||
id: root
|
||||
|
||||
property bool networkAvailable: false
|
||||
property string backend: ""
|
||||
|
||||
property string networkStatus: "disconnected"
|
||||
property string primaryConnection: ""
|
||||
@@ -109,7 +110,7 @@ Singleton {
|
||||
|
||||
function onNetworkStateUpdate(data) {
|
||||
const networksCount = data.wifiNetworks?.length ?? "null"
|
||||
console.log("NetworkManagerService: Subscription update received, networks:", networksCount)
|
||||
console.log("DMSNetworkService: Subscription update received, networks:", networksCount)
|
||||
updateState(data)
|
||||
}
|
||||
}
|
||||
@@ -148,8 +149,6 @@ Singleton {
|
||||
|
||||
networkAvailable = DMSService.capabilities.includes("network")
|
||||
|
||||
console.log("NetworkManagerService: Network available:", networkAvailable)
|
||||
|
||||
if (networkAvailable && !stateInitialized) {
|
||||
stateInitialized = true
|
||||
getState()
|
||||
@@ -191,7 +190,6 @@ Singleton {
|
||||
if (response.result) {
|
||||
updateState(response.result)
|
||||
if (!initialStateFetched && response.result.wifiEnabled && (!response.result.wifiNetworks || response.result.wifiNetworks.length === 0)) {
|
||||
console.log("NetworkManagerService: Initial state has no networks, triggering scan")
|
||||
initialStateFetched = true
|
||||
Qt.callLater(() => scanWifi())
|
||||
}
|
||||
@@ -203,6 +201,7 @@ Singleton {
|
||||
const previousConnecting = isConnecting
|
||||
const previousConnectingSSID = connectingSSID
|
||||
|
||||
backend = state.backend || ""
|
||||
networkStatus = state.networkStatus || "disconnected"
|
||||
primaryConnection = state.primaryConnection || ""
|
||||
|
||||
@@ -254,7 +253,7 @@ Singleton {
|
||||
if (pendingConnectionSSID) {
|
||||
if (wifiConnected && currentWifiSSID === pendingConnectionSSID && wifiIP) {
|
||||
const elapsed = Date.now() - pendingConnectionStartTime
|
||||
console.info("NetworkManagerService: Successfully connected to", pendingConnectionSSID, "in", elapsed, "ms")
|
||||
console.info("DMSNetworkService: Successfully connected to", pendingConnectionSSID, "in", elapsed, "ms")
|
||||
ToastService.showInfo(`Connected to ${pendingConnectionSSID}`)
|
||||
|
||||
if (userPreference === "wifi" || userPreference === "auto") {
|
||||
@@ -264,16 +263,21 @@ Singleton {
|
||||
pendingConnectionSSID = ""
|
||||
connectionStatus = "connected"
|
||||
} else if (previousConnecting && !isConnecting && !wifiConnected) {
|
||||
const elapsed = Date.now() - pendingConnectionStartTime
|
||||
const isCancellationError = connectionError === "user-canceled"
|
||||
const isBadCredentials = connectionError === "bad-credentials"
|
||||
|
||||
if (elapsed < 5000) {
|
||||
console.log("NetworkManagerService: Quick connection failure, likely authentication error")
|
||||
if (isCancellationError) {
|
||||
connectionStatus = "cancelled"
|
||||
pendingConnectionSSID = ""
|
||||
} else if (isBadCredentials) {
|
||||
const failedSSID = pendingConnectionSSID
|
||||
connectionStatus = "invalid_password"
|
||||
pendingConnectionSSID = ""
|
||||
Qt.callLater(() => {
|
||||
connectToWifi(failedSSID)
|
||||
})
|
||||
} else {
|
||||
console.log("NetworkManagerService: Connection failed for", pendingConnectionSSID)
|
||||
if (connectionError === "connection-failed") {
|
||||
ToastService.showError(I18n.tr("Connection failed. Check password and try again."))
|
||||
} else if (connectionError) {
|
||||
if (connectionError) {
|
||||
ToastService.showError(I18n.tr("Failed to connect to ") + pendingConnectionSSID)
|
||||
}
|
||||
connectionStatus = "failed"
|
||||
@@ -315,14 +319,12 @@ Singleton {
|
||||
function scanWifi() {
|
||||
if (!networkAvailable || isScanning || !wifiEnabled) return
|
||||
|
||||
console.log("NetworkManagerService: Starting WiFi scan...")
|
||||
isScanning = true
|
||||
DMSService.sendRequest("network.wifi.scan", null, response => {
|
||||
isScanning = false
|
||||
if (response.error) {
|
||||
console.warn("NetworkManagerService: WiFi scan failed:", response.error)
|
||||
console.warn("DMSNetworkService: WiFi scan failed:", response.error)
|
||||
} else {
|
||||
console.info("NetworkManagerService: Scan completed")
|
||||
Qt.callLater(() => getState())
|
||||
}
|
||||
})
|
||||
@@ -362,15 +364,15 @@ Singleton {
|
||||
|
||||
DMSService.sendRequest("network.wifi.connect", params, response => {
|
||||
if (response.error) {
|
||||
console.log("NetworkManagerService: Connection request failed:", response.error)
|
||||
if (connectionStatus === "cancelled") {
|
||||
return
|
||||
}
|
||||
|
||||
connectionError = response.error
|
||||
lastConnectionError = response.error
|
||||
pendingConnectionSSID = ""
|
||||
connectionStatus = "failed"
|
||||
ToastService.showError(I18n.tr("Failed to start connection to ") + ssid)
|
||||
} else {
|
||||
console.log("NetworkManagerService: Connection request sent for", ssid)
|
||||
}
|
||||
})
|
||||
}
|
||||
@@ -390,7 +392,12 @@ Singleton {
|
||||
}
|
||||
|
||||
function submitCredentials(token, secrets, save) {
|
||||
if (!networkAvailable || DMSService.apiVersion < 7) return
|
||||
console.log("submitCredentials: networkAvailable=" + networkAvailable + " apiVersion=" + DMSService.apiVersion)
|
||||
|
||||
if (!networkAvailable || DMSService.apiVersion < 7) {
|
||||
console.warn("submitCredentials: Aborting - networkAvailable=" + networkAvailable + " apiVersion=" + DMSService.apiVersion)
|
||||
return
|
||||
}
|
||||
|
||||
const params = {
|
||||
token: token,
|
||||
@@ -398,13 +405,11 @@ Singleton {
|
||||
save: save || false
|
||||
}
|
||||
|
||||
console.log("NetworkManagerService: Submitting credentials for token", token)
|
||||
|
||||
credentialsRequested = false
|
||||
|
||||
DMSService.sendRequest("network.credentials.submit", params, response => {
|
||||
if (response.error) {
|
||||
console.warn("NetworkManagerService: Failed to submit credentials:", response.error)
|
||||
console.warn("DMSNetworkService: Failed to submit credentials:", response.error)
|
||||
}
|
||||
})
|
||||
}
|
||||
@@ -413,19 +418,16 @@ Singleton {
|
||||
if (!networkAvailable || DMSService.apiVersion < 7) return
|
||||
|
||||
const params = {
|
||||
token: token,
|
||||
cancel: true
|
||||
token: token
|
||||
}
|
||||
|
||||
console.log("NetworkManagerService: Cancelling credentials for token", token)
|
||||
|
||||
credentialsRequested = false
|
||||
pendingConnectionSSID = ""
|
||||
connectionStatus = "cancelled"
|
||||
|
||||
DMSService.sendRequest("network.credentials.submit", params, response => {
|
||||
DMSService.sendRequest("network.credentials.cancel", params, response => {
|
||||
if (response.error) {
|
||||
console.warn("NetworkManagerService: Failed to cancel credentials:", response.error)
|
||||
console.warn("DMSNetworkService: Failed to cancel credentials:", response.error)
|
||||
}
|
||||
})
|
||||
}
|
||||
@@ -271,6 +271,7 @@ Singleton {
|
||||
|
||||
function sendRequest(method, params, callback) {
|
||||
if (!isConnected) {
|
||||
console.warn("DMSService.sendRequest: Not connected, method:", method)
|
||||
if (callback) {
|
||||
callback({
|
||||
"error": "not connected to DMS socket"
|
||||
@@ -294,6 +295,7 @@ Singleton {
|
||||
pendingRequests[id] = callback
|
||||
}
|
||||
|
||||
console.log("DMSService.sendRequest: Sending request id=" + id + " method=" + method)
|
||||
requestSocket.send(request)
|
||||
}
|
||||
|
||||
|
||||
@@ -11,6 +11,7 @@ Singleton {
|
||||
id: root
|
||||
|
||||
property bool networkAvailable: activeService !== null
|
||||
property string backend: activeService?.backend ?? ""
|
||||
property string networkStatus: activeService?.networkStatus ?? "disconnected"
|
||||
property string primaryConnection: activeService?.primaryConnection ?? ""
|
||||
|
||||
@@ -97,16 +98,16 @@ Singleton {
|
||||
}
|
||||
|
||||
Connections {
|
||||
target: NetworkManagerService
|
||||
target: DMSNetworkService
|
||||
|
||||
function onNetworkAvailableChanged() {
|
||||
if (!activeService && NetworkManagerService.networkAvailable) {
|
||||
console.info("NetworkService: Network capability detected, using NetworkManagerService")
|
||||
activeService = NetworkManagerService
|
||||
if (!activeService && DMSNetworkService.networkAvailable) {
|
||||
console.info("NetworkService: Network capability detected, using DMSNetworkService")
|
||||
activeService = DMSNetworkService
|
||||
usingLegacy = false
|
||||
console.info("NetworkService: Switched to NetworkManagerService, networkAvailable:", networkAvailable)
|
||||
console.info("NetworkService: Switched to DMSNetworkService, networkAvailable:", networkAvailable)
|
||||
connectSignals()
|
||||
} else if (!activeService && !NetworkManagerService.networkAvailable && socketPath && socketPath.length > 0) {
|
||||
} else if (!activeService && !DMSNetworkService.networkAvailable && socketPath && socketPath.length > 0) {
|
||||
console.info("NetworkService: Network capability not available in DMS, using LegacyNetworkService")
|
||||
useLegacyService()
|
||||
}
|
||||
|
||||
@@ -734,7 +734,7 @@
|
||||
{
|
||||
"term": "Configuration activated",
|
||||
"context": "Configuration activated",
|
||||
"reference": "Services/NetworkManagerService.qml:308",
|
||||
"reference": "Services/DMSNetworkService.qml:308",
|
||||
"comment": ""
|
||||
},
|
||||
{
|
||||
@@ -782,7 +782,7 @@
|
||||
{
|
||||
"term": "Connection failed. Check password and try again.",
|
||||
"context": "Connection failed. Check password and try again.",
|
||||
"reference": "Services/NetworkManagerService.qml:275",
|
||||
"reference": "Services/DMSNetworkService.qml:275",
|
||||
"comment": ""
|
||||
},
|
||||
{
|
||||
@@ -1028,7 +1028,7 @@
|
||||
{
|
||||
"term": "Disconnected from WiFi",
|
||||
"context": "Disconnected from WiFi",
|
||||
"reference": "Services/NetworkManagerService.qml:385",
|
||||
"reference": "Services/DMSNetworkService.qml:385",
|
||||
"comment": ""
|
||||
},
|
||||
{
|
||||
@@ -1292,25 +1292,25 @@
|
||||
{
|
||||
"term": "Failed to activate configuration",
|
||||
"context": "Failed to activate configuration",
|
||||
"reference": "Services/NetworkManagerService.qml:304",
|
||||
"reference": "Services/DMSNetworkService.qml:304",
|
||||
"comment": ""
|
||||
},
|
||||
{
|
||||
"term": "Failed to connect to ",
|
||||
"context": "Failed to connect to ",
|
||||
"reference": "Services/NetworkManagerService.qml:277",
|
||||
"reference": "Services/DMSNetworkService.qml:277",
|
||||
"comment": ""
|
||||
},
|
||||
{
|
||||
"term": "Failed to disconnect WiFi",
|
||||
"context": "Failed to disconnect WiFi",
|
||||
"reference": "Services/NetworkManagerService.qml:383",
|
||||
"reference": "Services/DMSNetworkService.qml:383",
|
||||
"comment": ""
|
||||
},
|
||||
{
|
||||
"term": "Failed to enable WiFi",
|
||||
"context": "Failed to enable WiFi",
|
||||
"reference": "Services/NetworkManagerService.qml:484",
|
||||
"reference": "Services/DMSNetworkService.qml:484",
|
||||
"comment": ""
|
||||
},
|
||||
{
|
||||
@@ -1334,7 +1334,7 @@
|
||||
{
|
||||
"term": "Failed to start connection to ",
|
||||
"context": "Failed to start connection to ",
|
||||
"reference": "Services/NetworkManagerService.qml:371",
|
||||
"reference": "Services/DMSNetworkService.qml:371",
|
||||
"comment": ""
|
||||
},
|
||||
{
|
||||
@@ -1424,7 +1424,7 @@
|
||||
{
|
||||
"term": "Forgot network ",
|
||||
"context": "Forgot network ",
|
||||
"reference": "Services/NetworkManagerService.qml:441",
|
||||
"reference": "Services/DMSNetworkService.qml:441",
|
||||
"comment": ""
|
||||
},
|
||||
{
|
||||
@@ -3500,13 +3500,13 @@
|
||||
{
|
||||
"term": "WiFi disabled",
|
||||
"context": "WiFi disabled",
|
||||
"reference": "Services/NetworkManagerService.qml:474",
|
||||
"reference": "Services/DMSNetworkService.qml:474",
|
||||
"comment": ""
|
||||
},
|
||||
{
|
||||
"term": "WiFi enabled",
|
||||
"context": "WiFi enabled",
|
||||
"reference": "Services/NetworkManagerService.qml:474, Services/NetworkManagerService.qml:486",
|
||||
"reference": "Services/DMSNetworkService.qml:474, Services/DMSNetworkService.qml:486",
|
||||
"comment": ""
|
||||
},
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user