Skip to content

Commit

Permalink
Initialize plugged using the main battery's status
Browse files Browse the repository at this point in the history
  • Loading branch information
baskerville committed Feb 25, 2024
1 parent a3a34b8 commit fad6eb2
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 1 deletion.
6 changes: 6 additions & 0 deletions crates/core/src/battery/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,12 @@ pub enum Status {
// Full,
}

impl Status {
pub fn is_wired(self) -> bool {
matches!(self, Status::Charging | Status::Charged)
}
}

pub trait Battery {
fn capacity(&mut self) -> Result<Vec<f32>, Error>;
fn status(&mut self) -> Result<Vec<Status>, Error>;
Expand Down
2 changes: 1 addition & 1 deletion crates/core/src/view/battery.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ impl View for Battery {

pt = self.rect.min + pt!(dx, dy) + pt!(border_thickness);

if self.status != Status::Discharging {
if self.status.is_wired() {
let name = if self.status == Status::Charging { "plug" } else { "check_mark-small" };
let pixmap = ICONS_PIXMAPS.get(name).unwrap();
pt += pt!((max_fill_width - pixmap.width as i32) / 2,
Expand Down
3 changes: 3 additions & 0 deletions crates/plato/src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,9 @@ pub fn run() -> Result<(), Error> {
}

let mut context = build_context(fb).context("can't build context")?;

context.plugged = context.battery.status().is_ok_and(|v| v[0].is_wired());

if context.settings.import.startup_trigger {
context.batch_import();
}
Expand Down

0 comments on commit fad6eb2

Please sign in to comment.