From 16cea533daf86a9b9c948238b5ea700b11880a97 Mon Sep 17 00:00:00 2001 From: LemmyCook Date: Tue, 9 Sep 2025 21:23:57 -0400 Subject: [PATCH] Bluetooth: added a button to enable/disable straight from the panel + minor improvements. --- Commons/Settings.qml | 2 ++ Modules/BluetoothPanel/BluetoothPanel.qml | 44 ++++++++++++++++++++++- Modules/SettingsPanel/Tabs/NetworkTab.qml | 10 +----- Services/BluetoothService.qml | 25 +++++++++++++ 4 files changed, 71 insertions(+), 10 deletions(-) diff --git a/Commons/Settings.qml b/Commons/Settings.qml index e9f8bf9..224dbd3 100644 --- a/Commons/Settings.qml +++ b/Commons/Settings.qml @@ -193,6 +193,8 @@ Singleton { FontService.init() HooksService.init() + + BluetoothService.init() } // ----------------------------------------------------- diff --git a/Modules/BluetoothPanel/BluetoothPanel.qml b/Modules/BluetoothPanel/BluetoothPanel.qml index 4f2cca9..ea6a64c 100644 --- a/Modules/BluetoothPanel/BluetoothPanel.qml +++ b/Modules/BluetoothPanel/BluetoothPanel.qml @@ -41,7 +41,15 @@ NPanel { Layout.fillWidth: true } + NToggle { + id: wifiSwitch + checked: Settings.data.network.bluetoothEnabled + onToggled: checked => BluetoothService.setBluetoothEnabled(checked) + baseSize: Style.baseWidgetSize * 0.65 * scaling + } + NIconButton { + enabled: Settings.data.network.bluetoothEnabled icon: BluetoothService.adapter && BluetoothService.adapter.discovering ? "stop" : "refresh" tooltipText: "Refresh Devices" sizeRatio: 0.8 @@ -66,7 +74,42 @@ NPanel { Layout.fillWidth: true } + Rectangle { + visible: !Settings.data.network.bluetoothEnabled + Layout.fillWidth: true + Layout.fillHeight: true + color: Color.transparent + + // Center the content within this rectangle + ColumnLayout { + anchors.centerIn: parent + spacing: Style.marginM * scaling + + NIcon { + icon: "bluetooth-off" + font.pointSize: 64 * scaling + color: Color.mOnSurfaceVariant + Layout.alignment: Qt.AlignHCenter + } + + NText { + text: "Bluetooth is disabled" + font.pointSize: Style.fontSizeL * scaling + color: Color.mOnSurfaceVariant + Layout.alignment: Qt.AlignHCenter + } + + NText { + text: "Enable Bluetooth to see available devices." + font.pointSize: Style.fontSizeS * scaling + color: Color.mOnSurfaceVariant + Layout.alignment: Qt.AlignHCenter + } + } + } + ScrollView { + visible: BluetoothService.adapter && BluetoothService.adapter.enabled Layout.fillWidth: true Layout.fillHeight: true ScrollBar.horizontal.policy: ScrollBar.AlwaysOff @@ -75,7 +118,6 @@ NPanel { contentWidth: availableWidth ColumnLayout { - visible: BluetoothService.adapter && BluetoothService.adapter.enabled width: parent.width spacing: Style.marginM * scaling diff --git a/Modules/SettingsPanel/Tabs/NetworkTab.qml b/Modules/SettingsPanel/Tabs/NetworkTab.qml index 0e1fd0d..c4ac87a 100644 --- a/Modules/SettingsPanel/Tabs/NetworkTab.qml +++ b/Modules/SettingsPanel/Tabs/NetworkTab.qml @@ -22,15 +22,7 @@ ColumnLayout { label: "Enable Bluetooth" description: "Enable Bluetooth connectivity." checked: Settings.data.network.bluetoothEnabled - onToggled: checked => { - Settings.data.network.bluetoothEnabled = checked - BluetoothService.setBluetoothEnabled(checked) - if (checked) { - ToastService.showNotice("Bluetooth", "Enabled") - } else { - ToastService.showNotice("Bluetooth", "Disabled") - } - } + onToggled: checked => BluetoothService.setBluetoothEnabled(checked) } NDivider { diff --git a/Services/BluetoothService.qml b/Services/BluetoothService.qml index da8e169..9bbc55b 100644 --- a/Services/BluetoothService.qml +++ b/Services/BluetoothService.qml @@ -30,6 +30,31 @@ Singleton { }) } + function init() { + Logger.log("Bluetooth", "Service initialized") + } + + Timer { + id: delayDiscovery + interval: 1000 + repeat: false + onTriggered: adapter.discovering = true + } + + Connections { + target: adapter + function onEnabledChanged() { + Settings.data.network.bluetoothEnabled = adapter.enabled + if (adapter.enabled) { + ToastService.showNotice("Bluetooth", "Enabled") + // Using a timer to give a little time so the adapter is really enabled + delayDiscovery.running = true + } else { + ToastService.showNotice("Bluetooth", "Disabled") + } + } + } + function sortDevices(devices) { return devices.sort((a, b) => { var aName = a.name || a.deviceName || ""