mirror of
https://github.com/zoriya/noctalia-shell.git
synced 2026-08-15 18:43:59 +00:00
Bluetooth: Removed the copy of the adapter's state in Settings, makes code much simpler and robust by always relying on the actual adapter's state.
This commit is contained in:
@@ -21,6 +21,7 @@ Singleton {
|
||||
return dev && (dev.paired || dev.trusted)
|
||||
})
|
||||
}
|
||||
|
||||
readonly property var allDevicesWithBattery: {
|
||||
if (!adapter || !adapter.devices) {
|
||||
return []
|
||||
@@ -30,30 +31,8 @@ Singleton {
|
||||
})
|
||||
}
|
||||
|
||||
property bool lastAdapterState: false
|
||||
property bool restoringState: false
|
||||
|
||||
function init() {
|
||||
Logger.log("Bluetooth", "Service initialized")
|
||||
// Try to restore saved state if needed
|
||||
if (Settings.data.network.bluetoothEnabled !== undefined && adapter) {
|
||||
restoringState = true
|
||||
adapter.enabled = Settings.data.network.bluetoothEnabled
|
||||
restoringState = false
|
||||
}
|
||||
|
||||
// Need to delay a bit for the adapter to be ready
|
||||
initTimer.running = true
|
||||
}
|
||||
|
||||
Timer {
|
||||
id: initTimer
|
||||
interval: 1000
|
||||
repeat: false
|
||||
onTriggered: {
|
||||
lastAdapterState = adapter?.enabled ?? false
|
||||
Logger.log("Bluetooth", "LastAdapterState:", lastAdapterState)
|
||||
}
|
||||
}
|
||||
|
||||
Timer {
|
||||
@@ -72,21 +51,11 @@ Singleton {
|
||||
}
|
||||
|
||||
Logger.log("Bluetooth", "onEnableChanged", adapter.enabled)
|
||||
|
||||
// Only save to settings if this is a user-initiated change
|
||||
if (!restoringState) {
|
||||
Settings.data.network.bluetoothEnabled = adapter.enabled
|
||||
}
|
||||
|
||||
// Show toast only for actual state changes
|
||||
if (lastAdapterState !== adapter.enabled) {
|
||||
lastAdapterState = adapter.enabled
|
||||
if (adapter.enabled) {
|
||||
ToastService.showNotice(I18n.tr("bluetooth.panel.title"), I18n.tr("toast.bluetooth.enabled"))
|
||||
discoveryTimer.running = true
|
||||
} else {
|
||||
ToastService.showNotice(I18n.tr("bluetooth.panel.title"), I18n.tr("toast.bluetooth.disabled"))
|
||||
}
|
||||
if (adapter.enabled) {
|
||||
ToastService.showNotice(I18n.tr("bluetooth.panel.title"), I18n.tr("toast.bluetooth.enabled"))
|
||||
discoveryTimer.running = true
|
||||
} else {
|
||||
ToastService.showNotice(I18n.tr("bluetooth.panel.title"), I18n.tr("toast.bluetooth.disabled"))
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -146,14 +115,10 @@ Singleton {
|
||||
if (!device)
|
||||
return false
|
||||
|
||||
|
||||
/*
|
||||
Paired
|
||||
|
||||
Means you’ve successfully exchanged keys with the device.
|
||||
|
||||
The devices remember each other and can authenticate without repeating the pairing process.
|
||||
|
||||
Example: once your headphones are paired, you don’t need to type a PIN every time.
|
||||
Hence, instead of !device.paired, should be device.connected
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user