mirror of
https://github.com/noctalia-dev/noctalia-shell.git
synced 2026-05-11 17:08:27 +08:00
Attempt to fix tracking, strict toggles,menus if airplane mode or hardware disabled/broken
Stricter toggles. hw (bluetooth) state polling. Update BluetoothSubTab.qml Disable toggles if airplane mode active. ethernetprefs cancelled.
This commit is contained in:
@@ -48,7 +48,8 @@ Item {
|
||||
{
|
||||
"label": BluetoothService.enabled ? I18n.tr("actions.disable-bluetooth") : I18n.tr("actions.enable-bluetooth"),
|
||||
"action": "toggle-bluetooth",
|
||||
"icon": BluetoothService.enabled ? "bluetooth-off" : "bluetooth"
|
||||
"icon": BluetoothService.enabled ? "bluetooth-off" : "bluetooth",
|
||||
"enabled": !Settings.data.network.airplaneModeEnabled && BluetoothService.bluetoothAvailable
|
||||
},
|
||||
{
|
||||
"label": I18n.tr("common.bluetooth") + " " + I18n.tr("tooltips.open-settings"),
|
||||
|
||||
@@ -48,18 +48,14 @@ Item {
|
||||
{
|
||||
"label": Settings.data.network.wifiEnabled ? I18n.tr("actions.disable-wifi") : I18n.tr("actions.enable-wifi"),
|
||||
"action": "toggle-wifi",
|
||||
"icon": Settings.data.network.wifiEnabled ? "wifi-off" : "wifi"
|
||||
"icon": Settings.data.network.wifiEnabled ? "wifi-off" : "wifi",
|
||||
"enabled": !Settings.data.network.airplaneModeEnabled && NetworkService.wifiAvailable
|
||||
},
|
||||
{
|
||||
"label": I18n.tr("common.wifi") + " " + I18n.tr("tooltips.open-settings"),
|
||||
"action": "wifi-settings",
|
||||
"icon": "settings"
|
||||
},
|
||||
{
|
||||
"label": I18n.tr("panels.connections.ethernet") + " " + I18n.tr("tooltips.open-settings"),
|
||||
"action": "ethernet-settings",
|
||||
"icon": "settings"
|
||||
},
|
||||
{
|
||||
"label": I18n.tr("actions.widget-settings"),
|
||||
"action": "widget-settings",
|
||||
@@ -75,8 +71,6 @@ Item {
|
||||
NetworkService.setWifiEnabled(!Settings.data.network.wifiEnabled);
|
||||
} else if (action === "wifi-settings") {
|
||||
SettingsPanelService.openToTab(SettingsPanel.Tab.Connections, 0, screen);
|
||||
}else if (action === "ethernet-settings") {
|
||||
SettingsPanelService.openToTab(SettingsPanel.Tab.Connections, 2, screen);
|
||||
}else if (action === "widget-settings") {
|
||||
BarService.openWidgetSettings(screen, section, sectionWidgetIndex, widgetId, widgetSettings);
|
||||
}
|
||||
|
||||
@@ -58,6 +58,7 @@ SmartPanel {
|
||||
NToggle {
|
||||
id: bluetoothSwitch
|
||||
checked: BluetoothService.enabled
|
||||
enabled: !Settings.data.network.airplaneModeEnabled && BluetoothService.bluetoothAvailable
|
||||
onToggled: checked => BluetoothService.setBluetoothEnabled(checked)
|
||||
baseSize: Style.baseWidgetSize * 0.65
|
||||
}
|
||||
@@ -90,7 +91,7 @@ SmartPanel {
|
||||
// Adapter not available of disabled
|
||||
NBox {
|
||||
id: disabledBox
|
||||
visible: !(BluetoothService.adapter && BluetoothService.adapter.enabled)
|
||||
visible: !BluetoothService.enabled
|
||||
Layout.fillWidth: true
|
||||
Layout.preferredHeight: disabledColumn.implicitHeight + Style.marginXL
|
||||
|
||||
@@ -137,7 +138,7 @@ SmartPanel {
|
||||
NBox {
|
||||
id: emptyBox
|
||||
visible: {
|
||||
if (!(BluetoothService.adapter && BluetoothService.adapter.enabled && BluetoothService.adapter.devices))
|
||||
if (!BluetoothService.enabled || !BluetoothService.devices)
|
||||
return false;
|
||||
// Pulling pairedDevices count from the source component
|
||||
return (btSource.pairedDevices.length === 0 && btSource.connectedDevices.length === 0);
|
||||
|
||||
@@ -15,5 +15,9 @@ NIconButtonHot {
|
||||
if (p)
|
||||
p.toggle(this);
|
||||
}
|
||||
onRightClicked: BluetoothService.setBluetoothEnabled(!BluetoothService.enabled)
|
||||
onRightClicked: {
|
||||
if (!Settings.data.network.airplaneModeEnabled) {
|
||||
BluetoothService.setBluetoothEnabled(!BluetoothService.enabled)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -52,5 +52,9 @@ NIconButtonHot {
|
||||
var panel = PanelService.getPanel("networkPanel", screen);
|
||||
panel?.toggle(this);
|
||||
}
|
||||
onRightClicked: NetworkService.setWifiEnabled(!Settings.data.network.wifiEnabled)
|
||||
onRightClicked: {
|
||||
if (!Settings.data.network.airplaneModeEnabled) {
|
||||
NetworkService.setWifiEnabled(!Settings.data.network.wifiEnabled)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -157,6 +157,7 @@ SmartPanel {
|
||||
id: wifiSwitch
|
||||
visible: panelViewMode === "wifi"
|
||||
checked: Settings.data.network.wifiEnabled
|
||||
enabled: !Settings.data.network.airplaneModeEnabled && NetworkService.wifiAvailable
|
||||
onToggled: checked => NetworkService.setWifiEnabled(checked)
|
||||
baseSize: Style.baseWidgetSize * 0.7 // Slightly smaller
|
||||
}
|
||||
|
||||
@@ -171,7 +171,7 @@ Item {
|
||||
|
||||
NToggle {
|
||||
checked: BluetoothService.enabled
|
||||
enabled: !NetworkService.bluetoothBlocked
|
||||
enabled: !Settings.data.network.airplaneModeEnabled && BluetoothService.bluetoothAvailable
|
||||
onToggled: checked => BluetoothService.setBluetoothEnabled(checked)
|
||||
Layout.alignment: Qt.AlignVCenter
|
||||
}
|
||||
@@ -201,7 +201,7 @@ Item {
|
||||
// Device List [1] (Connected)
|
||||
NBox {
|
||||
id: connectedDevicesBox
|
||||
visible: btprefs.connectedDevices.length > 0 && BluetoothService.adapter && BluetoothService.adapter.enabled
|
||||
visible: btprefs.connectedDevices.length > 0 && BluetoothService.enabled
|
||||
Layout.fillWidth: true
|
||||
Layout.preferredHeight: connectedDevicesCol.implicitHeight + Style.marginXL
|
||||
|
||||
@@ -233,7 +233,7 @@ Item {
|
||||
// Devices List [2] (Paired)
|
||||
NBox {
|
||||
id: pairedDevicesBox
|
||||
visible: btprefs.pairedDevices.length > 0 && BluetoothService.adapter && BluetoothService.adapter.enabled
|
||||
visible: btprefs.pairedDevices.length > 0 && BluetoothService.enabled
|
||||
Layout.fillWidth: true
|
||||
Layout.preferredHeight: pairedDevicesCol.implicitHeight + Style.marginXL
|
||||
|
||||
@@ -265,7 +265,7 @@ Item {
|
||||
// Device List [3] (Available)
|
||||
NBox {
|
||||
id: availableDevicesBox
|
||||
visible: !btprefs.showOnlyLists && btprefs.unnamedAvailableDevices.length > 0 && BluetoothService.adapter && BluetoothService.adapter.enabled
|
||||
visible: !btprefs.showOnlyLists && btprefs.unnamedAvailableDevices.length > 0 && BluetoothService.enabled
|
||||
Layout.fillWidth: true
|
||||
Layout.preferredHeight: availableDevicesCol.implicitHeight + Style.marginXL
|
||||
|
||||
|
||||
@@ -94,7 +94,7 @@ Item {
|
||||
checked: Settings.data.network.wifiEnabled
|
||||
onToggled: checked => NetworkService.setWifiEnabled(checked)
|
||||
Layout.alignment: Qt.AlignVCenter
|
||||
enabled: ProgramCheckerService.nmcliAvailable
|
||||
enabled: ProgramCheckerService.nmcliAvailable && !Settings.data.network.airplaneModeEnabled && NetworkService.wifiAvailable
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -22,12 +22,20 @@ Singleton {
|
||||
property bool airplaneModeToggled: false
|
||||
|
||||
// Power/blocked/availability state
|
||||
readonly property bool bluetoothAvailable: !!adapter
|
||||
readonly property bool enabled: adapter?.enabled ?? root.ctlPowered
|
||||
property bool ctlAvailable: false
|
||||
readonly property bool bluetoothAvailable: !!adapter || root.ctlAvailable
|
||||
readonly property bool enabled: (adapter && adapter.enabled) || root.ctlPowered
|
||||
property bool ctlPowered: false
|
||||
property bool ctlDiscovering: false
|
||||
property bool ctlDiscoverable: false
|
||||
|
||||
onAdapterChanged: {
|
||||
pollCtlState();
|
||||
if (!adapter) {
|
||||
ctlPollTimer.interval = 2000;
|
||||
}
|
||||
}
|
||||
|
||||
// Adapter discoverability (advertising) flag
|
||||
readonly property bool discoverable: adapter?.discoverable ?? root.ctlDiscoverable
|
||||
readonly property var devices: adapter ? adapter.devices : null
|
||||
@@ -60,6 +68,14 @@ Singleton {
|
||||
|
||||
// Internal: temporarily pause discovery during pair/connect to reduce HCI churn
|
||||
property bool _discoveryWasRunning: false
|
||||
property bool _lastEnabledState: root.enabled
|
||||
|
||||
Timer {
|
||||
id: initDelayTimer
|
||||
interval: 3000
|
||||
running: true
|
||||
repeat: false
|
||||
}
|
||||
|
||||
// Persistent process for bluetoothctl scanning when native discovery is unavailable
|
||||
Process {
|
||||
@@ -140,12 +156,18 @@ Singleton {
|
||||
Settings.data.network.airplaneModeEnabled = false;
|
||||
ToastService.showNotice(I18n.tr("toast.airplane-mode.title"), I18n.tr("common.disabled"), "plane-off");
|
||||
Logger.i("AirplaneMode", "Wi-Fi & Bluetooth adapter unblocked")
|
||||
} else if (adapter.enabled) {
|
||||
ToastService.showNotice(I18n.tr("common.bluetooth"), I18n.tr("common.enabled"), "bluetooth");
|
||||
Logger.d("Bluetooth", "Adapter enabled");
|
||||
} else {
|
||||
ToastService.showNotice(I18n.tr("common.bluetooth"), I18n.tr("common.disabled"), "bluetooth-off");
|
||||
Logger.d("Bluetooth", "Adapter disabled");
|
||||
var isCurrentlyEnabled = (adapter && adapter.enabled) || root.ctlPowered;
|
||||
var stateChanged = isCurrentlyEnabled !== root._lastEnabledState;
|
||||
if (!initDelayTimer.running && stateChanged) {
|
||||
if (isCurrentlyEnabled) {
|
||||
ToastService.showNotice(I18n.tr("common.bluetooth"), I18n.tr("common.enabled"), "bluetooth");
|
||||
} else {
|
||||
ToastService.showNotice(I18n.tr("common.bluetooth"), I18n.tr("common.disabled"), "bluetooth-off");
|
||||
}
|
||||
}
|
||||
root._lastEnabledState = isCurrentlyEnabled;
|
||||
Logger.d("Bluetooth", "State updated - enabled:", isCurrentlyEnabled);
|
||||
}
|
||||
root.airplaneModeToggled = false;
|
||||
}
|
||||
@@ -168,17 +190,29 @@ Singleton {
|
||||
try {
|
||||
var text = ctlStdout.text || "";
|
||||
var lines = text.split('\n');
|
||||
var foundController = false; // Strict state following.
|
||||
var powered = false; // Strict state following.
|
||||
var discoverable = false; // Strict state following.
|
||||
var discovering = false; // Strict state following.
|
||||
|
||||
for (var i = 0; i < lines.length; i++) {
|
||||
var line = lines[i].trim();
|
||||
if (line.indexOf("Controller") === 0) {
|
||||
foundController = true;
|
||||
}
|
||||
var mp = line.match(/\bPowered:\s*(yes|no)\b/i);
|
||||
if (mp) { root.ctlPowered = (mp[1].toLowerCase() === "yes"); }
|
||||
if (mp) { powered = (mp[1].toLowerCase() === "yes"); }
|
||||
|
||||
var md = line.match(/\bDiscoverable:\s*(yes|no)\b/i);
|
||||
if (md) { root.ctlDiscoverable = (md[1].toLowerCase() === "yes"); }
|
||||
if (md) { discoverable = (md[1].toLowerCase() === "yes"); }
|
||||
|
||||
var ms = line.match(/\bDiscovering:\s*(yes|no)\b/i);
|
||||
if (ms) { root.ctlDiscovering = (ms[1].toLowerCase() === "yes"); }
|
||||
if (ms) { discovering = (ms[1].toLowerCase() === "yes"); }
|
||||
}
|
||||
root.ctlAvailable = foundController; // Assign findings.
|
||||
root.ctlPowered = powered; // Assign findings.
|
||||
root.ctlDiscoverable = discoverable; // Assign findings.
|
||||
root.ctlDiscovering = discovering; // Assign findings.
|
||||
} catch (e) {
|
||||
Logger.d("Bluetooth", "Failed to parse bluetoothctl show output", e);
|
||||
}
|
||||
@@ -198,13 +232,14 @@ Singleton {
|
||||
// Periodic state polling
|
||||
Timer {
|
||||
id: ctlPollTimer
|
||||
interval: ctlPollMs
|
||||
interval: adapter ? ctlPollMs : 2000
|
||||
repeat: true
|
||||
running: root.enabled
|
||||
running: true
|
||||
onTriggered: {
|
||||
pollCtlState();
|
||||
if (interval !== ctlPollMs) {
|
||||
interval = ctlPollMs;
|
||||
var targetInterval = adapter ? ctlPollMs : 2000;
|
||||
if (interval !== targetInterval) {
|
||||
interval = targetInterval;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user