Files
08dde7f79a add: Cellular Network support (rebase of #2765) (#3096)
* feat: add cellular support

* fix(settings): resolve cellular tab index collision

* fix: address review feedback for cellular support

Bump the network API version, drop the deleted term freeze file,
regenerate the settings search index, and reuse existing translation
terms where they already cover the new cellular UI.

* fix: do not assign readonly userPreference when switching network type

Assigning SettingsData.networkPreference through the readonly alias
threw on click, so the Cellular segment in Control Center did nothing.

* fix: make Cellular selectable and the modem row clickable

The Control Center type switcher was bound only to preference, so
Cellular snapped back to Ethernet. The settings modem row highlighted
on hover but had no click handler. Show the modem as a connect target
when no APN profiles exist.

* fix: create a GSM profile when connecting cellular with none saved

Clicking Mobile broadband only activated an existing profile, so a
modem with no APN did nothing useful. Fall back to AddAndActivate
like ethernet connect.

* fix: address second round of cellular review feedback

- Guard cellularDevices map with devMutex via snapshot/by-iface/set/remove
  helpers, mirroring the existing ethernet and wifi accessors
- Regenerate mocks with mockery v3 instead of hand-editing mock_Backend.go
- Reuse refreshCellularState() in SetCellularEnabled, DisconnectCellular,
  DisconnectCellularDevice, ActivateCellularConnection and device removal
- Wrap retryErr rather than the first error when the auto-config retry fails
- Use Theme.surfaceTextSecondary/primaryHover/primaryHoverLight in the
  cellular-off state instead of hand-rolled Qt.rgba values
- Drop the duplicate "No devices found" label so it can no longer render
  twice with no modem and no saved config

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>

* fix: address remaining cellular review comments

- Toast "Failed to toggle cellular" instead of always "enable"
- Remove unused enableCellularRadio() wrappers
- Store Control Center network type as a value, not a list index

* fix: pass nmcli connection selector as separate argument

`nmcli con mod uuid:<UUID>` is not valid syntax -- nmcli expects the
selector keyword as its own argument, so every priority update failed
with "no such connection profile". Because practically every NM profile
has a UUID, this silently disabled autoconnect-priority and route-metric
updates for ethernet and WiFi as well as cellular.

Also fix the Cellular settings status text, which said "Connecting..."
for a flag that only tracks radio enable/disable, and add the seven
cellular terms that were missing from the translation catalogs.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>

* apply review comments

* fix lints

* update debug doc

* fix style inconsistencies

---------

Co-authored-by: Yechiel Worenklein <[email protected]>
Co-authored-by: Claude Opus 5 (1M context) <[email protected]>
Co-authored-by: bbedward <[email protected]>
2026-08-29 15:37:36 -04:00

410 lines
16 KiB
QML

pragma Singleton
pragma ComponentBehavior: Bound
import QtQuick
import Quickshell
import qs.Services
Singleton {
id: root
readonly property var log: Log.scoped("NetworkService")
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 cellularIP: activeService?.cellularIP ?? ""
property string cellularInterface: activeService?.cellularInterface ?? ""
property bool cellularConnected: activeService?.cellularConnected ?? false
property bool cellularEnabled: activeService?.cellularEnabled ?? true
property bool cellularHardwareEnabled: activeService?.cellularHardwareEnabled ?? true
property string cellularConnectionUuid: activeService?.cellularConnectionUuid ?? ""
property var cellularDevices: activeService?.cellularDevices ?? []
property var cellularConnections: activeService?.cellularConnections ?? []
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
readonly property bool isWifiConnecting: isConnecting && !ethernetConnected && !wifiToggling
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 cellularToggling: activeService?.cellularToggling ?? false
property bool changingPreference: activeService?.changingPreference ?? false
property string targetPreference: activeService?.targetPreference ?? ""
property var savedWifiNetworks: activeService?.savedWifiNetworks ?? []
readonly property int savedWifiStateApiVersion: activeService?.savedWifiStateApiVersion ?? 26
readonly property int hotspotApiVersion: activeService?.hotspotApiVersion ?? 28
property bool hotspotSupported: activeService?.hotspotSupported ?? false
property bool hotspotAvailable: activeService?.hotspotAvailable ?? false
property bool hotspotConfigured: activeService?.hotspotConfigured ?? false
property bool hotspotEnabled: activeService?.hotspotEnabled ?? false
property bool hotspotActivating: activeService?.hotspotActivating ?? false
property bool hotspotSecured: activeService?.hotspotSecured ?? false
property bool hotspotWouldDisconnectWifi: activeService?.hotspotWouldDisconnectWifi ?? false
property string hotspotSSID: activeService?.hotspotSSID ?? ""
property string hotspotDevice: activeService?.hotspotDevice ?? ""
property string hotspotBand: activeService?.hotspotBand ?? ""
property bool hotspotBusy: activeService?.hotspotBusy ?? false
property string hotspotError: activeService?.hotspotError ?? ""
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 var activeService: null
readonly property string socketPath: Quickshell.env("DMS_SOCKET")
// Backend adoption must be state-checked here, not only edge-triggered below:
// with staged shell loading this singleton can be instantiated after
// DMSNetworkService already resolved its capabilities, so the change signal
// may never fire again.
Component.onCompleted: {
log.info("Initializing...");
if (!socketPath || socketPath.length === 0) {
log.info("DMS_SOCKET not set, network backend unavailable");
return;
}
if (DMSNetworkService.networkAvailable) {
log.info("Network capability already available, using DMSNetworkService");
useDMSService();
return;
}
log.debug("DMS_SOCKET found, waiting for capabilities...");
}
Connections {
target: DMSNetworkService
function onNetworkAvailableChanged() {
if (!activeService && DMSNetworkService.networkAvailable) {
log.info("Network capability detected, using DMSNetworkService");
useDMSService();
}
}
}
function useDMSService() {
activeService = DMSNetworkService;
log.info("Switched to DMSNetworkService, networkAvailable:", networkAvailable);
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 refreshSavedWifiNetworks() {
if (activeService && activeService.refreshSavedWifiNetworks) {
activeService.refreshSavedWifiNetworks();
}
}
function connectToWifi(ssid, password = "", username = "", anonymousIdentity = "", domainSuffixMatch = "", hidden = false, eapMethod = "", phase2Auth = "") {
if (activeService && activeService.connectToWifi) {
activeService.connectToWifi(ssid, password, username, anonymousIdentity, domainSuffixMatch, hidden, eapMethod, phase2Auth);
}
}
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 toggleCellularRadio() {
if (activeService && activeService.toggleCellularRadio) {
activeService.toggleCellularRadio();
}
}
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 = "", hidden = false, eapMethod = "", phase2Auth = "") {
if (activeService && activeService.connectToWifiAndSetPreference) {
activeService.connectToWifiAndSetPreference(ssid, password, username, anonymousIdentity, domainSuffixMatch, hidden, eapMethod, phase2Auth);
}
}
function toggleNetworkConnection(type) {
if (activeService && activeService.toggleNetworkConnection) {
activeService.toggleNetworkConnection(type);
}
}
function disconnectEthernetDevice(deviceName) {
if (activeService && activeService.disconnectEthernetDevice) {
activeService.disconnectEthernetDevice(deviceName);
}
}
function disconnectCellularDevice(deviceName) {
if (activeService && activeService.disconnectCellularDevice) {
activeService.disconnectCellularDevice(deviceName);
}
}
function connectCellular() {
if (activeService && activeService.connectCellular) {
activeService.connectCellular();
}
}
function connectToSpecificCellularConfig(uuid) {
if (activeService && activeService.connectToSpecificCellularConfig) {
activeService.connectToSpecificCellularConfig(uuid);
}
}
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 configureHotspot(ssid, password = "", device = "", band = "", callback = null) {
if (activeService && activeService.configureHotspot) {
return activeService.configureHotspot(ssid, password, device, band, callback);
}
return false;
}
function startHotspot(callback = null) {
if (activeService && activeService.startHotspot) {
return activeService.startHotspot(callback);
}
return false;
}
function stopHotspot(callback = null) {
if (activeService && activeService.stopHotspot) {
return activeService.stopHotspot(callback);
}
return false;
}
function configureAndStartHotspot(ssid, password = "", device = "", band = "", callback = null) {
if (activeService && activeService.configureAndStartHotspot) {
return activeService.configureAndStartHotspot(ssid, password, device, band, callback);
}
return false;
}
function getHotspotSecrets(callback) {
if (activeService && activeService.getHotspotSecrets) {
return activeService.getHotspotSecrets(callback);
}
return false;
}
function hotspotTargetWouldDisconnectWifi(device, band = "") {
if (activeService && activeService.hotspotTargetWouldDisconnectWifi) {
return activeService.hotspotTargetWouldDisconnectWifi(device, band);
}
return false;
}
function setWifiDeviceOverride(deviceName) {
if (activeService && activeService.setWifiDeviceOverride) {
activeService.setWifiDeviceOverride(deviceName);
}
}
}