Skip to content

Commit aeef91f

Browse files
committed
Battery Percentage colour changes / alignment
1 parent c1998d2 commit aeef91f

File tree

1 file changed

+16
-7
lines changed

1 file changed

+16
-7
lines changed

src/lib/util.ts

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,11 @@ const icons: Record<string, icon> = {
2222
iconName: 'battery.25percent',
2323
color: Color.red(),
2424
},
25-
'battery.50': {
25+
'battery.50.green': {
26+
iconName: 'battery.50percent',
27+
color: Color.green(),
28+
},
29+
'battery.50.orange': {
2630
iconName: 'battery.50percent',
2731
color: Color.orange(),
2832
},
@@ -144,9 +148,9 @@ export function getChargeCompletionString(
144148
}
145149

146150
export function getBatteryPercentColor(batteryPercent: number): Color {
147-
if (batteryPercent >= 50) {
151+
if (batteryPercent >= 45) {
148152
return Color.green()
149-
} else if (batteryPercent >= 30) {
153+
} else if (batteryPercent >= 35) {
150154
return Color.orange()
151155
}
152156
return Color.red()
@@ -204,16 +208,21 @@ export function getChargingIcon(isCharging: boolean, isPluggedIn: boolean, isWid
204208

205209
export function calculateBatteryIcon(batteryPercent: number): string {
206210
let percentRounded = 0
211+
let colorExtra = ''
207212
if (batteryPercent > 90) {
208213
percentRounded = 100
209-
} else if (batteryPercent > 60) {
214+
} else if (batteryPercent >= 65) {
210215
percentRounded = 75
211-
} else if (batteryPercent > 40) {
216+
} else if (batteryPercent >= 45) {
217+
percentRounded = 50
218+
colorExtra = '.green'
219+
} else if (batteryPercent >= 35) {
212220
percentRounded = 50
213-
} else if (batteryPercent > 15) {
221+
colorExtra = '.orange'
222+
} else if (batteryPercent >= 15) {
214223
percentRounded = 25
215224
}
216-
return `battery.${percentRounded}`
225+
return `battery.${percentRounded}${colorExtra}`
217226
}
218227

219228
export async function tintSFSymbol(name: string, image: Image, color: Color, rotateDegree?: number) {

0 commit comments

Comments
 (0)