mirror of
https://github.com/rad4day/Waybar.git
synced 2023-12-21 10:22:59 +01:00
Clean (#31)
This commit is contained in:
@ -1,7 +1,7 @@
|
||||
#include "modules/battery.hpp"
|
||||
|
||||
waybar::modules::Battery::Battery(Json::Value config)
|
||||
: ALabel(std::move(config))
|
||||
waybar::modules::Battery::Battery(const Json::Value& config)
|
||||
: ALabel(config)
|
||||
{
|
||||
try {
|
||||
for (auto &node : fs::directory_iterator(data_dir_)) {
|
||||
@ -23,25 +23,29 @@ waybar::modules::Battery::Battery(Json::Value config)
|
||||
for (auto &bat : batteries_) {
|
||||
inotify_add_watch(fd_, (bat / "uevent").c_str(), IN_ACCESS);
|
||||
}
|
||||
// Trigger first values
|
||||
update();
|
||||
label_.set_name("battery");
|
||||
thread_.sig_update.connect(sigc::mem_fun(*this, &Battery::update));
|
||||
worker();
|
||||
}
|
||||
|
||||
waybar::modules::Battery::~Battery()
|
||||
{
|
||||
close(fd_);
|
||||
}
|
||||
|
||||
void waybar::modules::Battery::worker()
|
||||
{
|
||||
// Trigger first values
|
||||
dp.emit();
|
||||
thread_ = [this] {
|
||||
struct inotify_event event = {0};
|
||||
int nbytes = read(fd_, &event, sizeof(event));
|
||||
if (nbytes != sizeof(event)) {
|
||||
return;
|
||||
}
|
||||
thread_.emit();
|
||||
dp.emit();
|
||||
};
|
||||
}
|
||||
|
||||
waybar::modules::Battery::~Battery()
|
||||
{
|
||||
close(fd_);
|
||||
}
|
||||
|
||||
auto waybar::modules::Battery::update() -> void
|
||||
{
|
||||
try {
|
||||
|
Reference in New Issue
Block a user