Skip to content

Commit f924dbf

Browse files
evertirosoramanew
andauthored
feat: show battery status in Bluetooth popout (caelestia-dots#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>
1 parent dfc5bcf commit f924dbf

2 files changed

Lines changed: 29 additions & 0 deletions

File tree

modules/bar/popouts/Bluetooth.qml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ ColumnLayout {
1515

1616
required property PopoutState popouts
1717

18+
width: 300
1819
spacing: Appearance.spacing.small
1920

2021
StyledText {
@@ -99,6 +100,13 @@ ColumnLayout {
99100
Layout.rightMargin: Appearance.spacing.small / 2
100101
Layout.fillWidth: true
101102
text: device.modelData.name
103+
elide: Text.ElideRight
104+
}
105+
106+
MaterialIcon {
107+
visible: device.modelData.state === BluetoothDeviceState.Connected // qmllint disable unresolved-type
108+
text: Icons.getBatteryIcon(device.modelData.batteryAvailable ? device.modelData.battery * 100 : -1)
109+
color: device.modelData.battery < 0.2 ? Colours.palette.m3error : Colours.palette.m3onSurfaceVariant
102110
}
103111

104112
StyledRect {
@@ -141,6 +149,7 @@ ColumnLayout {
141149
}
142150

143151
Loader {
152+
visible: status === Loader.Ready
144153
asynchronous: true
145154
active: device.modelData.bonded
146155
sourceComponent: Item {

utils/Icons.qml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -240,4 +240,24 @@ Singleton {
240240
}
241241
return icon;
242242
}
243+
244+
function getBatteryIcon(charge: int): string {
245+
if (charge > 0 && charge < 5)
246+
return "battery_0_bar";
247+
if (charge >= 5 && charge < 20)
248+
return "battery_1_bar";
249+
if (charge >= 20 && charge < 35)
250+
return "battery_2_bar";
251+
if (charge >= 35 && charge < 50)
252+
return "battery_3_bar";
253+
if (charge >= 50 && charge < 65)
254+
return "battery_4_bar";
255+
if (charge >= 65 && charge < 80)
256+
return "battery_5_bar";
257+
if (charge >= 80 && charge < 95)
258+
return "battery_6_bar";
259+
if (charge >= 95)
260+
return "battery_full";
261+
return "battery_alert";
262+
}
243263
}

0 commit comments

Comments
 (0)