feat: show battery status in Bluetooth popout (#1130)

* Display bluetooth battery in popout when possible

Signed-off-by: Dan Griffiths <dgriffiths@widgitlabs.com>

* Actually return the alert icon if battery status can't be determined

Signed-off-by: Dan Griffiths <dgriffiths@widgitlabs.com>

* Fix lint error

Signed-off-by: Dan Griffiths <dgriffiths@widgitlabs.com>

* move icon to right + static popout width

---------

Signed-off-by: Dan Griffiths <dgriffiths@widgitlabs.com>
Co-authored-by: 2 * r + 2 * t <61896496+soramanew@users.noreply.github.com>
This commit is contained in:
Evertiro 2026-04-02 23:32:00 -05:00 committed by GitHub
parent dfc5bcf8b9
commit f924dbfbbb
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 29 additions and 0 deletions

View file

@ -15,6 +15,7 @@ ColumnLayout {
required property PopoutState popouts
width: 300
spacing: Appearance.spacing.small
StyledText {
@ -99,6 +100,13 @@ ColumnLayout {
Layout.rightMargin: Appearance.spacing.small / 2
Layout.fillWidth: true
text: device.modelData.name
elide: Text.ElideRight
}
MaterialIcon {
visible: device.modelData.state === BluetoothDeviceState.Connected // qmllint disable unresolved-type
text: Icons.getBatteryIcon(device.modelData.batteryAvailable ? device.modelData.battery * 100 : -1)
color: device.modelData.battery < 0.2 ? Colours.palette.m3error : Colours.palette.m3onSurfaceVariant
}
StyledRect {
@ -141,6 +149,7 @@ ColumnLayout {
}
Loader {
visible: status === Loader.Ready
asynchronous: true
active: device.modelData.bonded
sourceComponent: Item {

View file

@ -240,4 +240,24 @@ Singleton {
}
return icon;
}
function getBatteryIcon(charge: int): string {
if (charge > 0 && charge < 5)
return "battery_0_bar";
if (charge >= 5 && charge < 20)
return "battery_1_bar";
if (charge >= 20 && charge < 35)
return "battery_2_bar";
if (charge >= 35 && charge < 50)
return "battery_3_bar";
if (charge >= 50 && charge < 65)
return "battery_4_bar";
if (charge >= 65 && charge < 80)
return "battery_5_bar";
if (charge >= 80 && charge < 95)
return "battery_6_bar";
if (charge >= 95)
return "battery_full";
return "battery_alert";
}
}