diff --git a/applets/cosmic-applet-battery/i18n/en/cosmic_applet_battery.ftl b/applets/cosmic-applet-battery/i18n/en/cosmic_applet_battery.ftl index 4b4a14fc..40e38382 100644 --- a/applets/cosmic-applet-battery/i18n/en/cosmic_applet_battery.ftl +++ b/applets/cosmic-applet-battery/i18n/en/cosmic_applet_battery.ftl @@ -1 +1,8 @@ cosmic-applet-button = Cosmic Button +battery = Battery +max-charge = Increase the lifespan of your battery by setting a maximum charge value of 80% +seconds = s +minutes = m +hours = h +until-empty = until empty +power-settings = Power Settings... \ No newline at end of file diff --git a/applets/cosmic-applet-battery/src/app.rs b/applets/cosmic-applet-battery/src/app.rs index 62cc3047..92e3a4d3 100644 --- a/applets/cosmic-applet-battery/src/app.rs +++ b/applets/cosmic-applet-battery/src/app.rs @@ -24,6 +24,7 @@ use crate::backlight::{ScreenBacklightRequest, screen_backlight_subscription, Sc use crate::config; use crate::upower_device::{device_subscription, DeviceDbusEvent}; use crate::upower_kbdbacklight::{KeyboardBacklightRequest, kbd_backlight_subscription, KeyboardBacklightUpdate}; +use crate::fl; // XXX improve // TODO: time to empty varies? needs averaging? @@ -34,10 +35,10 @@ fn format_duration(duration: Duration) -> String { if min > 60 { format!("{}:{:02}", min / 60, min % 60) } else { - format!("{}m", min) + format!("{}{}", min, fl!("minutes")) } } else { - format!("{}s", secs) + format!("{}{}", secs, fl!("seconds")) } } @@ -169,7 +170,7 @@ impl Application for CosmicBatteryApplet { let mut popup_settings = get_popup_settings(window::Id::new(0), new_id, (400, 240), None, None); - // popup_settings.positioner.anchor_rect.x = 200; + popup_settings.positioner.anchor_rect.x = 200; return get_popup(popup_settings); } } @@ -216,13 +217,14 @@ impl Application for CosmicBatteryApplet { .style(Button::Text) .into(), SurfaceIdWrapper::Popup(_) => { - let name = text("Battery").size(18); - let description = text(if "battery-full-charged-symbolic" == self.icon_name { - "Charging".to_string() + let name = text(fl!("battery")).size(18); + let description = text(if "battery-full-charging-symbolic" == self.icon_name || "battery-full-charged-symbolic" == self.icon_name { + format!("{}%", self.battery_percent) } else { format!( - "{} until empty ({:.0}%)", + "{} {} ({:.0}%)", format_duration(self.time_remaining), + fl!("until-empty"), self.battery_percent ) }) @@ -240,10 +242,11 @@ impl Application for CosmicBatteryApplet { .height(Length::Units(24)), column![name, description] ] + .spacing(8) .align_items(Alignment::Center), separator!(1), // text{"Limit Battery Charging"}, - widget::Toggler::new(self.charging_limit, String::from("Increase the lifespan of your battery by settings a maximum charger valur of 80%"), |_| Message::SetChargingLimit(!self.charging_limit)), + widget::Toggler::new(self.charging_limit, fl!("max-charge"), |_| Message::SetChargingLimit(!self.charging_limit)), separator!(1), row![icon("display-brightness-symbolic", 24) .style( @@ -269,7 +272,7 @@ impl Application for CosmicBatteryApplet { widget::slider(0..=100, (self.kbd_brightness * 100.0) as i32, Message::SetKbdBrightness), text(format!("{:.0}%", self.kbd_brightness * 100.0)).width(Length::Units(40)).horizontal_alignment(Horizontal::Right) ].spacing(12), - button(text("Power Settings...").horizontal_alignment(Horizontal::Center).width(Length::Fill).style(theme::Text::Custom(|theme| { + button(text(fl!("power-settings")).horizontal_alignment(Horizontal::Center).width(Length::Fill).style(theme::Text::Custom(|theme| { let cosmic = theme.cosmic(); iced_style::text::Appearance { color: Some(cosmic.accent.on.into()) diff --git a/applets/cosmic-applet-battery/src/backlight.rs b/applets/cosmic-applet-battery/src/backlight.rs index c166eb22..84faaee0 100644 --- a/applets/cosmic-applet-battery/src/backlight.rs +++ b/applets/cosmic-applet-battery/src/backlight.rs @@ -117,13 +117,17 @@ async fn start_listening(id: I, state: State) -> (Option<(I, ScreenBack State::Waiting(backlight, proxy, mut rx) => { match rx.recv().await { Some(req) => match req { - ScreenBacklightRequest::Get => ( - Some(( - id, - ScreenBacklightUpdate::Update(backlight.brightness().await.unwrap_or_default() as f64) - )), - State::Waiting(backlight, proxy, rx), - ), + ScreenBacklightRequest::Get => { + let msg = if let Some(max_brightness) = backlight.max_brightness().await { + let value = (backlight.brightness().await.unwrap_or_default() as f64 / max_brightness as f64).clamp(0., 1.); + Some(( + id, + ScreenBacklightUpdate::Update(value) + )) + } else { None }; + (msg, State::Waiting(backlight, proxy, rx)) + } + , ScreenBacklightRequest::Set(value) => { if let Some(max_brightness) = backlight.max_brightness().await { let value = value.clamp(0., 1.) * (max_brightness as f64);