Bluetooth: added a button to enable/disable straight from the panel + minor improvements.

This commit is contained in:
LemmyCook 2025-09-09 21:23:57 -04:00
parent b1f501f3f9
commit 16cea533da
4 changed files with 71 additions and 10 deletions

View file

@ -193,6 +193,8 @@ Singleton {
FontService.init()
HooksService.init()
BluetoothService.init()
}
// -----------------------------------------------------

View file

@ -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

View file

@ -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 {

View file

@ -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 || ""