Fixes to builtin::BattInfo usage
This commit is contained in:
parent
6d9d23166e
commit
0b78778987
2 changed files with 10 additions and 7 deletions
|
@ -56,7 +56,7 @@ pub fn print_usage() {
|
|||
.ok();
|
||||
stderr_handle
|
||||
.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();
|
||||
stderr_handle
|
||||
|
|
15
src/main.rs
15
src/main.rs
|
@ -74,10 +74,8 @@ fn main() {
|
|||
}
|
||||
|
||||
let mut batt_info: builtin::BattInfo = Default::default();
|
||||
{
|
||||
let mut temp_object = SwaybarObject::new("battinfo".to_owned());
|
||||
batt_info.update(&mut temp_object).ok();
|
||||
}
|
||||
let batt_info_enabled: bool = args_result.map.contains_key("acpi-builtin");
|
||||
let mut batt_info_error: bool = false;
|
||||
|
||||
println!(
|
||||
"{}",
|
||||
|
@ -212,15 +210,20 @@ fn main() {
|
|||
}
|
||||
|
||||
// batt_info
|
||||
if !batt_info.is_error_state() {
|
||||
if batt_info_enabled {
|
||||
if is_empty {
|
||||
let mut new_object = SwaybarObject::new("battinfo".to_owned());
|
||||
if batt_info.update(&mut new_object).is_ok() {
|
||||
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") {
|
||||
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());
|
||||
batt_info_error = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue