Simplified logic
This commit is contained in:
@@ -1,7 +1,6 @@
|
||||
#pragma once
|
||||
|
||||
#include <json/value.h>
|
||||
#include <string>
|
||||
|
||||
namespace waybar::util {
|
||||
bool valid_host(const Json::Value& config);
|
||||
|
||||
+3
-13
@@ -3,6 +3,7 @@
|
||||
#include <gtk-layer-shell.h>
|
||||
#include <spdlog/spdlog.h>
|
||||
|
||||
#include <ostream>
|
||||
#include <type_traits>
|
||||
|
||||
#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;
|
||||
|
||||
|
||||
@@ -1,18 +1,16 @@
|
||||
#include <glibmm/miscutils.h>
|
||||
|
||||
#include "util/hosts_check.hpp"
|
||||
|
||||
#include <glibmm/miscutils.h>
|
||||
#include <json/config.h>
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user