diff --git a/include/util/hosts_check.hpp b/include/util/hosts_check.hpp index a927f535..4179f633 100644 --- a/include/util/hosts_check.hpp +++ b/include/util/hosts_check.hpp @@ -1,7 +1,6 @@ #pragma once #include -#include namespace waybar::util { bool valid_host(const Json::Value& config); diff --git a/src/bar.cpp b/src/bar.cpp index 04ad8362..4b619de2 100644 --- a/src/bar.cpp +++ b/src/bar.cpp @@ -3,6 +3,7 @@ #include #include +#include #include #include "client.hpp" @@ -11,7 +12,6 @@ #include "util/enum.hpp" #include "util/hosts_check.hpp" #include "util/kill_signal.hpp" -#include "util/hosts_check.hpp" #ifdef HAVE_SWAY #include "modules/sway/bar.hpp" @@ -534,19 +534,9 @@ void waybar::Bar::getModules(const Factory& factory, const std::string& pos, try { auto ref = name.asString(); - const Json::Value* module_config = nullptr; - if (config.isMember(ref)) { - module_config = &config[ref]; - } else { - auto hash_pos = ref.find('#'); - if (hash_pos != std::string::npos) { - std::string ref_base = ref.substr(0, hash_pos); - if (config.isMember(ref_base)) { - module_config = &config[ref_base]; - } - } + if (config[ref].isMember("hosts") && !waybar::util::valid_host(config[ref])) { + continue; } - if ((module_config != nullptr) && !waybar::util::valid_host(*module_config)) continue; AModule* module; diff --git a/src/util/hosts_check.cpp b/src/util/hosts_check.cpp index 27260cd3..1769dd78 100644 --- a/src/util/hosts_check.cpp +++ b/src/util/hosts_check.cpp @@ -1,18 +1,16 @@ -#include - #include "util/hosts_check.hpp" +#include +#include + namespace waybar::util { -// replaces ``<>&"'`` with their encoded counterparts bool valid_host(const Json::Value& config) { if (config.isMember("hosts") && config["hosts"].isArray()) { - auto hostname = Glib::get_host_name(); - for (const auto& host : config["hosts"]) { - if (host.asString() == hostname) { - return true; - } - } - return false; + const auto hostname = Glib::get_host_name(); + + if (!std::ranges::any_of(config["hosts"].begin(), config["hosts"].end(), + [&](const auto& h) { return h.asString() == hostname; })) + return false; } return true; }