add `waitingWorker()` to `Custom`

This commit is contained in:
Evan Overman 2023-09-18 14:56:14 -07:00
parent 7c28ffc856
commit bf371f70d1
No known key found for this signature in database
GPG Key ID: 770E66F5A8D6623F
2 changed files with 25 additions and 2 deletions

View File

@ -22,6 +22,7 @@ class Custom : public ALabel {
private:
void delayWorker();
void continuousWorker();
void waitingWorker();
void parseOutputRaw();
void parseOutputJson();
void handleEvent();

View File

@ -11,11 +11,13 @@ waybar::modules::Custom::Custom(const std::string& name, const std::string& id,
fp_(nullptr),
pid_(-1) {
dp.emit();
if (interval_.count() > 0) {
if (!config_["signal"].empty() && config_["interval"].empty()) {
waitingWorker();
} else if (interval_.count() > 0) {
delayWorker();
} else if (config_["exec"].isString()) {
continuousWorker();
}
}
}
waybar::modules::Custom::~Custom() {
@ -92,6 +94,26 @@ void waybar::modules::Custom::continuousWorker() {
};
}
void waybar::modules::Custom::waitingWorker() {
thread_ = [this] {
bool can_update = true;
if (config_["exec-if"].isString()) {
output_ = util::command::execNoRead(config_["exec-if"].asString());
if (output_.exit_code != 0) {
can_update = false;
dp.emit();
}
}
if (can_update) {
if (config_["exec"].isString()) {
output_ = util::command::exec(config_["exec"].asString());
}
dp.emit();
}
thread_.sleep();
};
}
void waybar::modules::Custom::refresh(int sig) {
if (sig == SIGRTMIN + config_["signal"].asInt()) {
thread_.wake_up();