Plug/Unplug batteries on hot(useful for gamepads)

This commit is contained in:
Viktar Lukashonak 2022-03-14 17:12:05 +03:00
parent 5c1c07a035
commit 8aee7492d4
No known key found for this signature in database
GPG Key ID: 08A413AA87200A6F

View File

@ -118,9 +118,10 @@ void waybar::modules::Battery::refreshBatteries() {
}
if (batteries_.empty()) {
if (config_["bat"].isString()) {
throw std::runtime_error("No battery named " + config_["bat"].asString());
spdlog::warn("No battery named {}", config_["bat"].asString());
} else {
spdlog::warn("No batteries.");
}
throw std::runtime_error("No batteries.");
}
// Remove any batteries that are no longer present and unwatch them
@ -283,6 +284,10 @@ const std::string waybar::modules::Battery::formatTimeRemaining(float hoursRemai
}
auto waybar::modules::Battery::update() -> void {
if (batteries_.empty()) {
event_box_.hide();
return;
}
auto [capacity, time_remaining, status, power] = getInfos();
if (status == "Unknown") {
status = getAdapterStatus(capacity);