Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improved battery detection #97

Merged
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion src/linux/btop_collect.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -477,7 +477,16 @@ namespace Cpu {
if (bat_dir.empty() and has_battery) {
jan-guenter marked this conversation as resolved.
Show resolved Hide resolved
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()
jan-guenter marked this conversation as resolved.
Show resolved Hide resolved
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;
}
Expand Down