Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit f824ae9

Browse files
author
Arkoniak
committed
Relative paths in included configs
1 parent 0776e69 commit f824ae9

File tree

4 files changed

+27
-5
lines changed

4 files changed

+27
-5
lines changed

include/config.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ class Config {
3535
void setupConfig(Json::Value &dst, const std::string &config_file, int depth);
3636
void resolveConfigIncludes(Json::Value &config, int depth);
3737
void mergeConfig(Json::Value &a_config_, Json::Value &b_config_);
38+
std::optional<std::string> findIncludePath(const std::string name);
3839

3940
std::string config_file_;
4041

src/bar.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -496,7 +496,11 @@ void waybar::Bar::getModules(const Factory& factory, const std::string& pos,
496496
auto vertical = (group != nullptr ? group->getBox().get_orientation()
497497
: box_.get_orientation()) == Gtk::ORIENTATION_VERTICAL;
498498

499-
auto* group_module = new waybar::Group(id_name, class_name, config[ref], vertical);
499+
auto group_config = config[ref];
500+
if (group_config["modules"].isNull()) {
501+
spdlog::warn("Group definition '{}' has not been found, group will be hidden", ref);
502+
}
503+
auto* group_module = new waybar::Group(id_name, class_name, group_config, vertical);
500504
getModules(factory, ref, group_module);
501505
module = group_module;
502506
} else {

src/config.cpp

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -89,19 +89,33 @@ void Config::setupConfig(Json::Value &dst, const std::string &config_file, int d
8989
mergeConfig(dst, tmp_config);
9090
}
9191

92+
std::optional<std::string> Config::findIncludePath(const std::string name) {
93+
auto match1 = tryExpandPath(name, "");
94+
if (!match1.empty()) {
95+
return match1.front();
96+
}
97+
return findConfigPath({name});
98+
}
99+
92100
void Config::resolveConfigIncludes(Json::Value &config, int depth) {
93101
Json::Value includes = config["include"];
94102
if (includes.isArray()) {
95103
for (const auto &include : includes) {
96104
spdlog::info("Including resource file: {}", include.asString());
97-
for (const auto &match : tryExpandPath(include.asString(), "")) {
98-
setupConfig(config, match, depth + 1);
105+
auto match = findIncludePath(include.asString());
106+
if (match.has_value()) {
107+
setupConfig(config, match.value(), depth + 1);
108+
} else {
109+
spdlog::warn("Unable to find resource file: {}", include.asString());
99110
}
100111
}
101112
} else if (includes.isString()) {
102113
spdlog::info("Including resource file: {}", includes.asString());
103-
for (const auto &match : tryExpandPath(includes.asString(), "")) {
104-
setupConfig(config, match, depth + 1);
114+
auto match = findIncludePath(includes.asString());
115+
if (match.has_value()) {
116+
setupConfig(config, match.value(), depth + 1);
117+
} else {
118+
spdlog::warn("Unable to find resource file: {}", includes.asString());
105119
}
106120
}
107121
}

src/modules/custom.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@ waybar::modules::Custom::Custom(const std::string& name, const std::string& id,
1414
percentage_(0),
1515
fp_(nullptr),
1616
pid_(-1) {
17+
if (config.isNull()) {
18+
spdlog::warn("There is no configuration for 'custom/{}', element will be hidden", name);
19+
}
1720
dp.emit();
1821
if (!config_["signal"].empty() && config_["interval"].empty() &&
1922
config_["restart-interval"].empty()) {

0 commit comments

Comments
 (0)