From 9068e183799a0423e92ab6b56428164f160c6cf3 Mon Sep 17 00:00:00 2001 From: embedovator Date: Sun, 3 Aug 2025 18:52:51 +0800 Subject: [PATCH] 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 --- Kit/Widgets/Battery.swift | 28 ++++++++++++++++++---------- 1 file changed, 18 insertions(+), 10 deletions(-) diff --git a/Kit/Widgets/Battery.swift b/Kit/Widgets/Battery.swift index 8374c9d3..09cf6347 100644 --- a/Kit/Widgets/Battery.swift +++ b/Kit/Widgets/Battery.swift @@ -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 }