battery: Better formatting for time to empty
This commit is contained in:
parent
e46abe4dc3
commit
0348d7a93d
1 changed files with 17 additions and 2 deletions
|
|
@ -20,6 +20,22 @@ async fn display_device() -> zbus::Result<DeviceProxy<'static>> {
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// XXX improve
|
||||||
|
// TODO: time to empty varies? needs averaging?
|
||||||
|
fn format_duration(duration: Duration) -> String {
|
||||||
|
let secs = duration.as_secs();
|
||||||
|
if secs > 60 {
|
||||||
|
let min = secs / 60;
|
||||||
|
if min > 60 {
|
||||||
|
format!("{}:{}", min / 60, min % 60)
|
||||||
|
} else {
|
||||||
|
format!("{}m", min)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
format!("{}s", secs)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Default)]
|
#[derive(Default)]
|
||||||
struct AppModel {
|
struct AppModel {
|
||||||
icon_name: String,
|
icon_name: String,
|
||||||
|
|
@ -73,10 +89,9 @@ impl SimpleComponent for AppModel {
|
||||||
},
|
},
|
||||||
gtk4::Label {
|
gtk4::Label {
|
||||||
set_halign: gtk4::Align::Start,
|
set_halign: gtk4::Align::Start,
|
||||||
// XXX duration formatting
|
|
||||||
// XXX time to full, fully changed, etc.
|
// XXX time to full, fully changed, etc.
|
||||||
#[watch]
|
#[watch]
|
||||||
set_label: &format!("{:?} until empty ({:.0}%)", model.time_remaining, model.battery_percent),
|
set_label: &format!("{} until empty ({:.0}%)", format_duration(model.time_remaining), model.battery_percent),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue