mirror of
https://github.com/noctalia-dev/noctalia-shell.git
synced 2026-05-11 17:08:27 +08:00
improve airplane mode handling
This commit is contained in:
@@ -147,7 +147,7 @@ Singleton {
|
||||
|
||||
Timer {
|
||||
id: ctlPollTimer
|
||||
interval: 2000
|
||||
interval: 250
|
||||
running: false
|
||||
onTriggered: {
|
||||
if (!adapter || !ProgramCheckerService.bluetoothctlAvailable) {
|
||||
@@ -172,19 +172,19 @@ Singleton {
|
||||
}
|
||||
}
|
||||
|
||||
// Check if airplane mode has been toggled
|
||||
function checkAirplaneMode() {
|
||||
var isAirplaneModeActive = !NetworkService.wifiEnabled && adapter.state === BluetoothAdapter.Blocked
|
||||
// Check if airplane mode has been toggled
|
||||
if (isAirplaneModeActive && !NetworkService.airplaneModeEnabled) {
|
||||
NetworkService.airplaneModeToggled = true;
|
||||
NetworkService.airplaneModeEnabled = true;
|
||||
ToastService.showNotice(I18n.tr("toast.airplane-mode.title"), I18n.tr("common.enabled"), "plane");
|
||||
Logger.i("AirplaneMode", "Wi-Fi & Bluetooth adapter blocked");
|
||||
Logger.i("AirplaneMode", "Enabled");
|
||||
} else if (!isAirplaneModeActive && NetworkService.airplaneModeEnabled) {
|
||||
NetworkService.airplaneModeToggled = true;
|
||||
NetworkService.airplaneModeEnabled = false;
|
||||
ToastService.showNotice(I18n.tr("toast.airplane-mode.title"), I18n.tr("common.disabled"), "plane-off");
|
||||
Logger.i("AirplaneMode", "Wi-Fi & Bluetooth adapter unblocked");
|
||||
Logger.i("AirplaneMode", "Disabled");
|
||||
} else if (adapter.enabled) {
|
||||
ToastService.showNotice(I18n.tr("common.bluetooth"), I18n.tr("common.enabled"), "bluetooth");
|
||||
Logger.d("Bluetooth", "Adapter enabled");
|
||||
|
||||
@@ -155,6 +155,31 @@ Singleton {
|
||||
onTriggered: {
|
||||
if (root.airplaneModeToggled) {
|
||||
root.airplaneModeToggled = false;
|
||||
if (root.wifiEnabled) {
|
||||
connectivityCheckProcess.running = true;
|
||||
deviceStatusProcess.running = true;
|
||||
scan();
|
||||
} else {
|
||||
root.networks = ({});
|
||||
}
|
||||
return;
|
||||
}
|
||||
var isAirplaneModeActive = !root.wifiEnabled && BluetoothService.blocked
|
||||
// Extra check for Airplane Mode if Bluetooth has been blocked before Wi-Fi
|
||||
if (isAirplaneModeActive && !root.airplaneModeEnabled) {
|
||||
root.airplaneModeEnabled = true;
|
||||
ToastService.showNotice(I18n.tr("toast.airplane-mode.title"), I18n.tr("common.enabled"), "plane");
|
||||
Logger.i("AirplaneMode", "Enabled");
|
||||
root.networks = ({});
|
||||
return;
|
||||
}
|
||||
// Extra check for Airplane Mode if Wi-Fi has been unblocked before Bluetooth
|
||||
if (!isAirplaneModeActive && root.airplaneModeEnabled) {
|
||||
root.airplaneModeEnabled = false;
|
||||
ToastService.showNotice(I18n.tr("toast.airplane-mode.title"), I18n.tr("common.disabled"), "plane-off");
|
||||
Logger.i("AirplaneMode", "Disabled");
|
||||
deviceStatusProcess.restart();
|
||||
scan();
|
||||
return;
|
||||
}
|
||||
if (root.wifiEnabled) {
|
||||
@@ -196,11 +221,10 @@ Singleton {
|
||||
|
||||
function setAirplaneMode(state) {
|
||||
if (state) {
|
||||
Quickshell.execDetached(["rfkill", "block", "wifi"]);
|
||||
Quickshell.execDetached(["rfkill", "block", "bluetooth"]);
|
||||
Quickshell.execDetached(["rfkill", "block", "all"]);
|
||||
} else {
|
||||
Quickshell.execDetached(["rfkill", "unblock", "wifi"]);
|
||||
Quickshell.execDetached(["rfkill", "unblock", "bluetooth"]);
|
||||
Quickshell.execDetached(["rfkill", "unblock", "all"]);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user