fix(Custom): loop script block main loop

This commit is contained in:
Alexis 2018-09-05 19:20:19 +02:00
parent 7020af7653
commit de5df09fcd
No known key found for this signature in database
GPG Key ID: 20B1EC2EBBA96BD9
3 changed files with 7 additions and 7 deletions

View File

@ -17,6 +17,7 @@ class Custom : public ALabel {
const std::string name_;
waybar::util::SleeperThread thread_;
waybar::util::command::res output_;
};
}

View File

@ -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) {

View File

@ -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,15 +33,13 @@ 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();