fix(custom): avoid hide outside update

This commit is contained in:
Alex 2020-05-25 09:21:04 +02:00
parent 1d92d78de7
commit 3b16946c25
1 changed files with 6 additions and 8 deletions

View File

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