From 9fae5efc069d19cb7437b84f7e638f785048a9e5 Mon Sep 17 00:00:00 2001 From: Alexis Date: Thu, 25 Oct 2018 17:39:15 +0200 Subject: [PATCH] feat: use interval thread until got inotify event --- include/modules/battery.hpp | 1 + src/modules/battery.cpp | 6 ++++++ 2 files changed, 7 insertions(+) diff --git a/include/modules/battery.hpp b/include/modules/battery.hpp index 7b612c4..d7bb757 100644 --- a/include/modules/battery.hpp +++ b/include/modules/battery.hpp @@ -24,6 +24,7 @@ class Battery : public ALabel { void worker(); util::SleeperThread thread_; + util::SleeperThread threadTimer_; std::vector batteries_; int fd_; }; diff --git a/src/modules/battery.cpp b/src/modules/battery.cpp index ddfcb4f..53abbe5 100644 --- a/src/modules/battery.cpp +++ b/src/modules/battery.cpp @@ -47,12 +47,18 @@ void waybar::modules::Battery::worker() { // Trigger first values update(); + uint32_t interval = config_["interval"] ? config_["interval"].asUInt() : 60; + threadTimer_ = [this, interval] { + thread_.sleep_for(chrono::seconds(interval)); + dp.emit(); + }; thread_ = [this] { struct inotify_event event = {0}; int nbytes = read(fd_, &event, sizeof(event)); if (nbytes != sizeof(event)) { return; } + threadTimer_.stop(); dp.emit(); }; }