fix(Custom): loop script block main loop
This commit is contained in:
parent
7020af7653
commit
de5df09fcd
|
@ -17,6 +17,7 @@ class Custom : public ALabel {
|
|||
|
||||
const std::string name_;
|
||||
waybar::util::SleeperThread thread_;
|
||||
waybar::util::command::res output_;
|
||||
};
|
||||
|
||||
}
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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();
|
||||
|
|
Loading…
Reference in New Issue