fix(custom): avoid hide outside update
This commit is contained in:
parent
1d92d78de7
commit
3b16946c25
|
@ -1,18 +1,15 @@
|
||||||
#include "modules/custom.hpp"
|
#include "modules/custom.hpp"
|
||||||
|
|
||||||
#include <spdlog/spdlog.h>
|
#include <spdlog/spdlog.h>
|
||||||
|
|
||||||
waybar::modules::Custom::Custom(const std::string& name, const std::string& id,
|
waybar::modules::Custom::Custom(const std::string& name, const std::string& id,
|
||||||
const Json::Value& config)
|
const Json::Value& config)
|
||||||
: ALabel(config, "custom-" + name, id, "{}"), name_(name), fp_(nullptr), pid_(-1) {
|
: ALabel(config, "custom-" + name, id, "{}"), name_(name), fp_(nullptr), pid_(-1) {
|
||||||
// Hide box by default
|
dp.emit();
|
||||||
event_box_.hide();
|
|
||||||
|
|
||||||
if (interval_.count() > 0) {
|
if (interval_.count() > 0) {
|
||||||
delayWorker();
|
delayWorker();
|
||||||
} else if (config_["exec"].isString()) {
|
} else if (config_["exec"].isString()) {
|
||||||
continuousWorker();
|
continuousWorker();
|
||||||
} else {
|
|
||||||
dp.emit();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -30,7 +27,7 @@ void waybar::modules::Custom::delayWorker() {
|
||||||
output_ = util::command::execNoRead(config_["exec-if"].asString());
|
output_ = util::command::execNoRead(config_["exec-if"].asString());
|
||||||
if (output_.exit_code != 0) {
|
if (output_.exit_code != 0) {
|
||||||
can_update = false;
|
can_update = false;
|
||||||
event_box_.hide();
|
dp.emit();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (can_update) {
|
if (can_update) {
|
||||||
|
@ -53,7 +50,7 @@ void waybar::modules::Custom::continuousWorker() {
|
||||||
thread_ = [this, cmd] {
|
thread_ = [this, cmd] {
|
||||||
char* buff = nullptr;
|
char* buff = nullptr;
|
||||||
size_t len = 0;
|
size_t len = 0;
|
||||||
bool restart = false;
|
bool restart = false;
|
||||||
if (getline(&buff, &len, fp_) == -1) {
|
if (getline(&buff, &len, fp_) == -1) {
|
||||||
int exit_code = 1;
|
int exit_code = 1;
|
||||||
if (fp_) {
|
if (fp_) {
|
||||||
|
@ -112,7 +109,8 @@ bool waybar::modules::Custom::handleToggle(GdkEventButton* const& e) {
|
||||||
|
|
||||||
auto waybar::modules::Custom::update() -> void {
|
auto waybar::modules::Custom::update() -> void {
|
||||||
// Hide label if output is empty
|
// Hide label if output is empty
|
||||||
if (config_["exec"].isString() && (output_.out.empty() || output_.exit_code != 0)) {
|
if ((config_["exec"].isString() || config_["exec-if"].isString()) &&
|
||||||
|
(output_.out.empty() || output_.exit_code != 0)) {
|
||||||
event_box_.hide();
|
event_box_.hide();
|
||||||
} else {
|
} else {
|
||||||
if (config_["return-type"].asString() == "json") {
|
if (config_["return-type"].asString() == "json") {
|
||||||
|
|
Loading…
Reference in New Issue