summaryrefslogtreecommitdiff
path: root/raveos-hyprland-theme/theme-data/dms/Services/NetworkService.qml
blob: 38383d289bb084815591caa2a789e497eb6030f3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
pragma Singleton
pragma ComponentBehavior: Bound

import QtQuick
import Quickshell

Singleton {
    id: root

    property bool networkAvailable: activeService !== null
    property string backend: activeService?.backend ?? ""
    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 var ethernetDevices: activeService?.ethernetDevices ?? []

    property var wiredConnections: activeService?.wiredConnections ?? []

    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 var wifiDevices: activeService?.wifiDevices ?? []
    property string wifiDeviceOverride: activeService?.wifiDeviceOverride ?? ""
    property string connectingDevice: activeService?.connectingDevice ?? ""

    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 string networkWiredInfoUUID: activeService?.networkWiredInfoUUID ?? ""
    property string networkWiredInfoDetails: activeService?.networkWiredInfoDetails ?? ""
    property bool networkWiredInfoLoading: activeService?.networkWiredInfoLoading ?? false

    property int refCount: activeService?.refCount ?? 0
    property bool stateInitialized: activeService?.stateInitialized ?? false

    property bool subscriptionConnected: activeService?.subscriptionConnected ?? false

    property var vpnProfiles: activeService?.vpnProfiles ?? []
    property var vpnActive: activeService?.vpnActive ?? []
    property bool vpnAvailable: activeService?.vpnAvailable ?? false
    property bool vpnIsBusy: activeService?.vpnIsBusy ?? false
    property bool vpnConnected: activeService?.vpnConnected ?? false
    property string vpnActiveUuid: activeService?.activeUuid ?? ""
    property string vpnActiveName: activeService?.activeName ?? ""

    property string credentialsToken: activeService?.credentialsToken ?? ""
    property string credentialsSSID: activeService?.credentialsSSID ?? ""
    property string credentialsSetting: activeService?.credentialsSetting ?? ""
    property var credentialsFields: activeService?.credentialsFields ?? []
    property var credentialsHints: activeService?.credentialsHints ?? []
    property string credentialsReason: activeService?.credentialsReason ?? ""
    property bool credentialsRequested: activeService?.credentialsRequested ?? false

    signal networksUpdated
    signal connectionChanged
    signal credentialsNeeded(string token, string ssid, string setting, var fields, var hints, string reason, string connType, string connName, string vpnService, var fieldsInfo)

    property bool usingLegacy: false
    property var activeService: null

    readonly property string socketPath: Quickshell.env("DMS_SOCKET")

    Component.onCompleted: {
        console.info("NetworkService: Initializing...");
        if (!socketPath || socketPath.length === 0) {
            console.info("NetworkService: DMS_SOCKET not set, using LegacyNetworkService");
            useLegacyService();
        } else {
            console.log("NetworkService: DMS_SOCKET found, waiting for capabilities...");
        }
    }

    Connections {
        target: DMSNetworkService

        function onNetworkAvailableChanged() {
            if (!activeService && DMSNetworkService.networkAvailable) {
                console.info("NetworkService: Network capability detected, using DMSNetworkService");
                activeService = DMSNetworkService;
                usingLegacy = false;
                console.info("NetworkService: Switched to DMSNetworkService, networkAvailable:", networkAvailable);
                connectSignals();
            } else if (!activeService && !DMSNetworkService.networkAvailable && socketPath && socketPath.length > 0) {
                console.info("NetworkService: Network capability not available in DMS, using LegacyNetworkService");
                useLegacyService();
            }
        }
    }

    function useLegacyService() {
        activeService = LegacyNetworkService;
        usingLegacy = true;
        console.info("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);
            }
            if (activeService.credentialsNeeded) {
                activeService.credentialsNeeded.connect(root.credentialsNeeded);
            }
        }
    }

    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 = "", anonymousIdentity = "", domainSuffixMatch = "") {
        if (activeService && activeService.connectToWifi) {
            activeService.connectToWifi(ssid, password, username, anonymousIdentity, domainSuffixMatch);
        }
    }

    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 = "", anonymousIdentity = "", domainSuffixMatch = "") {
        if (activeService && activeService.connectToWifiAndSetPreference) {
            activeService.connectToWifiAndSetPreference(ssid, password, username, anonymousIdentity, domainSuffixMatch);
        }
    }

    function toggleNetworkConnection(type) {
        if (activeService && activeService.toggleNetworkConnection) {
            activeService.toggleNetworkConnection(type);
        }
    }

    function disconnectEthernetDevice(deviceName) {
        if (activeService && activeService.disconnectEthernetDevice) {
            activeService.disconnectEthernetDevice(deviceName);
        }
    }

    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 fetchWiredNetworkInfo(uuid) {
        if (activeService && activeService.fetchWiredNetworkInfo) {
            activeService.fetchWiredNetworkInfo(uuid);
        }
    }

    function getNetworkInfo(ssid) {
        if (activeService && activeService.getNetworkInfo) {
            return activeService.getNetworkInfo(ssid);
        }
        return null;
    }

    function getWiredNetworkInfo(uuid) {
        if (activeService && activeService.getWiredNetworkInfo) {
            return activeService.getWiredNetworkInfo(uuid);
        }
        return null;
    }

    function refreshNetworkState() {
        if (activeService && activeService.refreshNetworkState) {
            activeService.refreshNetworkState();
        }
    }

    function connectToSpecificWiredConfig(uuid) {
        if (activeService && activeService.connectToSpecificWiredConfig) {
            activeService.connectToSpecificWiredConfig(uuid);
        }
    }

    function submitCredentials(token, secrets, save) {
        if (activeService && activeService.submitCredentials) {
            activeService.submitCredentials(token, secrets, save);
        }
    }

    function cancelCredentials(token) {
        if (activeService && activeService.cancelCredentials) {
            activeService.cancelCredentials(token);
        }
    }

    function setWifiAutoconnect(ssid, autoconnect) {
        if (activeService && activeService.setWifiAutoconnect) {
            activeService.setWifiAutoconnect(ssid, autoconnect);
        }
    }

    function setWifiDeviceOverride(deviceName) {
        if (activeService && activeService.setWifiDeviceOverride) {
            activeService.setWifiDeviceOverride(deviceName);
        }
    }
}