use capacity as default for battery percentage, less complicated and matches desktop percent exactly

This commit is contained in:
jkre 2023-12-13 23:58:40 +01:00
parent ab294bfc10
commit f6d8c4a044

View file

@ -757,7 +757,14 @@ namespace Cpu {
long seconds = -1;
//? Try to get battery percentage
if (b.use_energy_or_charge) {
if (percent < 0) {
try {
percent = stoll(readfile(b.base_dir / "capacity", "-1"));
}
catch (const std::invalid_argument&) { }
catch (const std::out_of_range&) { }
}
if (b.use_energy_or_charge and percent < 0) {
try {
percent = round(100.0 * stoll(readfile(b.energy_now, "-1")) / stoll(readfile(b.energy_full, "1")));
}
@ -771,13 +778,6 @@ namespace Cpu {
catch (const std::invalid_argument&) { }
catch (const std::out_of_range&) { }
}
if (percent < 0) {
try {
percent = stoll(readfile(b.base_dir / "capacity", "-1"));
}
catch (const std::invalid_argument&) { }
catch (const std::out_of_range&) { }
}
if (percent < 0) {
has_battery = false;
return {0, 0, ""};