mirror of
https://github.com/noctalia-dev/noctalia-shell.git
synced 2026-05-11 17:08:27 +08:00
fixes to Airplane Mode
This commit is contained in:
@@ -18,9 +18,8 @@ Singleton {
|
||||
readonly property BluetoothAdapter adapter: Bluetooth.defaultAdapter
|
||||
|
||||
// Airplane mode status
|
||||
readonly property bool airplaneModeEnabled: Settings.data.network.airplaneModeEnabled
|
||||
property bool airplaneModeToggled: false
|
||||
property bool wifiBlocked: false
|
||||
property bool btBlocked: false
|
||||
|
||||
// Power/blocked/availability state
|
||||
readonly property bool bluetoothAvailable: !!adapter
|
||||
@@ -126,19 +125,16 @@ Singleton {
|
||||
var output = this.text || "";
|
||||
var wifiBlocked = /^\d+:.*Wireless LAN[^\n]*\n\s*Soft blocked:\s*yes/im.test(output)
|
||||
var btBlocked = /^\d+:.*Bluetooth[^\n]*\n\s*Soft blocked:\s*yes/im.test(output)
|
||||
|
||||
// Track if actual state changed
|
||||
var actualAirplaneModeActive = wifiBlocked && btBlocked;
|
||||
var previousAirplaneModeActive = root.wifiBlocked && root.btBlocked;
|
||||
var isAirplaneModeActive = wifiBlocked && btBlocked;
|
||||
|
||||
// Check if airplane mode has been toggled
|
||||
if (actualAirplaneModeActive && !previousAirplaneModeActive) {
|
||||
if (isAirplaneModeActive && !root.airplaneModeEnabled) {
|
||||
root.airplaneModeToggled = true;
|
||||
NetworkService.setWifiEnabled(false);
|
||||
Settings.data.network.airplaneModeEnabled = true;
|
||||
ToastService.showNotice(I18n.tr("toast.airplane-mode.title"), I18n.tr("common.enabled"), "plane");
|
||||
Logger.i("AirplaneMode", "Wi-Fi & Bluetooth adapter blocked")
|
||||
} else if (!actualAirplaneModeActive && previousAirplaneModeActive) {
|
||||
} else if (!isAirplaneModeActive && root.airplaneModeEnabled) {
|
||||
root.airplaneModeToggled = true;
|
||||
NetworkService.setWifiEnabled(true);
|
||||
Settings.data.network.airplaneModeEnabled = false;
|
||||
@@ -152,10 +148,6 @@ Singleton {
|
||||
Logger.d("Bluetooth", "Adapter disabled");
|
||||
}
|
||||
root.airplaneModeToggled = false;
|
||||
|
||||
// Update current blocked states (always reflect actual rfkill state)
|
||||
root.wifiBlocked = wifiBlocked;
|
||||
root.btBlocked = btBlocked;
|
||||
}
|
||||
}
|
||||
stderr: StdioCollector {
|
||||
@@ -517,4 +509,4 @@ Singleton {
|
||||
ToastService.showWarning(I18n.tr("common.bluetooth"), I18n.tr("toast.bluetooth.forget-failed"));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -74,12 +74,16 @@ Singleton {
|
||||
target: Settings.data.network
|
||||
function onWifiEnabledChanged() {
|
||||
if (Settings.data.network.wifiEnabled) {
|
||||
ToastService.showNotice(I18n.tr("common.wifi"), I18n.tr("common.enabled"), "wifi");
|
||||
if (!BluetoothService.airplaneModeToggled) {
|
||||
ToastService.showNotice(I18n.tr("common.wifi"), I18n.tr("common.enabled"), "wifi");
|
||||
}
|
||||
// Perform a scan to update the UI
|
||||
delayedScanTimer.interval = 3000;
|
||||
delayedScanTimer.restart();
|
||||
} else {
|
||||
ToastService.showNotice(I18n.tr("common.wifi"), I18n.tr("common.disabled"), "wifi-off");
|
||||
if (!BluetoothService.airplaneModeToggled) {
|
||||
ToastService.showNotice(I18n.tr("common.wifi"), I18n.tr("common.disabled"), "wifi-off");
|
||||
}
|
||||
// Clear networks so the widget icon changes
|
||||
root.networks = ({});
|
||||
}
|
||||
@@ -96,7 +100,6 @@ Singleton {
|
||||
root.refreshActiveWifiDetails();
|
||||
root.refreshActiveEthernetDetails();
|
||||
connectivityCheckProcess.running = true;
|
||||
checkWifiBlocked.running = true; // Refresh rfkill states after resume
|
||||
}
|
||||
}
|
||||
|
||||
@@ -110,7 +113,6 @@ Singleton {
|
||||
ethernetStateProcess.running = true;
|
||||
refreshActiveWifiDetails();
|
||||
refreshActiveEthernetDetails();
|
||||
checkWifiBlocked.running = true; // Trigger rfkill check on startup
|
||||
}
|
||||
}
|
||||
|
||||
@@ -260,11 +262,9 @@ Singleton {
|
||||
if (enabled) {
|
||||
Quickshell.execDetached(["rfkill", "block", "wifi"]);
|
||||
Quickshell.execDetached(["rfkill", "block", "bluetooth"]);
|
||||
Settings.data.network.airplaneModeEnabled = true;
|
||||
} else {
|
||||
Quickshell.execDetached(["rfkill", "unblock", "wifi"]);
|
||||
Quickshell.execDetached(["rfkill", "unblock", "bluetooth"]);
|
||||
Settings.data.network.airplaneModeEnabled = false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user