mirror of
https://github.com/rad4day/Waybar.git
synced 2023-12-21 10:22:59 +01:00
fix(Custom): hide label when exec-if failed
This commit is contained in:
parent
0ad2bc7516
commit
c8ca8b3725
@ -7,6 +7,7 @@ waybar::modules::Custom::Custom(const std::string name,
|
|||||||
if (!config_["exec"]) {
|
if (!config_["exec"]) {
|
||||||
throw std::runtime_error(name_ + " has no exec path.");
|
throw std::runtime_error(name_ + " has no exec path.");
|
||||||
}
|
}
|
||||||
|
label_.set_name("custom-" + name_);
|
||||||
worker();
|
worker();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -19,6 +20,7 @@ void waybar::modules::Custom::worker()
|
|||||||
auto res = waybar::util::command::exec(config_["exec-if"].asString());
|
auto res = waybar::util::command::exec(config_["exec-if"].asString());
|
||||||
if (res.exit_code != 0) {
|
if (res.exit_code != 0) {
|
||||||
can_update = false;
|
can_update = false;
|
||||||
|
label_.hide();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (can_update) {
|
if (can_update) {
|
||||||
@ -35,9 +37,7 @@ auto waybar::modules::Custom::update() -> void
|
|||||||
// Hide label if output is empty
|
// Hide label if output is empty
|
||||||
if (res.out.empty() || res.exit_code != 0) {
|
if (res.out.empty() || res.exit_code != 0) {
|
||||||
label_.hide();
|
label_.hide();
|
||||||
label_.set_name("");
|
|
||||||
} else {
|
} else {
|
||||||
label_.set_name("custom-" + name_);
|
|
||||||
auto format = config_["format"] ? config_["format"].asString() : "{}";
|
auto format = config_["format"] ? config_["format"].asString() : "{}";
|
||||||
auto str = fmt::format(format, res.out);
|
auto str = fmt::format(format, res.out);
|
||||||
label_.set_text(str);
|
label_.set_text(str);
|
||||||
|
Loading…
Reference in New Issue
Block a user