bluetooth: refractor and fix wrong icon

This commit is contained in:
end-4
2025-08-29 12:06:01 +07:00
parent b52440bcc1
commit d239ab6b1f
4 changed files with 27 additions and 16 deletions
@@ -1,4 +1,5 @@
import qs
import qs.services
import qs.modules.common
import qs.modules.common.widgets
import qs.modules.common.functions
@@ -10,11 +11,8 @@ import Quickshell.Hyprland
QuickToggleButton {
id: root
readonly property bool bluetoothEnabled: Bluetooth.defaultAdapter?.enabled ?? false
readonly property BluetoothDevice bluetoothDevice: Bluetooth.defaultAdapter?.devices.values.find(device => device.connected) ?? null
readonly property bool bluetoothConnected: bluetoothDevice !== undefined
toggled: bluetoothEnabled
buttonIcon: bluetoothConnected ? "bluetooth_connected" : bluetoothEnabled ? "bluetooth" : "bluetooth_disabled"
toggled: BluetoothStatus.enabled
buttonIcon: BluetoothStatus.connected ? "bluetooth_connected" : BluetoothStatus.enabled ? "bluetooth" : "bluetooth_disabled"
onClicked: {
Bluetooth.defaultAdapter.enabled = !Bluetooth.defaultAdapter?.enabled
}
@@ -24,7 +22,8 @@ QuickToggleButton {
}
StyledToolTip {
content: Translation.tr("%1 | Right-click to configure").arg(
(bluetoothDevice?.name.length > 0) ?
bluetoothDevice.name : Translation.tr("Bluetooth"))
(BluetoothStatus.firstActiveDevice?.name ?? Translation.tr("Bluetooth"))
+ (BluetoothStatus.activeDeviceCount > 1 ? ` +${BluetoothStatus.activeDeviceCount - 1}` : "")
)
}
}