Fixes to builtin::BattInfo usage

This commit is contained in:
Stephen Seo 2022-07-26 21:18:59 +09:00
parent 6d9d23166e
commit 0b78778987
2 changed files with 10 additions and 7 deletions

View file

@ -56,7 +56,7 @@ pub fn print_usage() {
.ok(); .ok();
stderr_handle stderr_handle
.write_all( .write_all(
b" --acpi-builtin\t\t\t\tUse \"acpi -b\" built-in fetching (battery info, with color)\n", b" --acpi-builtin\t\t\t\t\tUse \"acpi -b\" built-in fetching (battery info, with color)\n",
) )
.ok(); .ok();
stderr_handle stderr_handle

View file

@ -74,10 +74,8 @@ fn main() {
} }
let mut batt_info: builtin::BattInfo = Default::default(); let mut batt_info: builtin::BattInfo = Default::default();
{ let batt_info_enabled: bool = args_result.map.contains_key("acpi-builtin");
let mut temp_object = SwaybarObject::new("battinfo".to_owned()); let mut batt_info_error: bool = false;
batt_info.update(&mut temp_object).ok();
}
println!( println!(
"{}", "{}",
@ -212,15 +210,20 @@ fn main() {
} }
// batt_info // batt_info
if !batt_info.is_error_state() { if batt_info_enabled {
if is_empty { if is_empty {
let mut new_object = SwaybarObject::new("battinfo".to_owned()); let mut new_object = SwaybarObject::new("battinfo".to_owned());
if batt_info.update(&mut new_object).is_ok() { if batt_info.update(&mut new_object).is_ok() {
array.push_object(new_object); array.push_object(new_object);
} else {
new_object.update_as_error("BATTINFO ERROR".to_owned());
array.push_object(new_object);
batt_info_error = true;
} }
} else if let Some(obj) = array.get_by_name_mut("battinfo") { } else if let Some(obj) = array.get_by_name_mut("battinfo") {
if batt_info.update(obj).is_err() { if !batt_info_error && batt_info.update(obj).is_err() {
obj.update_as_error("BATTINFO ERROR".to_owned()); obj.update_as_error("BATTINFO ERROR".to_owned());
batt_info_error = true;
} }
} }
} }