From de5df09fcdffeeea19e7eb117505302d01f6da1d Mon Sep 17 00:00:00 2001 From: Alexis Date: Wed, 5 Sep 2018 19:20:19 +0200 Subject: [PATCH] fix(Custom): loop script block main loop --- include/modules/custom.hpp | 1 + include/util/command.hpp | 4 ++-- src/modules/custom.cpp | 9 ++++----- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/include/modules/custom.hpp b/include/modules/custom.hpp index dcab363..bb0204f 100644 --- a/include/modules/custom.hpp +++ b/include/modules/custom.hpp @@ -17,6 +17,7 @@ class Custom : public ALabel { const std::string name_; waybar::util::SleeperThread thread_; + waybar::util::command::res output_; }; } diff --git a/include/util/command.hpp b/include/util/command.hpp index 80773cb..1806958 100644 --- a/include/util/command.hpp +++ b/include/util/command.hpp @@ -4,12 +4,12 @@ namespace waybar::util::command { -struct cmd_res { +struct res { int exit_code; std::string out; }; -inline struct cmd_res exec(const std::string cmd) +inline struct res exec(const std::string cmd) { FILE* fp(popen(cmd.c_str(), "r")); if (!fp) { diff --git a/src/modules/custom.cpp b/src/modules/custom.cpp index ccb9e4d..a47d508 100644 --- a/src/modules/custom.cpp +++ b/src/modules/custom.cpp @@ -24,6 +24,7 @@ void waybar::modules::Custom::worker() } } if (can_update) { + output_ = waybar::util::command::exec(config_["exec"].asString()); dp.emit(); } thread_.sleep_for(chrono::seconds(interval)); @@ -32,17 +33,15 @@ void waybar::modules::Custom::worker() auto waybar::modules::Custom::update() -> void { - auto res = waybar::util::command::exec(config_["exec"].asString()); - // Hide label if output is empty - if (res.out.empty() || res.exit_code != 0) { + if (output_.out.empty() || output_.exit_code != 0) { label_.hide(); label_.set_name(""); } else { label_.set_name("custom-" + name_); - auto str = fmt::format(format_, res.out); + auto str = fmt::format(format_, output_.out); label_.set_text(str); label_.set_tooltip_text(str); label_.show(); } -} +} \ No newline at end of file