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:
1094
Services/LegacyNetworkService.qml
Normal file
1094
Services/LegacyNetworkService.qml
Normal file
File diff suppressed because it is too large
Load Diff
236
Services/NetworkService.qml
Normal file
236
Services/NetworkService.qml
Normal 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()
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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,12 +346,17 @@ Singleton {
|
||||
}
|
||||
|
||||
function onDMSCapabilitiesChanged() {
|
||||
if (dmsService && dmsService.service && dmsService.service.capabilities.includes("loginctl")) {
|
||||
loginctlAvailable = true
|
||||
if (dmsService.service.isConnected && !stateInitialized) {
|
||||
stateInitialized = true
|
||||
getLoginctlState()
|
||||
subscriptionSocket.connected = true
|
||||
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()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user