support multiple items in hwmon-path of temperature module

So user can share configuration file among different machines with different hardware
configurations.
This commit is contained in:
yangyingchao
2023-06-17 11:33:14 +08:00
parent d367b7e1d6
commit e403c3b71b
2 changed files with 15 additions and 3 deletions

View File

@ -11,8 +11,18 @@ waybar::modules::Temperature::Temperature(const std::string& id, const Json::Val
#if defined(__FreeBSD__)
// try to read sysctl?
#else
if (config_["hwmon-path"].isString()) {
file_path_ = config_["hwmon-path"].asString();
auto& hwmon_path = config_["hwmon-path"];
if (hwmon_path.isString()) {
file_path_ = hwmon_path.asString();
} else if (hwmon_path.isArray()) {
// if hwmon_path is an array, loop to find first valid item
for (auto& item : hwmon_path) {
auto path = item.asString();
if (std::filesystem::exists(path)) {
file_path_ = path;
break;
}
}
} else if (config_["hwmon-path-abs"].isString() && config_["input-filename"].isString()) {
file_path_ = (*std::filesystem::directory_iterator(config_["hwmon-path-abs"].asString()))
.path()