From e55d59ed94d24119775f8fd819a1e1b2e2d49196 Mon Sep 17 00:00:00 2001 From: Jonathan Capps Date: Sat, 15 Mar 2025 18:02:58 +0000 Subject: [PATCH] fix: prevent time remaining showing 0 after unplugging --- cosmic-applet-battery/src/app.rs | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/cosmic-applet-battery/src/app.rs b/cosmic-applet-battery/src/app.rs index 31f2e3fc..835520c3 100644 --- a/cosmic-applet-battery/src/app.rs +++ b/cosmic-applet-battery/src/app.rs @@ -504,16 +504,18 @@ impl cosmic::Application for CosmicBatteryApplet { } = theme::active().cosmic().spacing; let name = text::body(fl!("battery")); - let description = text::caption(if !self.on_battery { - format!("{:.0}%", self.battery_percent) - } else { - format!( - "{} {} ({:.0}%)", - format_duration(self.time_remaining), - fl!("until-empty"), - self.battery_percent - ) - }); + let description = text::caption( + if !self.on_battery || self.time_remaining == Duration::from_secs(0u64) { + format!("{:.0}%", self.battery_percent) + } else { + format!( + "{} {} ({:.0}%)", + format_duration(self.time_remaining), + fl!("until-empty"), + self.battery_percent + ) + }, + ); let mut content = vec![ padded_control(