feat(control-center): show Bluetooth battery in quick tile (#3160)

Display the selected device as `name • N%` when battery information is available, while preserving the existing name-only fallback.
This commit is contained in:
Vladimir
2026-08-25 17:43:09 -04:00
committed by GitHub
parent c8ec045a3c
commit 34cf6e6346
2 changed files with 16 additions and 3 deletions
@@ -545,8 +545,18 @@ Column {
}
return null;
})();
if (primaryDevice)
return primaryDevice.name || primaryDevice.alias || primaryDevice.deviceName || I18n.tr("Connected Device", "bluetooth status");
if (primaryDevice) {
const name = primaryDevice.name || primaryDevice.alias || primaryDevice.deviceName || I18n.tr("Connected Device", "bluetooth status");
// A reported 0% is valid; batteryAvailable distinguishes missing data.
// https://quickshell.org/docs/v0.3.1/types/Quickshell.Bluetooth/BluetoothDevice/
// https://bluez.readthedocs.io/en/latest/battery-api/
if (primaryDevice.batteryAvailable)
return `${name} • ${Math.round(primaryDevice.battery * 100)}%`;
const btBattery = BatteryService.bluetoothDevices.find(dev => dev.name === name || dev.name.toLowerCase().includes(name.toLowerCase()) || name.toLowerCase().includes(dev.name.toLowerCase()));
if (btBattery)
return `${name} • ${btBattery.percentage}%`;
return name;
}
return I18n.tr("No devices", "bluetooth status");
}
case "audioOutput":
@@ -362,7 +362,10 @@ Rectangle {
return BatteryService.bluetoothDevices.find(dev => dev.name === name || dev.name.toLowerCase().includes(name.toLowerCase()) || name.toLowerCase().includes(dev.name.toLowerCase()));
}
text: {
if (pairedDelegate.modelData.batteryAvailable && pairedDelegate.modelData.battery > 0)
// A reported 0% is valid; batteryAvailable distinguishes missing data.
// https://quickshell.org/docs/v0.3.1/types/Quickshell.Bluetooth/BluetoothDevice/
// https://bluez.readthedocs.io/en/latest/battery-api/
if (pairedDelegate.modelData.batteryAvailable)
return "• " + Math.round(pairedDelegate.modelData.battery * 100) + "%";
if (btBattery)
return "• " + btBattery.percentage + "%";