diff --git a/src/linux/btop_collect.cpp b/src/linux/btop_collect.cpp index 0d58596..3961d91 100644 --- a/src/linux/btop_collect.cpp +++ b/src/linux/btop_collect.cpp @@ -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, ""};