mirror of
https://github.com/morgan9e/macos-stats
synced 2026-04-14 00:04:15 +09:00
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:
@@ -537,21 +537,29 @@ public class BatteryDetailsWidget: WidgetWrapper {
|
||||
if let percentage = self.percentage {
|
||||
value = "\(Int((percentage.rounded(toPlaces: 2)) * 100))%"
|
||||
}
|
||||
width = self.drawTwoRows(
|
||||
first: value,
|
||||
second: Double(self.time*60).printSecondsToHoursMinutesSeconds(short: isShortTimeFormat),
|
||||
x: x
|
||||
).rounded(.up)
|
||||
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))%"
|
||||
}
|
||||
width = self.drawTwoRows(
|
||||
first: Double(self.time*60).printSecondsToHoursMinutesSeconds(short: isShortTimeFormat),
|
||||
second: value,
|
||||
x: x
|
||||
).rounded(.up)
|
||||
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
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user