Simplified logic
This commit is contained in:
@@ -1,7 +1,6 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <json/value.h>
|
#include <json/value.h>
|
||||||
#include <string>
|
|
||||||
|
|
||||||
namespace waybar::util {
|
namespace waybar::util {
|
||||||
bool valid_host(const Json::Value& config);
|
bool valid_host(const Json::Value& config);
|
||||||
|
|||||||
+3
-13
@@ -3,6 +3,7 @@
|
|||||||
#include <gtk-layer-shell.h>
|
#include <gtk-layer-shell.h>
|
||||||
#include <spdlog/spdlog.h>
|
#include <spdlog/spdlog.h>
|
||||||
|
|
||||||
|
#include <ostream>
|
||||||
#include <type_traits>
|
#include <type_traits>
|
||||||
|
|
||||||
#include "client.hpp"
|
#include "client.hpp"
|
||||||
@@ -11,7 +12,6 @@
|
|||||||
#include "util/enum.hpp"
|
#include "util/enum.hpp"
|
||||||
#include "util/hosts_check.hpp"
|
#include "util/hosts_check.hpp"
|
||||||
#include "util/kill_signal.hpp"
|
#include "util/kill_signal.hpp"
|
||||||
#include "util/hosts_check.hpp"
|
|
||||||
|
|
||||||
#ifdef HAVE_SWAY
|
#ifdef HAVE_SWAY
|
||||||
#include "modules/sway/bar.hpp"
|
#include "modules/sway/bar.hpp"
|
||||||
@@ -534,19 +534,9 @@ void waybar::Bar::getModules(const Factory& factory, const std::string& pos,
|
|||||||
try {
|
try {
|
||||||
auto ref = name.asString();
|
auto ref = name.asString();
|
||||||
|
|
||||||
const Json::Value* module_config = nullptr;
|
if (config[ref].isMember("hosts") && !waybar::util::valid_host(config[ref])) {
|
||||||
if (config.isMember(ref)) {
|
continue;
|
||||||
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 ((module_config != nullptr) && !waybar::util::valid_host(*module_config)) continue;
|
|
||||||
|
|
||||||
AModule* module;
|
AModule* module;
|
||||||
|
|
||||||
|
|||||||
@@ -1,17 +1,15 @@
|
|||||||
#include <glibmm/miscutils.h>
|
|
||||||
|
|
||||||
#include "util/hosts_check.hpp"
|
#include "util/hosts_check.hpp"
|
||||||
|
|
||||||
|
#include <glibmm/miscutils.h>
|
||||||
|
#include <json/config.h>
|
||||||
|
|
||||||
namespace waybar::util {
|
namespace waybar::util {
|
||||||
// replaces ``<>&"'`` with their encoded counterparts
|
|
||||||
bool valid_host(const Json::Value& config) {
|
bool valid_host(const Json::Value& config) {
|
||||||
if (config.isMember("hosts") && config["hosts"].isArray()) {
|
if (config.isMember("hosts") && config["hosts"].isArray()) {
|
||||||
auto hostname = Glib::get_host_name();
|
const auto hostname = Glib::get_host_name();
|
||||||
for (const auto& host : config["hosts"]) {
|
|
||||||
if (host.asString() == hostname) {
|
if (!std::ranges::any_of(config["hosts"].begin(), config["hosts"].end(),
|
||||||
return true;
|
[&](const auto& h) { return h.asString() == hostname; }))
|
||||||
}
|
|
||||||
}
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
|
|||||||
Reference in New Issue
Block a user