fix: show single row with percentage when time is not available in battery widget (#2649)

- Modified battery widget to show only percentage in a single row when time remaining is not available (e.g., when AC adapter is plugged in)
- Maintains two-row display with both percentage and time when running on battery with valid time information
- Improves UI by removing duplicate information and making better use of space

Co-authored-by: Nathan Martin <embedovator@pm.me>
This commit is contained in:
embedovator
2025-08-03 18:52:51 +08:00
committed by GitHub
parent 3a59807044
commit 9068e18379

View File

@@ -537,21 +537,29 @@ public class BatteryDetailsWidget: WidgetWrapper {
if let percentage = self.percentage {
value = "\(Int((percentage.rounded(toPlaces: 2)) * 100))%"
}
if self.time > 0 {
width = self.drawTwoRows(
first: value,
second: Double(self.time*60).printSecondsToHoursMinutesSeconds(short: isShortTimeFormat),
x: x
).rounded(.up)
} else {
width = self.drawOneRow(value: value, x: x).rounded(.up)
}
case "timeAndPercentage":
var value = "n/a"
if let percentage = self.percentage {
value = "\(Int((percentage.rounded(toPlaces: 2)) * 100))%"
}
if self.time > 0 {
width = self.drawTwoRows(
first: Double(self.time*60).printSecondsToHoursMinutesSeconds(short: isShortTimeFormat),
second: value,
x: x
).rounded(.up)
} else {
width = self.drawOneRow(value: value, x: x).rounded(.up)
}
default: break
}