mirror of
https://github.com/AvengeMedia/DankMaterialShell.git
synced 2026-08-02 03:28:28 -04:00
feat(network): initial WiFi hotspot support (#2825)
* Add hotspot contract layer with capability-gated dispatch. Establish the interface and manager plumbing for hotspot support so backends can opt in without expanding the core Backend contract. Only backends that implement HotspotBackend get hotspot state propagated; others are forced to unsupported regardless of what they self-report. * Add IPC handlers and API docs for hotspot actions. Wire up configure/ start/ stop hotspot through the request router so the QML service layer can drive hotspot operations. Bump API version to 27 and document the capability-gating contract clients should follow. * Implement NetworkManager hotspot backend. Implement HotspotBackend on NetworkManagerBackend with DMS-owned profile management, AP capability detection, and band validation. Device resolution is deferred to StartHotspot when no device is specified, so profiles survive hardware changes. * Isolate client Wi-Fi state from AP-mode connections. Filter AP-mode profiles and access points out of all client Wi-Fi paths so the DMS hotspot (and user-created APs) never appear as saved networks, visible networks, or connected state. This protects existing client behavior before hotspot controls are exposed in the UI. * Prefer idle radios for automatic hotspot device selection. * Add hotspot properties and methods to QML service layer. Expose hotspot state and actions through DMSNetworkService, NetworkService, and LegacyNetworkService. Capability is gated on API version and backend-reported support, not backend name checks, and stays stable when Wi-Fi radio is disabled. * Add hotspot controls to Settings and Control Center. Settings shows a hotspot setup card as a sibling in the Wi-Fi tab with SSID, password, device, band, save, and start/ stop controls. Control Center shows a compact row that toggles a configured hotspot or routes to Settings for initial setup. Both stay visible when Wi-Fi is disabled, explaining the requirement instead of hiding. * Add translator context to hotspot strings.
This commit is contained in:
@@ -6,6 +6,7 @@ import qs.Modules.Network
|
||||
import qs.Services
|
||||
import qs.Widgets
|
||||
import qs.Modals
|
||||
import qs.Modals.Common
|
||||
|
||||
Rectangle {
|
||||
id: root
|
||||
@@ -17,10 +18,10 @@ Rectangle {
|
||||
if (height > 0)
|
||||
return height;
|
||||
if (NetworkService.wifiToggling)
|
||||
return headerRow.height + wifiToggleContent.height + Theme.spacingM;
|
||||
return headerRow.height + hotspotContentHeight + wifiToggleContent.height + Theme.spacingM;
|
||||
if (NetworkService.wifiEnabled)
|
||||
return headerRow.height + wifiContent.height + Theme.spacingM;
|
||||
return headerRow.height + wifiOffContent.height + Theme.spacingM;
|
||||
return headerRow.height + hotspotContentHeight + wifiContent.height + Theme.spacingM;
|
||||
return headerRow.height + hotspotContentHeight + wifiOffContent.height + Theme.spacingM;
|
||||
}
|
||||
radius: Theme.cornerRadius
|
||||
color: Theme.nestedSurface
|
||||
@@ -39,6 +40,31 @@ Rectangle {
|
||||
property bool hasWifiAvailable: (NetworkService.wifiDevices?.length ?? 0) > 0
|
||||
property bool hasBothConnectionTypes: hasEthernetAvailable && hasWifiAvailable
|
||||
property int maxPinnedNetworks: 3
|
||||
readonly property int hotspotContentHeight: currentPreferenceIndex === 1 && NetworkService.hotspotAvailable ? 56 + Theme.spacingS : 0
|
||||
|
||||
property var hotspotStartConfirm: ConfirmModal {}
|
||||
|
||||
function explainHotspotNeedsWiFi() {
|
||||
ToastService.showError(I18n.tr("WiFi is disabled", "hotspot start error title"), I18n.tr("Enable WiFi before starting the hotspot.", "hotspot WiFi requirement message"));
|
||||
}
|
||||
|
||||
function startHotspotWithConfirm() {
|
||||
if (!NetworkService.hotspotWouldDisconnectWifi) {
|
||||
NetworkService.startHotspot();
|
||||
return;
|
||||
}
|
||||
hotspotStartConfirm.showWithOptions({
|
||||
title: I18n.tr("Start Hotspot?", "hotspot start confirmation title"),
|
||||
message: I18n.tr("This will disconnect WiFi from \"%1\" — the radio can't host a hotspot and stay connected at the same time. Internet sharing will need another connection, such as Ethernet.", "hotspot WiFi disconnection confirmation message").arg(NetworkService.currentWifiSSID),
|
||||
confirmText: I18n.tr("Start", "hotspot start confirmation action"),
|
||||
onConfirm: () => NetworkService.startHotspot()
|
||||
});
|
||||
}
|
||||
|
||||
function openHotspotSettings() {
|
||||
PopoutService.closeControlCenter();
|
||||
PopoutService.openSettingsWithTab("network_wifi");
|
||||
}
|
||||
|
||||
function normalizePinList(value) {
|
||||
if (Array.isArray(value))
|
||||
@@ -159,12 +185,183 @@ Rectangle {
|
||||
}
|
||||
|
||||
Item {
|
||||
id: wifiToggleContent
|
||||
id: hotspotRow
|
||||
anchors.top: headerRow.bottom
|
||||
anchors.left: parent.left
|
||||
anchors.right: parent.right
|
||||
anchors.margins: Theme.spacingM
|
||||
anchors.topMargin: Theme.spacingM
|
||||
visible: currentPreferenceIndex === 1 && NetworkService.hotspotAvailable
|
||||
height: visible ? 56 : 0
|
||||
|
||||
Rectangle {
|
||||
anchors.fill: parent
|
||||
radius: Theme.cornerRadius
|
||||
color: hotspotMouseArea.containsMouse ? Theme.primaryHoverLight : Theme.surfaceLight
|
||||
border.width: NetworkService.hotspotEnabled ? 2 : 1
|
||||
border.color: NetworkService.hotspotEnabled ? Theme.primary : Theme.outlineLight
|
||||
|
||||
Row {
|
||||
anchors.left: parent.left
|
||||
anchors.leftMargin: Theme.spacingM
|
||||
anchors.right: hotspotRightControls.left
|
||||
anchors.rightMargin: Theme.spacingS
|
||||
anchors.verticalCenter: parent.verticalCenter
|
||||
spacing: Theme.spacingS
|
||||
|
||||
DankIcon {
|
||||
name: NetworkService.hotspotEnabled ? "wifi_tethering" : "wifi_tethering_off"
|
||||
size: Theme.iconSize - 4
|
||||
color: NetworkService.hotspotEnabled ? Theme.primary : Theme.surfaceText
|
||||
anchors.verticalCenter: parent.verticalCenter
|
||||
}
|
||||
|
||||
Column {
|
||||
id: hotspotTextColumn
|
||||
|
||||
readonly property bool warnsWifiDrop: NetworkService.hotspotConfigured && NetworkService.wifiEnabled && !NetworkService.hotspotBusy && !NetworkService.hotspotActivating && !NetworkService.hotspotEnabled && NetworkService.hotspotWouldDisconnectWifi
|
||||
|
||||
anchors.verticalCenter: parent.verticalCenter
|
||||
spacing: 2
|
||||
width: parent.width - Theme.iconSize - Theme.spacingS
|
||||
|
||||
StyledText {
|
||||
text: NetworkService.hotspotConfigured ? I18n.tr("Hotspot", "hotspot control label") : I18n.tr("Set up hotspot", "hotspot setup action label")
|
||||
font.pixelSize: Theme.fontSizeMedium
|
||||
font.weight: NetworkService.hotspotEnabled ? Font.Medium : Font.Normal
|
||||
color: NetworkService.hotspotEnabled ? Theme.primary : Theme.surfaceText
|
||||
elide: Text.ElideRight
|
||||
width: parent.width
|
||||
}
|
||||
|
||||
StyledText {
|
||||
visible: !hotspotTextColumn.warnsWifiDrop
|
||||
text: {
|
||||
if (!NetworkService.hotspotConfigured)
|
||||
return I18n.tr("Set up hotspot in Settings", "unconfigured hotspot status message");
|
||||
if (NetworkService.hotspotBusy || NetworkService.hotspotActivating)
|
||||
return I18n.tr("Starting...", "hotspot activation status");
|
||||
if (NetworkService.hotspotEnabled)
|
||||
return NetworkService.hotspotSSID || I18n.tr("Running", "hotspot active status");
|
||||
if (!NetworkService.wifiEnabled)
|
||||
return I18n.tr("WiFi disabled", "hotspot unavailable status");
|
||||
return NetworkService.hotspotSSID || I18n.tr("Ready", "hotspot ready status");
|
||||
}
|
||||
font.pixelSize: Theme.fontSizeSmall
|
||||
color: NetworkService.hotspotEnabled ? Theme.primary : Theme.surfaceVariantText
|
||||
elide: Text.ElideRight
|
||||
width: parent.width
|
||||
}
|
||||
|
||||
Row {
|
||||
visible: hotspotTextColumn.warnsWifiDrop
|
||||
width: parent.width
|
||||
spacing: Theme.spacingXS
|
||||
|
||||
StyledText {
|
||||
id: hotspotWarnSsid
|
||||
text: NetworkService.hotspotSSID || I18n.tr("Ready", "hotspot ready status")
|
||||
font.pixelSize: Theme.fontSizeSmall
|
||||
color: Theme.surfaceVariantText
|
||||
elide: Text.ElideRight
|
||||
width: Math.min(implicitWidth, parent.width / 2)
|
||||
}
|
||||
|
||||
StyledText {
|
||||
id: hotspotWarnSeparator
|
||||
text: "•"
|
||||
font.pixelSize: Theme.fontSizeSmall
|
||||
color: Theme.surfaceVariantText
|
||||
}
|
||||
|
||||
StyledText {
|
||||
text: I18n.tr("Will disconnect \"%1\"", "hotspot WiFi disconnection warning").arg(NetworkService.currentWifiSSID)
|
||||
font.pixelSize: Theme.fontSizeSmall
|
||||
color: Theme.warning
|
||||
elide: Text.ElideRight
|
||||
width: Math.max(0, parent.width - hotspotWarnSsid.width - hotspotWarnSeparator.width - Theme.spacingXS * 2)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Row {
|
||||
id: hotspotRightControls
|
||||
anchors.right: parent.right
|
||||
anchors.rightMargin: Theme.spacingM
|
||||
anchors.verticalCenter: parent.verticalCenter
|
||||
spacing: Theme.spacingS
|
||||
|
||||
StyledText {
|
||||
text: I18n.tr("Setup", "hotspot setup action")
|
||||
font.pixelSize: Theme.fontSizeSmall
|
||||
color: Theme.primary
|
||||
visible: !NetworkService.hotspotConfigured
|
||||
anchors.verticalCenter: parent.verticalCenter
|
||||
}
|
||||
|
||||
DankIcon {
|
||||
name: "chevron_right"
|
||||
size: 20
|
||||
color: Theme.primary
|
||||
visible: !NetworkService.hotspotConfigured
|
||||
anchors.verticalCenter: parent.verticalCenter
|
||||
}
|
||||
|
||||
DankSpinner {
|
||||
readonly property bool hotspotWorking: NetworkService.hotspotBusy || NetworkService.hotspotActivating
|
||||
size: 20
|
||||
strokeWidth: 2
|
||||
color: Theme.primary
|
||||
running: hotspotWorking
|
||||
visible: NetworkService.hotspotConfigured && hotspotWorking
|
||||
anchors.verticalCenter: parent.verticalCenter
|
||||
}
|
||||
|
||||
DankToggle {
|
||||
readonly property bool hotspotWorking: NetworkService.hotspotBusy || NetworkService.hotspotActivating
|
||||
checked: NetworkService.hotspotEnabled
|
||||
enabled: NetworkService.hotspotConfigured && !hotspotWorking
|
||||
visible: NetworkService.hotspotConfigured && !hotspotWorking
|
||||
onToggled: checked => {
|
||||
if (checked) {
|
||||
if (!NetworkService.wifiEnabled) {
|
||||
root.explainHotspotNeedsWiFi();
|
||||
return;
|
||||
}
|
||||
root.startHotspotWithConfirm();
|
||||
} else {
|
||||
NetworkService.stopHotspot();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
DankRipple {
|
||||
id: hotspotRipple
|
||||
cornerRadius: parent.radius
|
||||
}
|
||||
|
||||
MouseArea {
|
||||
id: hotspotMouseArea
|
||||
anchors.fill: parent
|
||||
hoverEnabled: true
|
||||
cursorShape: Qt.PointingHandCursor
|
||||
enabled: !NetworkService.hotspotConfigured
|
||||
visible: !NetworkService.hotspotConfigured
|
||||
onPressed: mouse => hotspotRipple.trigger(mouse.x, mouse.y)
|
||||
onClicked: root.openHotspotSettings()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Item {
|
||||
id: wifiToggleContent
|
||||
anchors.top: hotspotRow.visible ? hotspotRow.bottom : headerRow.bottom
|
||||
anchors.left: parent.left
|
||||
anchors.right: parent.right
|
||||
anchors.margins: Theme.spacingM
|
||||
anchors.topMargin: hotspotRow.visible ? Theme.spacingS : Theme.spacingM
|
||||
visible: currentPreferenceIndex === 1 && NetworkService.wifiToggling
|
||||
height: visible ? wifiToggleColumn.implicitHeight + Theme.spacingM * 2 : 0
|
||||
|
||||
@@ -201,11 +398,11 @@ Rectangle {
|
||||
|
||||
Item {
|
||||
id: wifiOffContent
|
||||
anchors.top: headerRow.bottom
|
||||
anchors.top: hotspotRow.visible ? hotspotRow.bottom : headerRow.bottom
|
||||
anchors.left: parent.left
|
||||
anchors.right: parent.right
|
||||
anchors.margins: Theme.spacingM
|
||||
anchors.topMargin: Theme.spacingM
|
||||
anchors.topMargin: hotspotRow.visible ? Theme.spacingS : Theme.spacingM
|
||||
visible: currentPreferenceIndex === 1 && !NetworkService.wifiEnabled && !NetworkService.wifiToggling
|
||||
height: visible ? wifiOffColumn.implicitHeight + Theme.spacingM * 2 : 0
|
||||
|
||||
@@ -482,12 +679,12 @@ Rectangle {
|
||||
|
||||
Item {
|
||||
id: wifiScanningOverlay
|
||||
anchors.top: headerRow.bottom
|
||||
anchors.top: hotspotRow.visible ? hotspotRow.bottom : headerRow.bottom
|
||||
anchors.left: parent.left
|
||||
anchors.right: parent.right
|
||||
anchors.bottom: parent.bottom
|
||||
anchors.margins: Theme.spacingM
|
||||
anchors.topMargin: Theme.spacingM
|
||||
anchors.topMargin: hotspotRow.visible ? Theme.spacingS : Theme.spacingM
|
||||
visible: currentPreferenceIndex === 1 && NetworkService.wifiEnabled && !NetworkService.wifiToggling && NetworkService.wifiInterface && (NetworkService.wifiNetworks?.length ?? 0) < 1 && NetworkService.isScanning
|
||||
|
||||
DankIcon {
|
||||
@@ -509,12 +706,12 @@ Rectangle {
|
||||
|
||||
DankListView {
|
||||
id: wifiContent
|
||||
anchors.top: headerRow.bottom
|
||||
anchors.top: hotspotRow.visible ? hotspotRow.bottom : headerRow.bottom
|
||||
anchors.left: parent.left
|
||||
anchors.right: parent.right
|
||||
anchors.bottom: parent.bottom
|
||||
anchors.margins: Theme.spacingM
|
||||
anchors.topMargin: Theme.spacingM
|
||||
anchors.topMargin: hotspotRow.visible ? Theme.spacingS : Theme.spacingM
|
||||
visible: currentPreferenceIndex === 1 && NetworkService.wifiEnabled && !NetworkService.wifiToggling && !wifiScanningOverlay.visible
|
||||
clip: true
|
||||
spacing: Theme.spacingS
|
||||
|
||||
@@ -1263,6 +1263,359 @@ Item {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
SettingsCard {
|
||||
id: hotspotCard
|
||||
|
||||
width: parent.width
|
||||
title: I18n.tr("Hotspot", "hotspot settings card title")
|
||||
iconName: "wifi_tethering"
|
||||
settingKey: "networkHotspot"
|
||||
tags: ["wifi", "wi-fi", "wireless", "network", "hotspot", "access point", "sharing", "ssid"]
|
||||
visible: NetworkService.hotspotAvailable
|
||||
|
||||
property string ssid: NetworkService.hotspotSSID || ""
|
||||
property string password: ""
|
||||
property string device: NetworkService.hotspotDevice || ""
|
||||
property string band: NetworkService.hotspotBand || ""
|
||||
property bool editing: false
|
||||
property bool passwordLoading: false
|
||||
property bool passwordResolved: true
|
||||
property int passwordRequestId: 0
|
||||
property int passwordEditRevision: 0
|
||||
readonly property bool showForm: !NetworkService.hotspotConfigured || editing
|
||||
readonly property bool starting: NetworkService.hotspotBusy || NetworkService.hotspotActivating
|
||||
property var startConfirm: ConfirmModal {}
|
||||
|
||||
function confirmThenStart(targetDevice, targetBand, startFn) {
|
||||
if (!NetworkService.hotspotTargetWouldDisconnectWifi(targetDevice, targetBand)) {
|
||||
startFn();
|
||||
return;
|
||||
}
|
||||
startConfirm.showWithOptions({
|
||||
title: I18n.tr("Start Hotspot?", "hotspot start confirmation title"),
|
||||
message: I18n.tr("This will disconnect WiFi from \"%1\" — the radio can't host a hotspot and stay connected at the same time. Internet sharing will need another connection, such as Ethernet.", "hotspot WiFi disconnection confirmation message").arg(NetworkService.currentWifiSSID),
|
||||
confirmText: I18n.tr("Start", "hotspot start confirmation action"),
|
||||
onConfirm: startFn
|
||||
});
|
||||
}
|
||||
|
||||
function bandLabel(value) {
|
||||
switch (value) {
|
||||
case "bg":
|
||||
return I18n.tr("2.4 GHz", "hotspot WiFi band option");
|
||||
case "a":
|
||||
return I18n.tr("5 GHz", "hotspot WiFi band option");
|
||||
default:
|
||||
return I18n.tr("Auto", "hotspot device or band option");
|
||||
}
|
||||
}
|
||||
|
||||
function bandValue(label) {
|
||||
if (label === I18n.tr("2.4 GHz", "hotspot WiFi band option"))
|
||||
return "bg";
|
||||
if (label === I18n.tr("5 GHz", "hotspot WiFi band option"))
|
||||
return "a";
|
||||
return "";
|
||||
}
|
||||
|
||||
function syncFromService() {
|
||||
ssid = NetworkService.hotspotSSID || ssid || "";
|
||||
device = NetworkService.hotspotDevice || "";
|
||||
band = NetworkService.hotspotBand || "";
|
||||
}
|
||||
|
||||
function beginEditing() {
|
||||
syncFromService();
|
||||
password = "";
|
||||
editing = true;
|
||||
passwordRequestId++;
|
||||
const requestId = passwordRequestId;
|
||||
const editRevision = passwordEditRevision;
|
||||
passwordLoading = NetworkService.hotspotSecured;
|
||||
passwordResolved = !NetworkService.hotspotSecured;
|
||||
if (NetworkService.hotspotSecured) {
|
||||
NetworkService.getHotspotSecrets(response => {
|
||||
if (!editing || requestId !== passwordRequestId)
|
||||
return;
|
||||
passwordLoading = false;
|
||||
if (response.error) {
|
||||
ToastService.showError(I18n.tr("Couldn't load hotspot password", "hotspot password error title"), I18n.tr("Re-enter the password before saving.", "hotspot password recovery message"));
|
||||
} else {
|
||||
const storedPassword = response.result?.password ?? response.password ?? "";
|
||||
if (!storedPassword) {
|
||||
ToastService.showError(I18n.tr("Couldn't load hotspot password", "hotspot password error title"), I18n.tr("Re-enter the password before saving.", "hotspot password recovery message"));
|
||||
} else {
|
||||
passwordResolved = true;
|
||||
if (editRevision === passwordEditRevision) {
|
||||
password = storedPassword;
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
function stopEditing() {
|
||||
passwordRequestId++;
|
||||
editing = false;
|
||||
password = "";
|
||||
passwordLoading = false;
|
||||
passwordResolved = true;
|
||||
}
|
||||
|
||||
function buildCanConfigure() {
|
||||
return ssid.trim().length > 0 && passwordResolved && !passwordLoading && !NetworkService.hotspotBusy && !NetworkService.hotspotEnabled && !NetworkService.hotspotActivating;
|
||||
}
|
||||
|
||||
function explainWiFiDisabled() {
|
||||
ToastService.showError(I18n.tr("WiFi is disabled", "hotspot start error title"), I18n.tr("Enable WiFi before starting the hotspot.", "hotspot WiFi requirement message"));
|
||||
}
|
||||
|
||||
function saveOnly() {
|
||||
if (!buildCanConfigure())
|
||||
return;
|
||||
NetworkService.configureHotspot(ssid.trim(), password, device, band, response => {
|
||||
if (!response.error) {
|
||||
stopEditing();
|
||||
ToastService.showInfo(I18n.tr("Hotspot saved", "hotspot configuration success message"));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function startOrStop() {
|
||||
if (NetworkService.hotspotEnabled) {
|
||||
NetworkService.stopHotspot(response => {
|
||||
if (!response.error)
|
||||
ToastService.showInfo(I18n.tr("Hotspot stopped", "hotspot stop success message"));
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
if (!NetworkService.wifiEnabled) {
|
||||
explainWiFiDisabled();
|
||||
return;
|
||||
}
|
||||
|
||||
if (showForm) {
|
||||
if (!buildCanConfigure())
|
||||
return;
|
||||
confirmThenStart(device, band, () => {
|
||||
NetworkService.configureAndStartHotspot(ssid.trim(), password, device, band, response => {
|
||||
if (!response.error)
|
||||
stopEditing();
|
||||
});
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
confirmThenStart(NetworkService.hotspotDevice, NetworkService.hotspotBand, () => NetworkService.startHotspot());
|
||||
}
|
||||
|
||||
onVisibleChanged: if (visible)
|
||||
syncFromService()
|
||||
|
||||
Column {
|
||||
width: parent.width
|
||||
spacing: Theme.spacingM
|
||||
|
||||
StyledText {
|
||||
width: parent.width
|
||||
text: {
|
||||
if (NetworkService.hotspotEnabled)
|
||||
return I18n.tr("Your hotspot is running.", "hotspot active status message");
|
||||
if (hotspotCard.starting)
|
||||
return I18n.tr("Starting hotspot...", "hotspot activation status message");
|
||||
if (NetworkService.hotspotConfigured)
|
||||
return I18n.tr("Your hotspot profile is saved and ready to start.", "configured hotspot status message");
|
||||
return I18n.tr("Set up a WiFi hotspot for sharing this connection.", "unconfigured hotspot description");
|
||||
}
|
||||
font.pixelSize: Theme.fontSizeSmall
|
||||
color: NetworkService.hotspotEnabled ? Theme.primary : Theme.surfaceVariantText
|
||||
wrapMode: Text.WordWrap
|
||||
}
|
||||
|
||||
StyledText {
|
||||
width: parent.width
|
||||
text: I18n.tr("WiFi is disabled. You can still edit and save hotspot settings, but starting the hotspot requires WiFi to be enabled.", "hotspot WiFi requirement explanation")
|
||||
font.pixelSize: Theme.fontSizeSmall
|
||||
color: Theme.warning
|
||||
wrapMode: Text.WordWrap
|
||||
visible: !NetworkService.wifiEnabled
|
||||
}
|
||||
|
||||
StyledText {
|
||||
width: parent.width
|
||||
text: I18n.tr("Starting the hotspot will disconnect WiFi from \"%1\" — the radio can't do both at once. Sharing internet then requires another connection, such as Ethernet.", "hotspot WiFi disconnection warning").arg(NetworkService.currentWifiSSID)
|
||||
font.pixelSize: Theme.fontSizeSmall
|
||||
color: Theme.warning
|
||||
wrapMode: Text.WordWrap
|
||||
visible: NetworkService.wifiEnabled && !NetworkService.hotspotEnabled && !hotspotCard.starting && (hotspotCard.showForm ? NetworkService.hotspotTargetWouldDisconnectWifi(hotspotCard.device, hotspotCard.band) : NetworkService.hotspotWouldDisconnectWifi)
|
||||
}
|
||||
|
||||
Row {
|
||||
width: parent.width
|
||||
spacing: Theme.spacingM
|
||||
visible: !hotspotCard.showForm
|
||||
|
||||
DankIcon {
|
||||
name: NetworkService.hotspotEnabled ? "wifi_tethering" : "wifi_tethering_off"
|
||||
size: Theme.iconSize
|
||||
color: NetworkService.hotspotEnabled ? Theme.primary : Theme.surfaceVariantText
|
||||
anchors.verticalCenter: parent.verticalCenter
|
||||
}
|
||||
|
||||
Column {
|
||||
width: parent.width - Theme.iconSize - Theme.spacingM
|
||||
spacing: 2
|
||||
anchors.verticalCenter: parent.verticalCenter
|
||||
|
||||
StyledText {
|
||||
width: parent.width
|
||||
text: NetworkService.hotspotSSID
|
||||
font.pixelSize: Theme.fontSizeMedium
|
||||
font.weight: Font.Medium
|
||||
color: Theme.surfaceText
|
||||
elide: Text.ElideRight
|
||||
}
|
||||
|
||||
StyledText {
|
||||
width: parent.width
|
||||
text: {
|
||||
const parts = [NetworkService.hotspotSecured ? I18n.tr("WPA2 password", "hotspot security summary") : I18n.tr("Open network", "hotspot security summary"), hotspotCard.bandLabel(NetworkService.hotspotBand)];
|
||||
if (NetworkService.hotspotDevice)
|
||||
parts.push(NetworkService.hotspotDevice);
|
||||
return parts.join(" • ");
|
||||
}
|
||||
font.pixelSize: Theme.fontSizeSmall
|
||||
color: Theme.surfaceVariantText
|
||||
elide: Text.ElideRight
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Column {
|
||||
width: parent.width
|
||||
spacing: Theme.spacingM
|
||||
visible: hotspotCard.showForm
|
||||
|
||||
DankTextField {
|
||||
width: parent.width
|
||||
labelText: I18n.tr("Hotspot name", "hotspot SSID field label")
|
||||
placeholderText: I18n.tr("SSID", "hotspot network name placeholder")
|
||||
text: hotspotCard.ssid
|
||||
leftIconName: "badge"
|
||||
showClearButton: true
|
||||
onTextEdited: hotspotCard.ssid = text
|
||||
onAccepted: hotspotCard.saveOnly()
|
||||
}
|
||||
|
||||
DankTextField {
|
||||
width: parent.width
|
||||
labelText: I18n.tr("Password", "hotspot password field label")
|
||||
placeholderText: I18n.tr("Optional; leave blank for open hotspot", "hotspot password field placeholder")
|
||||
text: hotspotCard.password
|
||||
leftIconName: "key"
|
||||
showPasswordToggle: true
|
||||
echoMode: passwordVisible ? TextInput.Normal : TextInput.Password
|
||||
onTextEdited: {
|
||||
hotspotCard.password = text;
|
||||
hotspotCard.passwordEditRevision++;
|
||||
if (text.length > 0)
|
||||
hotspotCard.passwordResolved = true;
|
||||
}
|
||||
onAccepted: hotspotCard.saveOnly()
|
||||
}
|
||||
|
||||
Row {
|
||||
width: parent.width
|
||||
spacing: Theme.spacingM
|
||||
|
||||
DankDropdown {
|
||||
width: (parent.width - Theme.spacingM) / 2
|
||||
text: I18n.tr("Device", "hotspot WiFi device field label")
|
||||
description: I18n.tr("Optional", "hotspot WiFi device field description")
|
||||
currentValue: hotspotCard.device || I18n.tr("Auto", "hotspot device or band option")
|
||||
options: {
|
||||
const devices = NetworkService.wifiDevices || [];
|
||||
return [I18n.tr("Auto", "hotspot device or band option")].concat(devices.filter(d => d.apCapable).map(d => d.name));
|
||||
}
|
||||
onValueChanged: value => hotspotCard.device = value === I18n.tr("Auto", "hotspot device or band option") ? "" : value
|
||||
}
|
||||
|
||||
DankDropdown {
|
||||
width: (parent.width - Theme.spacingM) / 2
|
||||
text: I18n.tr("Band", "hotspot WiFi band field label")
|
||||
description: I18n.tr("Optional", "hotspot WiFi band field description")
|
||||
currentValue: hotspotCard.bandLabel(hotspotCard.band)
|
||||
options: [I18n.tr("Auto", "hotspot device or band option"), I18n.tr("2.4 GHz", "hotspot WiFi band option"), I18n.tr("5 GHz", "hotspot WiFi band option")]
|
||||
onValueChanged: value => hotspotCard.band = hotspotCard.bandValue(value)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Row {
|
||||
width: parent.width
|
||||
spacing: Theme.spacingS
|
||||
|
||||
Item {
|
||||
width: Math.max(0, parent.width - (cancelButton.visible ? cancelButton.width + Theme.spacingS : 0) - (editButton.visible ? editButton.width + Theme.spacingS : 0) - (saveButton.visible ? saveButton.width + Theme.spacingS : 0) - (startStopButton.width + Theme.spacingS))
|
||||
height: 1
|
||||
}
|
||||
|
||||
DankButton {
|
||||
id: cancelButton
|
||||
visible: hotspotCard.editing
|
||||
text: I18n.tr("Cancel", "cancel hotspot editing action")
|
||||
buttonHeight: 36
|
||||
backgroundColor: Theme.surfaceVariant
|
||||
textColor: Theme.surfaceText
|
||||
onClicked: hotspotCard.stopEditing()
|
||||
}
|
||||
|
||||
DankButton {
|
||||
id: editButton
|
||||
visible: !hotspotCard.showForm
|
||||
text: I18n.tr("Edit", "edit hotspot action")
|
||||
iconName: "edit"
|
||||
buttonHeight: 36
|
||||
enabled: !NetworkService.hotspotEnabled && !hotspotCard.starting
|
||||
backgroundColor: Theme.surfaceVariant
|
||||
textColor: Theme.surfaceText
|
||||
onClicked: hotspotCard.beginEditing()
|
||||
}
|
||||
|
||||
DankButton {
|
||||
id: saveButton
|
||||
visible: hotspotCard.showForm
|
||||
text: hotspotCard.passwordLoading ? I18n.tr("Loading...", "hotspot password loading status") : (NetworkService.hotspotBusy ? I18n.tr("Saving...", "hotspot configuration saving status") : I18n.tr("Save", "save hotspot configuration action"))
|
||||
iconName: "save"
|
||||
buttonHeight: 36
|
||||
enabled: hotspotCard.buildCanConfigure()
|
||||
backgroundColor: Theme.surfaceVariant
|
||||
textColor: Theme.surfaceText
|
||||
onClicked: hotspotCard.saveOnly()
|
||||
}
|
||||
|
||||
DankButton {
|
||||
id: startStopButton
|
||||
text: {
|
||||
if (NetworkService.hotspotEnabled)
|
||||
return I18n.tr("Stop", "stop hotspot action");
|
||||
if (hotspotCard.starting)
|
||||
return I18n.tr("Starting...", "hotspot activation status");
|
||||
return hotspotCard.showForm ? I18n.tr("Save & Start", "save and start hotspot action") : I18n.tr("Start", "start hotspot action");
|
||||
}
|
||||
iconName: NetworkService.hotspotEnabled ? "stop" : "wifi_tethering"
|
||||
buttonHeight: 36
|
||||
enabled: !hotspotCard.starting && (NetworkService.hotspotEnabled || hotspotCard.buildCanConfigure())
|
||||
backgroundColor: NetworkService.hotspotEnabled ? Theme.error : Theme.primary
|
||||
textColor: NetworkService.hotspotEnabled ? Theme.surfaceText : Theme.onPrimary
|
||||
onClicked: hotspotCard.startOrStop()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -70,6 +70,29 @@ Singleton {
|
||||
property string targetPreference: ""
|
||||
property var savedWifiNetworks: []
|
||||
readonly property int savedWifiStateApiVersion: 26
|
||||
readonly property int hotspotApiVersion: 28
|
||||
property bool backendHotspotSupported: false
|
||||
property bool backendHotspotAvailable: false
|
||||
property bool backendHotspotConfigured: false
|
||||
property bool backendHotspotEnabled: false
|
||||
property bool backendHotspotActivating: false
|
||||
property bool backendHotspotSecured: false
|
||||
property string backendHotspotSSID: ""
|
||||
property string backendHotspotDevice: ""
|
||||
property string backendHotspotBand: ""
|
||||
property string backendHotspotLastError: ""
|
||||
readonly property bool hotspotSupported: DMSService.isConnected && networkAvailable && DMSService.apiVersion >= hotspotApiVersion && backendHotspotSupported
|
||||
readonly property bool hotspotAvailable: hotspotSupported && backendHotspotAvailable
|
||||
readonly property bool hotspotConfigured: hotspotSupported && backendHotspotConfigured
|
||||
readonly property bool hotspotEnabled: hotspotSupported && backendHotspotEnabled
|
||||
readonly property bool hotspotActivating: hotspotSupported && backendHotspotActivating
|
||||
readonly property bool hotspotSecured: hotspotSupported && backendHotspotSecured
|
||||
readonly property bool hotspotWouldDisconnectWifi: hotspotSupported && !hotspotEnabled && !hotspotActivating && hotspotTargetWouldDisconnectWifi(backendHotspotDevice, backendHotspotBand)
|
||||
readonly property string hotspotSSID: hotspotSupported ? backendHotspotSSID : ""
|
||||
readonly property string hotspotDevice: hotspotSupported ? backendHotspotDevice : ""
|
||||
readonly property string hotspotBand: hotspotSupported ? backendHotspotBand : ""
|
||||
property bool hotspotBusy: false
|
||||
property string hotspotError: ""
|
||||
property string connectionStatus: ""
|
||||
property string lastConnectionError: ""
|
||||
property bool passwordDialogShouldReopen: false
|
||||
@@ -318,6 +341,43 @@ Singleton {
|
||||
wifiDevices = state.wifiDevices || [];
|
||||
connectingDevice = state.connectingDevice || "";
|
||||
|
||||
if (DMSService.apiVersion >= hotspotApiVersion) {
|
||||
const supportsHotspot = state.hotspotSupported === true;
|
||||
const wasHotspotEnabled = backendHotspotEnabled;
|
||||
const wasHotspotActivating = backendHotspotActivating;
|
||||
backendHotspotSupported = supportsHotspot;
|
||||
backendHotspotAvailable = state.hotspotAvailable === true;
|
||||
backendHotspotConfigured = state.hotspotConfigured === true;
|
||||
backendHotspotEnabled = state.hotspotEnabled === true;
|
||||
backendHotspotActivating = state.hotspotActivating === true;
|
||||
backendHotspotSecured = state.hotspotSecured === true;
|
||||
backendHotspotSSID = state.hotspotSSID || "";
|
||||
backendHotspotDevice = state.hotspotDevice || "";
|
||||
backendHotspotBand = state.hotspotBand || "";
|
||||
backendHotspotLastError = state.hotspotLastError || "";
|
||||
|
||||
// Activation is asynchronous: only toast outcomes of starts we watched
|
||||
// begin, so restoring state after a shell restart stays silent.
|
||||
const watchedStart = wasHotspotActivating || hotspotBusy;
|
||||
if (watchedStart && !wasHotspotEnabled && backendHotspotEnabled) {
|
||||
ToastService.showInfo(I18n.tr("Hotspot started", "hotspot start success message"));
|
||||
} else if (wasHotspotActivating && !backendHotspotActivating && !backendHotspotEnabled && backendHotspotLastError) {
|
||||
hotspotError = backendHotspotLastError;
|
||||
ToastService.showError(I18n.tr("Failed to start hotspot", "hotspot start error title"), hotspotErrorMessage(backendHotspotLastError));
|
||||
}
|
||||
} else {
|
||||
backendHotspotSupported = false;
|
||||
backendHotspotAvailable = false;
|
||||
backendHotspotConfigured = false;
|
||||
backendHotspotEnabled = false;
|
||||
backendHotspotActivating = false;
|
||||
backendHotspotSecured = false;
|
||||
backendHotspotSSID = "";
|
||||
backendHotspotDevice = "";
|
||||
backendHotspotBand = "";
|
||||
backendHotspotLastError = "";
|
||||
}
|
||||
|
||||
currentWifiSSID = state.wifiSSID || "";
|
||||
wifiSignalStrength = state.wifiSignal || 0;
|
||||
|
||||
@@ -1026,6 +1086,137 @@ Singleton {
|
||||
});
|
||||
}
|
||||
|
||||
function configureHotspot(ssid, password = "", device = "", band = "", callback = null) {
|
||||
if (!hotspotSupported || hotspotBusy)
|
||||
return false;
|
||||
|
||||
const params = {
|
||||
ssid: ssid
|
||||
};
|
||||
if (password)
|
||||
params.password = password;
|
||||
if (device)
|
||||
params.device = device;
|
||||
if (band)
|
||||
params.band = band;
|
||||
|
||||
hotspotBusy = true;
|
||||
hotspotError = "";
|
||||
|
||||
DMSService.sendRequest("network.hotspot.configure", params, response => {
|
||||
hotspotBusy = false;
|
||||
if (response.error) {
|
||||
hotspotError = response.error;
|
||||
ToastService.showError(I18n.tr("Failed to configure hotspot", "hotspot configuration error title"), response.error);
|
||||
} else {
|
||||
Qt.callLater(() => getState());
|
||||
}
|
||||
if (callback)
|
||||
callback(response);
|
||||
});
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
function startHotspot(callback = null) {
|
||||
if (!hotspotAvailable || hotspotBusy)
|
||||
return false;
|
||||
|
||||
hotspotBusy = true;
|
||||
hotspotError = "";
|
||||
|
||||
DMSService.sendRequest("network.hotspot.start", null, response => {
|
||||
hotspotBusy = false;
|
||||
if (response.error) {
|
||||
hotspotError = response.error;
|
||||
ToastService.showError(I18n.tr("Failed to start hotspot", "hotspot start error title"), response.error);
|
||||
} else {
|
||||
Qt.callLater(() => getState());
|
||||
}
|
||||
if (callback)
|
||||
callback(response);
|
||||
});
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
function stopHotspot(callback = null) {
|
||||
if (!hotspotSupported || hotspotBusy)
|
||||
return false;
|
||||
|
||||
hotspotBusy = true;
|
||||
hotspotError = "";
|
||||
|
||||
DMSService.sendRequest("network.hotspot.stop", null, response => {
|
||||
hotspotBusy = false;
|
||||
if (response.error) {
|
||||
hotspotError = response.error;
|
||||
ToastService.showError(I18n.tr("Failed to stop hotspot", "hotspot stop error title"), response.error);
|
||||
} else {
|
||||
Qt.callLater(() => getState());
|
||||
}
|
||||
if (callback)
|
||||
callback(response);
|
||||
});
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
function configureAndStartHotspot(ssid, password = "", device = "", band = "", callback = null) {
|
||||
return configureHotspot(ssid, password, device, band, configureResponse => {
|
||||
if (configureResponse.error) {
|
||||
if (callback)
|
||||
callback(configureResponse);
|
||||
return;
|
||||
}
|
||||
startHotspot(callback);
|
||||
});
|
||||
}
|
||||
|
||||
function getHotspotSecrets(callback) {
|
||||
if (!hotspotSupported) {
|
||||
if (callback)
|
||||
callback({
|
||||
error: "hotspot not supported"
|
||||
});
|
||||
return false;
|
||||
}
|
||||
|
||||
DMSService.sendRequest("network.hotspot.getSecrets", null, response => {
|
||||
if (callback)
|
||||
callback(response);
|
||||
});
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
function hotspotTargetWouldDisconnectWifi(device, band = "") {
|
||||
const devices = wifiDevices || [];
|
||||
const active = devices.find(d => d.connected);
|
||||
if (!active)
|
||||
return false;
|
||||
if (device) {
|
||||
const target = devices.find(d => d.name === device);
|
||||
return target ? target.connected : device === active.name;
|
||||
}
|
||||
// Band capabilities are not exposed per device, so a fixed-band automatic
|
||||
// selection cannot safely promise that an idle radio will be usable.
|
||||
if (band)
|
||||
return true;
|
||||
return !devices.some(d => d.apCapable && !d.connected && d.state === "disconnected" && d.name !== active.name);
|
||||
}
|
||||
|
||||
function hotspotErrorMessage(code) {
|
||||
switch (code) {
|
||||
case "hotspot-ip-config-failed":
|
||||
return I18n.tr("IP sharing setup failed. Check that dnsmasq is installed.", "hotspot IP configuration failure message");
|
||||
case "hotspot-supplicant-failed":
|
||||
return I18n.tr("The WiFi adapter could not start access point mode.", "hotspot adapter failure message");
|
||||
default:
|
||||
return I18n.tr("Hotspot activation failed.", "generic hotspot activation failure message");
|
||||
}
|
||||
}
|
||||
|
||||
function refreshSavedWifiNetworks() {
|
||||
if (!networkAvailable)
|
||||
return;
|
||||
|
||||
@@ -55,6 +55,19 @@ Singleton {
|
||||
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
|
||||
@@ -312,6 +325,48 @@ Singleton {
|
||||
}
|
||||
}
|
||||
|
||||
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);
|
||||
|
||||
@@ -9475,6 +9475,27 @@
|
||||
],
|
||||
"icon": "settings_ethernet"
|
||||
},
|
||||
{
|
||||
"section": "networkHotspot",
|
||||
"label": "Hotspot",
|
||||
"tabIndex": 40,
|
||||
"category": "Network",
|
||||
"keywords": [
|
||||
"access point",
|
||||
"connectivity",
|
||||
"hotspot",
|
||||
"network",
|
||||
"online",
|
||||
"optional",
|
||||
"sharing",
|
||||
"ssid",
|
||||
"wi-fi",
|
||||
"wifi",
|
||||
"wireless"
|
||||
],
|
||||
"icon": "wifi_tethering",
|
||||
"description": "Optional"
|
||||
},
|
||||
{
|
||||
"section": "networkSavedWifi",
|
||||
"label": "Saved Networks",
|
||||
|
||||
Reference in New Issue
Block a user