1
0
mirror of https://github.com/AvengeMedia/DankMaterialShell.git synced 2026-01-24 21:42:51 -05:00

Add proxy service for legacy nmcli version

This commit is contained in:
bbedward
2025-10-08 14:00:51 -04:00
parent ad43ca11eb
commit e327b1ca5b
12 changed files with 1441 additions and 111 deletions

View File

@@ -17,7 +17,7 @@ DankModal {
networkData = data
networkInfoModalVisible = true
open()
NetworkManagerService.fetchNetworkInfo(ssid)
NetworkService.fetchNetworkInfo(ssid)
}
function hideDialog() {
@@ -101,7 +101,7 @@ DankModal {
id: detailsText
width: parent.width
text: NetworkManagerService.networkInfoDetails && NetworkManagerService.networkInfoDetails.replace(/\\n/g, '\n') || "No information available"
text: NetworkService.networkInfoDetails && NetworkService.networkInfoDetails.replace(/\\n/g, '\n') || "No information available"
font.pixelSize: Theme.fontSizeMedium
color: Theme.surfaceText
wrapMode: Text.WordWrap

View File

@@ -17,7 +17,7 @@ DankModal {
wifiPasswordInput = ""
wifiUsernameInput = ""
const network = NetworkManagerService.wifiNetworks.find(n => n.ssid === ssid)
const network = NetworkService.wifiNetworks.find(n => n.ssid === ssid)
requiresEnterprise = network?.enterprise || false
open()
@@ -59,14 +59,14 @@ DankModal {
}
Connections {
target: NetworkManagerService
target: NetworkService
function onPasswordDialogShouldReopenChanged() {
if (NetworkManagerService.passwordDialogShouldReopen && NetworkManagerService.connectingSSID !== "") {
wifiPasswordSSID = NetworkManagerService.connectingSSID
if (NetworkService.passwordDialogShouldReopen && NetworkService.connectingSSID !== "") {
wifiPasswordSSID = NetworkService.connectingSSID
wifiPasswordInput = ""
open()
NetworkManagerService.passwordDialogShouldReopen = false
NetworkService.passwordDialogShouldReopen = false
}
}
}
@@ -196,7 +196,7 @@ DankModal {
}
onAccepted: () => {
const username = requiresEnterprise ? usernameInput.text : ""
NetworkManagerService.connectToWifi(wifiPasswordSSID, passwordInput.text, username)
NetworkService.connectToWifi(wifiPasswordSSID, passwordInput.text, username)
close()
wifiPasswordInput = ""
wifiUsernameInput = ""
@@ -344,7 +344,7 @@ DankModal {
enabled: parent.enabled
onClicked: () => {
const username = requiresEnterprise ? usernameInput.text : ""
NetworkManagerService.connectToWifi(wifiPasswordSSID, passwordInput.text, username)
NetworkService.connectToWifi(wifiPasswordSSID, passwordInput.text, username)
close()
wifiPasswordInput = ""
wifiUsernameInput = ""

View File

@@ -126,15 +126,7 @@ Column {
return builtinPluginWidgetComponent
} else if (id.startsWith("plugin_")) {
return pluginWidgetComponent
} else if (id === "wifi") {
if (!DMSService.dmsAvailable) {
return errorPillComponent
}
if (DMSService.dmsAvailable && !DMSService.capabilities.includes("network")) {
return errorPillComponent
}
return compoundPillComponent
} else if (id === "bluetooth" || id === "audioOutput" || id === "audioInput") {
} else if (id === "wifi" || id === "bluetooth" || id === "audioOutput" || id === "audioInput") {
return compoundPillComponent
} else if (id === "volumeSlider") {
return audioSliderComponent
@@ -211,13 +203,13 @@ Column {
switch (widgetData.id || "") {
case "wifi":
{
if (NetworkManagerService.wifiToggling)
if (NetworkService.wifiToggling)
return "sync"
if (NetworkManagerService.networkStatus === "ethernet")
if (NetworkService.networkStatus === "ethernet")
return "settings_ethernet"
if (NetworkManagerService.networkStatus === "wifi")
return NetworkManagerService.wifiSignalIcon
if (NetworkManagerService.wifiEnabled)
if (NetworkService.networkStatus === "wifi")
return NetworkService.wifiSignalIcon
if (NetworkService.wifiEnabled)
return "wifi_off"
return "wifi_off"
}
@@ -270,13 +262,13 @@ Column {
switch (widgetData.id || "") {
case "wifi":
{
if (NetworkManagerService.wifiToggling)
return NetworkManagerService.wifiEnabled ? "Disabling WiFi..." : "Enabling WiFi..."
if (NetworkManagerService.networkStatus === "ethernet")
if (NetworkService.wifiToggling)
return NetworkService.wifiEnabled ? "Disabling WiFi..." : "Enabling WiFi..."
if (NetworkService.networkStatus === "ethernet")
return "Ethernet"
if (NetworkManagerService.networkStatus === "wifi" && NetworkManagerService.currentWifiSSID)
return NetworkManagerService.currentWifiSSID
if (NetworkManagerService.wifiEnabled)
if (NetworkService.networkStatus === "wifi" && NetworkService.currentWifiSSID)
return NetworkService.currentWifiSSID
if (NetworkService.wifiEnabled)
return "Not connected"
return "WiFi off"
}
@@ -302,13 +294,13 @@ Column {
switch (widgetData.id || "") {
case "wifi":
{
if (NetworkManagerService.wifiToggling)
if (NetworkService.wifiToggling)
return "Please wait..."
if (NetworkManagerService.networkStatus === "ethernet")
if (NetworkService.networkStatus === "ethernet")
return "Connected"
if (NetworkManagerService.networkStatus === "wifi")
return NetworkManagerService.wifiSignalStrength > 0 ? NetworkManagerService.wifiSignalStrength + "%" : "Connected"
if (NetworkManagerService.wifiEnabled)
if (NetworkService.networkStatus === "wifi")
return NetworkService.wifiSignalStrength > 0 ? NetworkService.wifiSignalStrength + "%" : "Connected"
if (NetworkService.wifiEnabled)
return "Select network"
return ""
}
@@ -356,13 +348,13 @@ Column {
switch (widgetData.id || "") {
case "wifi":
{
if (NetworkManagerService.wifiToggling)
if (NetworkService.wifiToggling)
return false
if (NetworkManagerService.networkStatus === "ethernet")
if (NetworkService.networkStatus === "ethernet")
return true
if (NetworkManagerService.networkStatus === "wifi")
if (NetworkService.networkStatus === "wifi")
return true
return NetworkManagerService.wifiEnabled
return NetworkService.wifiEnabled
}
case "bluetooth":
return !!(BluetoothService.available && BluetoothService.adapter && BluetoothService.adapter.enabled)

View File

@@ -73,13 +73,17 @@ DankPopout {
onShouldBeVisibleChanged: {
if (shouldBeVisible) {
Qt.callLater(() => {
NetworkManagerService.autoRefreshEnabled = NetworkManagerService.wifiEnabled
if (NetworkService.activeService) {
NetworkService.activeService.autoRefreshEnabled = NetworkService.wifiEnabled
}
if (UserInfoService)
UserInfoService.getUptime()
})
} else {
Qt.callLater(() => {
NetworkManagerService.autoRefreshEnabled = false
if (NetworkService.activeService) {
NetworkService.activeService.autoRefreshEnabled = false
}
if (BluetoothService.adapter && BluetoothService.adapter.discovering)
BluetoothService.adapter.discovering = false
editMode = false

View File

@@ -8,10 +8,10 @@ import qs.Modals
Rectangle {
implicitHeight: {
if (NetworkManagerService.wifiToggling) {
if (NetworkService.wifiToggling) {
return headerRow.height + wifiToggleContent.height + Theme.spacingM
}
if (NetworkManagerService.wifiEnabled) {
if (NetworkService.wifiEnabled) {
return headerRow.height + wifiContent.height + Theme.spacingM
}
return headerRow.height + wifiOffContent.height + Theme.spacingM
@@ -22,11 +22,11 @@ Rectangle {
border.width: 0
Component.onCompleted: {
NetworkManagerService.addRef()
NetworkService.addRef()
}
Component.onDestruction: {
NetworkManagerService.removeRef()
NetworkService.removeRef()
}
Row {
@@ -56,11 +56,11 @@ Rectangle {
DankButtonGroup {
id: preferenceControls
anchors.verticalCenter: parent.verticalCenter
visible: NetworkManagerService.ethernetConnected
visible: NetworkService.ethernetConnected
property int currentPreferenceIndex: {
const pref = NetworkManagerService.userPreference
const status = NetworkManagerService.networkStatus
const pref = NetworkService.userPreference
const status = NetworkService.networkStatus
let index = 1
if (pref === "ethernet") {
@@ -80,7 +80,7 @@ Rectangle {
onSelectionChanged: (index, selected) => {
if (!selected) return
console.log("NetworkDetail: Setting preference to", index === 0 ? "ethernet" : "wifi")
NetworkManagerService.setNetworkPreference(index === 0 ? "ethernet" : "wifi")
NetworkService.setNetworkPreference(index === 0 ? "ethernet" : "wifi")
}
}
}
@@ -92,7 +92,7 @@ Rectangle {
anchors.right: parent.right
anchors.margins: Theme.spacingM
anchors.topMargin: Theme.spacingM
visible: NetworkManagerService.wifiToggling
visible: NetworkService.wifiToggling
height: visible ? 80 : 0
Column {
@@ -106,7 +106,7 @@ Rectangle {
color: Theme.primary
RotationAnimation on rotation {
running: NetworkManagerService.wifiToggling
running: NetworkService.wifiToggling
loops: Animation.Infinite
from: 0
to: 360
@@ -116,7 +116,7 @@ Rectangle {
StyledText {
anchors.horizontalCenter: parent.horizontalCenter
text: NetworkManagerService.wifiEnabled ? "Disabling WiFi..." : "Enabling WiFi..."
text: NetworkService.wifiEnabled ? "Disabling WiFi..." : "Enabling WiFi..."
font.pixelSize: Theme.fontSizeMedium
color: Theme.surfaceText
horizontalAlignment: Text.AlignHCenter
@@ -131,7 +131,7 @@ Rectangle {
anchors.right: parent.right
anchors.margins: Theme.spacingM
anchors.topMargin: Theme.spacingM
visible: !NetworkManagerService.wifiEnabled && !NetworkManagerService.wifiToggling
visible: !NetworkService.wifiEnabled && !NetworkService.wifiToggling
height: visible ? 120 : 0
Column {
@@ -177,7 +177,7 @@ Rectangle {
anchors.fill: parent
hoverEnabled: true
cursorShape: Qt.PointingHandCursor
onClicked: NetworkManagerService.toggleWifiRadio()
onClicked: NetworkService.toggleWifiRadio()
}
}
@@ -192,7 +192,7 @@ Rectangle {
anchors.bottom: parent.bottom
anchors.margins: Theme.spacingM
anchors.topMargin: Theme.spacingM
visible: NetworkManagerService.wifiInterface && NetworkManagerService.wifiEnabled && !NetworkManagerService.wifiToggling
visible: NetworkService.wifiInterface && NetworkService.wifiEnabled && !NetworkService.wifiToggling
contentHeight: wifiColumn.height
clip: true
@@ -204,7 +204,7 @@ Rectangle {
Item {
width: parent.width
height: 200
visible: NetworkManagerService.wifiInterface && NetworkManagerService.wifiNetworks?.length < 1 && !NetworkManagerService.wifiToggling && NetworkManagerService.isScanning
visible: NetworkService.wifiInterface && NetworkService.wifiNetworks?.length < 1 && !NetworkService.wifiToggling && NetworkService.isScanning
DankIcon {
anchors.centerIn: parent
@@ -213,7 +213,7 @@ Rectangle {
color: Qt.rgba(Theme.surfaceText.r || 0.8, Theme.surfaceText.g || 0.8, Theme.surfaceText.b || 0.8, 0.3)
RotationAnimation on rotation {
running: NetworkManagerService.isScanning
running: NetworkService.isScanning
loops: Animation.Infinite
from: 0
to: 360
@@ -226,8 +226,8 @@ Rectangle {
model: sortedNetworks
property var sortedNetworks: {
const ssid = NetworkManagerService.currentWifiSSID
const networks = NetworkManagerService.wifiNetworks
const ssid = NetworkService.currentWifiSSID
const networks = NetworkService.wifiNetworks
let sorted = [...networks]
sorted.sort((a, b) => {
if (a.ssid === ssid) return -1
@@ -244,7 +244,7 @@ Rectangle {
height: 50
radius: Theme.cornerRadius
color: networkMouseArea.containsMouse ? Qt.rgba(Theme.primary.r, Theme.primary.g, Theme.primary.b, 0.08) : Theme.surfaceContainerHighest
border.color: modelData.ssid === NetworkManagerService.currentWifiSSID ? Theme.primary : Qt.rgba(Theme.outline.r, Theme.outline.g, Theme.outline.b, 0.12)
border.color: modelData.ssid === NetworkService.currentWifiSSID ? Theme.primary : Qt.rgba(Theme.outline.r, Theme.outline.g, Theme.outline.b, 0.12)
border.width: 0
Row {
@@ -261,7 +261,7 @@ Rectangle {
return "wifi_1_bar"
}
size: Theme.iconSize - 4
color: modelData.ssid === NetworkManagerService.currentWifiSSID ? Theme.primary : Theme.surfaceText
color: modelData.ssid === NetworkService.currentWifiSSID ? Theme.primary : Theme.surfaceText
anchors.verticalCenter: parent.verticalCenter
}
@@ -273,7 +273,7 @@ Rectangle {
text: modelData.ssid || "Unknown Network"
font.pixelSize: Theme.fontSizeMedium
color: Theme.surfaceText
font.weight: modelData.ssid === NetworkManagerService.currentWifiSSID ? Font.Medium : Font.Normal
font.weight: modelData.ssid === NetworkService.currentWifiSSID ? Font.Medium : Font.Normal
elide: Text.ElideRight
width: parent.width
}
@@ -282,7 +282,7 @@ Rectangle {
spacing: Theme.spacingXS
StyledText {
text: modelData.ssid === NetworkManagerService.currentWifiSSID ? "Connected" : (modelData.secured ? "Secured" : "Open")
text: modelData.ssid === NetworkService.currentWifiSSID ? "Connected" : (modelData.secured ? "Secured" : "Open")
font.pixelSize: Theme.fontSizeSmall
color: Theme.surfaceVariantText
}
@@ -316,7 +316,7 @@ Rectangle {
} else {
networkContextMenu.currentSSID = modelData.ssid
networkContextMenu.currentSecured = modelData.secured
networkContextMenu.currentConnected = modelData.ssid === NetworkManagerService.currentWifiSSID
networkContextMenu.currentConnected = modelData.ssid === NetworkService.currentWifiSSID
networkContextMenu.currentSaved = modelData.saved
networkContextMenu.currentSignal = modelData.signal
networkContextMenu.popup(optionsButton, -networkContextMenu.width + optionsButton.width, optionsButton.height + Theme.spacingXS)
@@ -331,11 +331,11 @@ Rectangle {
hoverEnabled: true
cursorShape: Qt.PointingHandCursor
onClicked: function(event) {
if (modelData.ssid !== NetworkManagerService.currentWifiSSID) {
if (modelData.ssid !== NetworkService.currentWifiSSID) {
if (modelData.secured && !modelData.saved) {
wifiPasswordModal.show(modelData.ssid)
} else {
NetworkManagerService.connectToWifi(modelData.ssid)
NetworkService.connectToWifi(modelData.ssid)
}
}
event.accepted = true
@@ -384,12 +384,12 @@ Rectangle {
onTriggered: {
if (networkContextMenu.currentConnected) {
NetworkManagerService.disconnectWifi()
NetworkService.disconnectWifi()
} else {
if (networkContextMenu.currentSecured && !networkContextMenu.currentSaved) {
wifiPasswordModal.show(networkContextMenu.currentSSID)
} else {
NetworkManagerService.connectToWifi(networkContextMenu.currentSSID)
NetworkService.connectToWifi(networkContextMenu.currentSSID)
}
}
}
@@ -413,7 +413,7 @@ Rectangle {
}
onTriggered: {
let networkData = NetworkManagerService.getNetworkInfo(networkContextMenu.currentSSID)
let networkData = NetworkService.getNetworkInfo(networkContextMenu.currentSSID)
networkInfoModal.showNetworkInfo(networkContextMenu.currentSSID, networkData)
}
}
@@ -437,7 +437,7 @@ Rectangle {
}
onTriggered: {
NetworkManagerService.forgetWifiNetwork(networkContextMenu.currentSSID)
NetworkService.forgetWifiNetwork(networkContextMenu.currentSSID)
}
}
}

View File

@@ -67,8 +67,8 @@ QtObject {
"description": "Wi-Fi and Ethernet connection",
"icon": "wifi",
"type": "connection",
"enabled": NetworkManagerService.wifiAvailable,
"warning": !NetworkManagerService.wifiAvailable ? "Wi-Fi not available" : undefined
"enabled": NetworkService.wifiAvailable,
"warning": !NetworkService.wifiAvailable ? "Wi-Fi not available" : undefined
}, {
"id": "bluetooth",
"text": "Bluetooth",

View File

@@ -1003,8 +1003,8 @@ Item {
}
controlCenterLoader.item.triggerScreen = barWindow.screen
controlCenterLoader.item.toggle()
if (controlCenterLoader.item.shouldBeVisible && NetworkManagerService.wifiEnabled) {
NetworkManagerService.scanWifi()
if (controlCenterLoader.item.shouldBeVisible && NetworkService.wifiEnabled) {
NetworkService.scanWifi()
}
}
}

View File

@@ -42,26 +42,26 @@ Rectangle {
DankIcon {
name: {
if (NetworkManagerService.wifiToggling) {
if (NetworkService.wifiToggling) {
return "sync"
}
if (NetworkManagerService.networkStatus === "ethernet") {
if (NetworkService.networkStatus === "ethernet") {
return "lan"
}
return NetworkManagerService.wifiSignalIcon
return NetworkService.wifiSignalIcon
}
size: Theme.barIconSize(barThickness)
color: {
if (NetworkManagerService.wifiToggling) {
if (NetworkService.wifiToggling) {
return Theme.primary
}
return NetworkManagerService.networkStatus !== "disconnected" ? Theme.primary : Theme.outlineButton
return NetworkService.networkStatus !== "disconnected" ? Theme.primary : Theme.outlineButton
}
anchors.horizontalCenter: parent.horizontalCenter
visible: root.showNetworkIcon && NetworkManagerService.networkAvailable
visible: root.showNetworkIcon && NetworkService.networkAvailable
}
DankIcon {
@@ -141,26 +141,26 @@ Rectangle {
id: networkIcon
name: {
if (NetworkManagerService.wifiToggling) {
if (NetworkService.wifiToggling) {
return "sync";
}
if (NetworkManagerService.networkStatus === "ethernet") {
if (NetworkService.networkStatus === "ethernet") {
return "lan";
}
return NetworkManagerService.wifiSignalIcon;
return NetworkService.wifiSignalIcon;
}
size: Theme.barIconSize(barThickness)
color: {
if (NetworkManagerService.wifiToggling) {
if (NetworkService.wifiToggling) {
return Theme.primary;
}
return NetworkManagerService.networkStatus !== "disconnected" ? Theme.primary : Theme.outlineButton;
return NetworkService.networkStatus !== "disconnected" ? Theme.primary : Theme.outlineButton;
}
anchors.verticalCenter: parent.verticalCenter
visible: root.showNetworkIcon && NetworkManagerService.networkAvailable
visible: root.showNetworkIcon && NetworkService.networkAvailable
}

View File

@@ -906,20 +906,20 @@ Item {
height: 24
color: Qt.rgba(255, 255, 255, 0.2)
anchors.verticalCenter: parent.verticalCenter
visible: WeatherService.weather.available && (NetworkManagerService.networkStatus !== "disconnected" || BluetoothService.enabled || (AudioService.sink && AudioService.sink.audio) || BatteryService.batteryAvailable)
visible: WeatherService.weather.available && (NetworkService.networkStatus !== "disconnected" || BluetoothService.enabled || (AudioService.sink && AudioService.sink.audio) || BatteryService.batteryAvailable)
}
Row {
spacing: Theme.spacingM
anchors.verticalCenter: parent.verticalCenter
visible: NetworkManagerService.networkStatus !== "disconnected" || (BluetoothService.available && BluetoothService.enabled) || (AudioService.sink && AudioService.sink.audio)
visible: NetworkService.networkStatus !== "disconnected" || (BluetoothService.available && BluetoothService.enabled) || (AudioService.sink && AudioService.sink.audio)
DankIcon {
name: NetworkManagerService.networkStatus === "ethernet" ? "lan" : NetworkManagerService.wifiSignalIcon
name: NetworkService.networkStatus === "ethernet" ? "lan" : NetworkService.wifiSignalIcon
size: Theme.iconSize - 2
color: NetworkManagerService.networkStatus !== "disconnected" ? "white" : Qt.rgba(255, 255, 255, 0.5)
color: NetworkService.networkStatus !== "disconnected" ? "white" : Qt.rgba(255, 255, 255, 0.5)
anchors.verticalCenter: parent.verticalCenter
visible: NetworkManagerService.networkStatus !== "disconnected"
visible: NetworkService.networkStatus !== "disconnected"
}
DankIcon {
@@ -955,7 +955,7 @@ Item {
height: 24
color: Qt.rgba(255, 255, 255, 0.2)
anchors.verticalCenter: parent.verticalCenter
visible: BatteryService.batteryAvailable && (NetworkManagerService.networkStatus !== "disconnected" || BluetoothService.enabled || (AudioService.sink && AudioService.sink.audio))
visible: BatteryService.batteryAvailable && (NetworkService.networkStatus !== "disconnected" || BluetoothService.enabled || (AudioService.sink && AudioService.sink.audio))
}
Row {

File diff suppressed because it is too large Load Diff

236
Services/NetworkService.qml Normal file
View File

@@ -0,0 +1,236 @@
pragma Singleton
pragma ComponentBehavior: Bound
import QtQuick
import Quickshell
import Quickshell.Io
import qs.Common
Singleton {
id: root
property bool networkAvailable: activeService !== null
property string networkStatus: activeService?.networkStatus ?? "disconnected"
property string primaryConnection: activeService?.primaryConnection ?? ""
property string ethernetIP: activeService?.ethernetIP ?? ""
property string ethernetInterface: activeService?.ethernetInterface ?? ""
property bool ethernetConnected: activeService?.ethernetConnected ?? false
property string ethernetConnectionUuid: activeService?.ethernetConnectionUuid ?? ""
property string wifiIP: activeService?.wifiIP ?? ""
property string wifiInterface: activeService?.wifiInterface ?? ""
property bool wifiConnected: activeService?.wifiConnected ?? false
property bool wifiEnabled: activeService?.wifiEnabled ?? true
property string wifiConnectionUuid: activeService?.wifiConnectionUuid ?? ""
property string wifiDevicePath: activeService?.wifiDevicePath ?? ""
property string activeAccessPointPath: activeService?.activeAccessPointPath ?? ""
property string currentWifiSSID: activeService?.currentWifiSSID ?? ""
property int wifiSignalStrength: activeService?.wifiSignalStrength ?? 0
property var wifiNetworks: activeService?.wifiNetworks ?? []
property var savedConnections: activeService?.savedConnections ?? []
property var ssidToConnectionName: activeService?.ssidToConnectionName ?? ({})
property var wifiSignalIcon: activeService?.wifiSignalIcon ?? "wifi_off"
property string userPreference: activeService?.userPreference ?? "auto"
property bool isConnecting: activeService?.isConnecting ?? false
property string connectingSSID: activeService?.connectingSSID ?? ""
property string connectionError: activeService?.connectionError ?? ""
property bool isScanning: activeService?.isScanning ?? false
property bool autoScan: activeService?.autoScan ?? false
property bool wifiAvailable: activeService?.wifiAvailable ?? true
property bool wifiToggling: activeService?.wifiToggling ?? false
property bool changingPreference: activeService?.changingPreference ?? false
property string targetPreference: activeService?.targetPreference ?? ""
property var savedWifiNetworks: activeService?.savedWifiNetworks ?? []
property string connectionStatus: activeService?.connectionStatus ?? ""
property string lastConnectionError: activeService?.lastConnectionError ?? ""
property bool passwordDialogShouldReopen: activeService?.passwordDialogShouldReopen ?? false
property bool autoRefreshEnabled: activeService?.autoRefreshEnabled ?? false
property string wifiPassword: activeService?.wifiPassword ?? ""
property string forgetSSID: activeService?.forgetSSID ?? ""
property string networkInfoSSID: activeService?.networkInfoSSID ?? ""
property string networkInfoDetails: activeService?.networkInfoDetails ?? ""
property bool networkInfoLoading: activeService?.networkInfoLoading ?? false
property int refCount: activeService?.refCount ?? 0
property bool stateInitialized: activeService?.stateInitialized ?? false
property bool subscriptionConnected: activeService?.subscriptionConnected ?? false
signal networksUpdated
signal connectionChanged
property bool usingLegacy: false
property var activeService: null
readonly property string socketPath: Quickshell.env("DMS_SOCKET")
Component.onCompleted: {
console.log("NetworkService: Initializing...")
if (!socketPath || socketPath.length === 0) {
console.log("NetworkService: DMS_SOCKET not set, using LegacyNetworkService")
useLegacyService()
} else {
console.log("NetworkService: DMS_SOCKET found, waiting for capabilities...")
}
}
Connections {
target: NetworkManagerService
function onNetworkAvailableChanged() {
if (!activeService && NetworkManagerService.networkAvailable) {
console.log("NetworkService: Network capability detected, using NetworkManagerService")
activeService = NetworkManagerService
usingLegacy = false
console.log("NetworkService: Switched to NetworkManagerService, networkAvailable:", networkAvailable)
connectSignals()
} else if (!activeService && !NetworkManagerService.networkAvailable && socketPath && socketPath.length > 0) {
console.log("NetworkService: Network capability not available in DMS, using LegacyNetworkService")
useLegacyService()
}
}
}
function useLegacyService() {
activeService = LegacyNetworkService
usingLegacy = true
console.log("NetworkService: Switched to LegacyNetworkService, networkAvailable:", networkAvailable)
if (LegacyNetworkService.activate) {
LegacyNetworkService.activate()
}
connectSignals()
}
function connectSignals() {
if (activeService) {
if (activeService.networksUpdated) {
activeService.networksUpdated.connect(root.networksUpdated)
}
if (activeService.connectionChanged) {
activeService.connectionChanged.connect(root.connectionChanged)
}
}
}
function addRef() {
if (activeService && activeService.addRef) {
activeService.addRef()
}
}
function removeRef() {
if (activeService && activeService.removeRef) {
activeService.removeRef()
}
}
function getState() {
if (activeService && activeService.getState) {
activeService.getState()
}
}
function scanWifi() {
if (activeService && activeService.scanWifi) {
activeService.scanWifi()
}
}
function scanWifiNetworks() {
if (activeService && activeService.scanWifiNetworks) {
activeService.scanWifiNetworks()
}
}
function connectToWifi(ssid, password = "", username = "") {
if (activeService && activeService.connectToWifi) {
activeService.connectToWifi(ssid, password, username)
}
}
function disconnectWifi() {
if (activeService && activeService.disconnectWifi) {
activeService.disconnectWifi()
}
}
function forgetWifiNetwork(ssid) {
if (activeService && activeService.forgetWifiNetwork) {
activeService.forgetWifiNetwork(ssid)
}
}
function toggleWifiRadio() {
if (activeService && activeService.toggleWifiRadio) {
activeService.toggleWifiRadio()
}
}
function enableWifiDevice() {
if (activeService && activeService.enableWifiDevice) {
activeService.enableWifiDevice()
}
}
function setNetworkPreference(preference) {
if (activeService && activeService.setNetworkPreference) {
activeService.setNetworkPreference(preference)
}
}
function setConnectionPriority(type) {
if (activeService && activeService.setConnectionPriority) {
activeService.setConnectionPriority(type)
}
}
function connectToWifiAndSetPreference(ssid, password, username = "") {
if (activeService && activeService.connectToWifiAndSetPreference) {
activeService.connectToWifiAndSetPreference(ssid, password, username)
}
}
function toggleNetworkConnection(type) {
if (activeService && activeService.toggleNetworkConnection) {
activeService.toggleNetworkConnection(type)
}
}
function startAutoScan() {
if (activeService && activeService.startAutoScan) {
activeService.startAutoScan()
}
}
function stopAutoScan() {
if (activeService && activeService.stopAutoScan) {
activeService.stopAutoScan()
}
}
function fetchNetworkInfo(ssid) {
if (activeService && activeService.fetchNetworkInfo) {
activeService.fetchNetworkInfo(ssid)
}
}
function getNetworkInfo(ssid) {
if (activeService && activeService.getNetworkInfo) {
return activeService.getNetworkInfo(ssid)
}
return null
}
function refreshNetworkState() {
if (activeService && activeService.refreshNetworkState) {
activeService.refreshNetworkState()
}
}
}

View File

@@ -311,28 +311,24 @@ Singleton {
}
function initializeDMSConnection() {
if (!socketPath || socketPath.length === 0) {
console.log("SessionService: DMS_SOCKET not set, using fallback")
initFallbackLoginctl()
return
}
try {
dmsService = Qt.createQmlObject('import QtQuick; import qs.Services; QtObject { property var service: DMSService }', root)
if (dmsService && dmsService.service) {
checkCapabilities()
dmsService.service.connectionStateChanged.connect(onDMSConnectionStateChanged)
dmsService.service.capabilitiesChanged.connect(onDMSCapabilitiesChanged)
if (!dmsService.service.isConnected) {
Qt.callLater(checkFallback)
}
checkCapabilities()
} else {
console.warn("SessionService: Failed to get DMS service reference")
Qt.callLater(checkFallback)
console.warn("SessionService: Failed to get DMS service reference, using fallback")
initFallbackLoginctl()
}
} catch (e) {
console.warn("SessionService: Failed to initialize DMS connection:", e)
Qt.callLater(checkFallback)
}
}
function checkFallback() {
if (!loginctlAvailable) {
console.log("SessionService: DMS not available, using fallback methods")
console.warn("SessionService: Failed to initialize DMS connection, using fallback:", e)
initFallbackLoginctl()
}
}
@@ -350,13 +346,18 @@ Singleton {
}
function onDMSCapabilitiesChanged() {
if (dmsService && dmsService.service && dmsService.service.capabilities.includes("loginctl")) {
if (dmsService && dmsService.service) {
if (dmsService.service.capabilities.includes("loginctl")) {
loginctlAvailable = true
if (dmsService.service.isConnected && !stateInitialized) {
stateInitialized = true
getLoginctlState()
subscriptionSocket.connected = true
}
} else if (dmsService.service.capabilities.length > 0 && !loginctlAvailable) {
console.log("SessionService: loginctl capability not available in DMS, using fallback")
initFallbackLoginctl()
}
}
}
@@ -368,6 +369,9 @@ Singleton {
stateInitialized = true
getLoginctlState()
subscriptionSocket.connected = true
} else if (!loginctlAvailable) {
console.log("SessionService: loginctl capability not available in DMS, using fallback")
initFallbackLoginctl()
}
}
}