1
0
Fork 0
mirror of https://github.com/Zedfrigg/ironbar.git synced 2025-07-01 18:51:04 +02:00

fix(upower): popup always empty

This commit is contained in:
Jake Stanger 2023-05-07 16:13:32 +01:00
parent fe12251af8
commit f82f897982

View file

@ -212,28 +212,35 @@ impl Module<gtk::Box> for UpowerModule {
let label = Label::new(None); let label = Label::new(None);
add_class(&label, "upower-details"); add_class(&label, "upower-details");
container.add(&label);
rx.attach(None, move |properties| { rx.attach(None, move |properties| {
let mut format = String::new();
let state = u32_to_battery_state(properties.state); let state = u32_to_battery_state(properties.state);
match state { let format = match state {
Ok(BatteryState::Charging | BatteryState::PendingCharge) => { Ok(BatteryState::Charging | BatteryState::PendingCharge) => {
let ttf = properties.time_to_full; let ttf = properties.time_to_full;
if ttf > 0 { if ttf > 0 {
format = format!("Full in {}", seconds_to_string(ttf)); format!("Full in {}", seconds_to_string(ttf))
} else {
String::new()
} }
} }
Ok(BatteryState::Discharging | BatteryState::PendingDischarge) => { Ok(BatteryState::Discharging | BatteryState::PendingDischarge) => {
let tte = properties.time_to_empty; let tte = properties.time_to_empty;
if tte > 0 { if tte > 0 {
format = format!("Empty in {}", seconds_to_string(tte)); format!("Empty in {}", seconds_to_string(tte))
} else {
String::new()
} }
} }
Err(state) => error!("Invalid battery state: {state}"), Err(state) => {
_ => {} error!("Invalid battery state: {state}");
String::new()
} }
label.set_markup(&format); _ => String::new(),
};
label.set_markup(&format);
Continue(true) Continue(true)
}); });