mirror of https://github.com/aristocratos/btop.git
improved battery detection
- new considering all power supplies (instead of path name filtering) - only consider power supplies that are currently present - only consider power supplies of type Batter or UPS
This commit is contained in:
parent
2ee1333226
commit
966c9f5e5e
|
@ -477,7 +477,16 @@ namespace Cpu {
|
|||
if (bat_dir.empty() and has_battery) {
|
||||
if (fs::exists("/sys/class/power_supply")) {
|
||||
for (const auto& d : fs::directory_iterator("/sys/class/power_supply")) {
|
||||
if (const string dir_name = d.path().filename(); d.is_directory() and (dir_name.starts_with("BAT") or s_contains(str_to_lower(dir_name), "battery"))) {
|
||||
//? Only consider online power supplies of type Battery or UPS
|
||||
//? see kernel docs for details on the file structure and contents
|
||||
//? https://www.kernel.org/doc/Documentation/ABI/testing/sysfs-class-power
|
||||
if (not d.is_directory()
|
||||
or not fs::exists(d.path() / "type")
|
||||
or not fs::exists(d.path() / "present")
|
||||
or stoi(readfile(d.path() / "present")) != 1)
|
||||
continue;
|
||||
string type = readfile(d.path() / "type");
|
||||
if (type == "Battery" or type == "UPS") {
|
||||
bat_dir = d.path();
|
||||
break;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue