fix(Battery): plugged state

This commit is contained in:
Alex 2019-05-17 10:59:54 +02:00
parent 9a091d7740
commit 17291dffdf

View File

@ -93,10 +93,14 @@ const std::tuple<uint8_t, uint32_t, std::string> waybar::modules::Battery::getIn
total += capacity; total += capacity;
total_current += current_now; total_current += current_now;
} }
uint16_t capacity = total / batteries_.size(); if (!adapter_.empty() && status == "Discharging") {
if (status == "Charging" && total_current != 0) { bool online;
status = "Plugged"; std::ifstream(adapter_ / "online") >> online;
if (online) {
status = "Plugged";
}
} }
uint16_t capacity = total / batteries_.size();
return {capacity, total_current, status}; return {capacity, total_current, status};
} catch (const std::exception& e) { } catch (const std::exception& e) {
std::cerr << e.what() << std::endl; std::cerr << e.what() << std::endl;
@ -113,7 +117,7 @@ const std::string waybar::modules::Battery::getAdapterStatus(uint8_t capacity,
return "Full"; return "Full";
} }
if (online) { if (online) {
return current_now == 0 ? "Charging" : "Plugged"; return "Charging";
} }
return "Discharging"; return "Discharging";
} }