parent
7f1f217d84
commit
9fae5efc06
|
@ -24,6 +24,7 @@ class Battery : public ALabel {
|
||||||
void worker();
|
void worker();
|
||||||
|
|
||||||
util::SleeperThread thread_;
|
util::SleeperThread thread_;
|
||||||
|
util::SleeperThread threadTimer_;
|
||||||
std::vector<fs::path> batteries_;
|
std::vector<fs::path> batteries_;
|
||||||
int fd_;
|
int fd_;
|
||||||
};
|
};
|
||||||
|
|
|
@ -47,12 +47,18 @@ void waybar::modules::Battery::worker()
|
||||||
{
|
{
|
||||||
// Trigger first values
|
// Trigger first values
|
||||||
update();
|
update();
|
||||||
|
uint32_t interval = config_["interval"] ? config_["interval"].asUInt() : 60;
|
||||||
|
threadTimer_ = [this, interval] {
|
||||||
|
thread_.sleep_for(chrono::seconds(interval));
|
||||||
|
dp.emit();
|
||||||
|
};
|
||||||
thread_ = [this] {
|
thread_ = [this] {
|
||||||
struct inotify_event event = {0};
|
struct inotify_event event = {0};
|
||||||
int nbytes = read(fd_, &event, sizeof(event));
|
int nbytes = read(fd_, &event, sizeof(event));
|
||||||
if (nbytes != sizeof(event)) {
|
if (nbytes != sizeof(event)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
threadTimer_.stop();
|
||||||
dp.emit();
|
dp.emit();
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue