wactioncenter: bluetooth menu

This commit is contained in:
end-4
2025-11-22 21:55:47 +01:00
parent 7613bba393
commit 55961ae079
22 changed files with 451 additions and 69 deletions
@@ -6,9 +6,6 @@ import Quickshell.Bluetooth
import Quickshell.Io
import QtQuick
/**
* Network service with nmcli.
*/
Singleton {
id: root
@@ -17,4 +14,24 @@ Singleton {
readonly property BluetoothDevice firstActiveDevice: Bluetooth.defaultAdapter?.devices.values.find(device => device.connected) ?? null
readonly property int activeDeviceCount: Bluetooth.defaultAdapter?.devices.values.filter(device => device.connected).length ?? 0
readonly property bool connected: Bluetooth.devices.values.some(d => d.connected)
function sortFunction(a, b) {
// Ones with meaningful names before MAC addresses
const macRegex = /^([0-9A-Fa-f]{2}-){5}[0-9A-Fa-f]{2}$/;
const aIsMac = macRegex.test(a.name);
const bIsMac = macRegex.test(b.name);
if (aIsMac !== bIsMac)
return aIsMac ? 1 : -1;
// Alphabetical by name
return a.name.localeCompare(b.name);
}
property list<var> connectedDevices: Bluetooth.devices.values.filter(d => d.connected).sort(sortFunction)
property list<var> pairedButNotConnectedDevices: Bluetooth.devices.values.filter(d => d.paired && !d.connected).sort(sortFunction)
property list<var> unpairedDevices: Bluetooth.devices.values.filter(d => !d.paired && !d.connected).sort(sortFunction)
property list<var> friendlyDeviceList: [
...connectedDevices,
...pairedButNotConnectedDevices,
...unpairedDevices
]
}