add `waitingWorker()` to `Custom`
parent
7c28ffc856
commit
bf371f70d1
|
@ -22,6 +22,7 @@ class Custom : public ALabel {
|
|||
private:
|
||||
void delayWorker();
|
||||
void continuousWorker();
|
||||
void waitingWorker();
|
||||
void parseOutputRaw();
|
||||
void parseOutputJson();
|
||||
void handleEvent();
|
||||
|
|
|
@ -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();
|
||||
|
|
Loading…
Reference in New Issue