EWW_BATTERY is empty string when its {total_avg} property would otherwise be NaN (#425)

Fixes #373
This commit is contained in:
Biniam Bekele 2022-04-19 07:50:52 -04:00 committed by GitHub
parent 776dc787e7
commit fe4097c73e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -149,9 +149,11 @@ pub fn get_battery_capacity() -> Result<String> {
}
}
}
json.pop();
json.push_str(&format!(r#", "total_avg": {:.1}}}"#, (current / total) * 100_f64));
if total == 0_f64 {
return Ok(String::from(""));
}
json.push_str(&format!(r#" "total_avg": {:.1}}}"#, (current / total) * 100_f64));
Ok(json)
}