Merge pull request #3241 from rtgiskard/master
temperature: allow hwmon-path-abs as array
This commit is contained in:
commit
ac2fa9870f
|
@ -25,6 +25,7 @@ Addressed by *temperature*
|
||||||
*hwmon-path-abs*: ++
|
*hwmon-path-abs*: ++
|
||||||
typeof: string ++
|
typeof: string ++
|
||||||
The path of the hwmon-directory of the device, e.g. */sys/devices/pci0000:00/0000:00:18.3/hwmon*. (Note that the subdirectory *hwmon/hwmon#*, where *#* is a number is not part of the path!) Has to be used together with *input-filename*.
|
The path of the hwmon-directory of the device, e.g. */sys/devices/pci0000:00/0000:00:18.3/hwmon*. (Note that the subdirectory *hwmon/hwmon#*, where *#* is a number is not part of the path!) Has to be used together with *input-filename*.
|
||||||
|
This can also be an array of strings, for which, it just works like *hwmon-path*.
|
||||||
|
|
||||||
*input-filename*: ++
|
*input-filename*: ++
|
||||||
typeof: string ++
|
typeof: string ++
|
||||||
|
|
|
@ -1,6 +1,9 @@
|
||||||
#include "modules/temperature.hpp"
|
#include "modules/temperature.hpp"
|
||||||
|
|
||||||
|
#include <bits/ranges_algo.h>
|
||||||
|
|
||||||
#include <filesystem>
|
#include <filesystem>
|
||||||
|
#include <string>
|
||||||
|
|
||||||
#if defined(__FreeBSD__)
|
#if defined(__FreeBSD__)
|
||||||
#include <sys/sysctl.h>
|
#include <sys/sysctl.h>
|
||||||
|
@ -11,26 +14,32 @@ waybar::modules::Temperature::Temperature(const std::string& id, const Json::Val
|
||||||
#if defined(__FreeBSD__)
|
#if defined(__FreeBSD__)
|
||||||
// FreeBSD uses sysctlbyname instead of read from a file
|
// FreeBSD uses sysctlbyname instead of read from a file
|
||||||
#else
|
#else
|
||||||
auto& hwmon_path = config_["hwmon-path"];
|
auto traverseAsArray = [](const Json::Value& value, auto&& check_set_path) {
|
||||||
if (hwmon_path.isString()) {
|
if (value.isString())
|
||||||
file_path_ = hwmon_path.asString();
|
check_set_path(value.asString());
|
||||||
} else if (hwmon_path.isArray()) {
|
else if (value.isArray())
|
||||||
|
for (const auto& item : value)
|
||||||
|
if (check_set_path(item.asString())) break;
|
||||||
|
};
|
||||||
|
|
||||||
// if hwmon_path is an array, loop to find first valid item
|
// if hwmon_path is an array, loop to find first valid item
|
||||||
for (auto& item : hwmon_path) {
|
traverseAsArray(config_["hwmon-path"], [this](const std::string& path) {
|
||||||
auto path = item.asString();
|
if (!std::filesystem::exists(path)) return false;
|
||||||
if (std::filesystem::exists(path)) {
|
|
||||||
file_path_ = path;
|
file_path_ = path;
|
||||||
break;
|
return true;
|
||||||
}
|
});
|
||||||
}
|
|
||||||
} else if (config_["hwmon-path-abs"].isString() && config_["input-filename"].isString()) {
|
if (file_path_.empty() && config_["input-filename"].isString()) {
|
||||||
for (const auto& hwmon :
|
// fallback to hwmon_paths-abs
|
||||||
std::filesystem::directory_iterator(config_["hwmon-path-abs"].asString())) {
|
traverseAsArray(config_["hwmon-path-abs"], [this](const std::string& path) {
|
||||||
if (hwmon.path().filename().string().starts_with("hwmon")) {
|
if (!std::filesystem::is_directory(path)) return false;
|
||||||
|
return std::ranges::any_of(
|
||||||
|
std::filesystem::directory_iterator(path), [this](const auto& hwmon) {
|
||||||
|
if (!hwmon.path().filename().string().starts_with("hwmon")) return false;
|
||||||
file_path_ = hwmon.path().string() + "/" + config_["input-filename"].asString();
|
file_path_ = hwmon.path().string() + "/" + config_["input-filename"].asString();
|
||||||
break;
|
return true;
|
||||||
}
|
});
|
||||||
}
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
if (file_path_.empty()) {
|
if (file_path_.empty()) {
|
||||||
|
|
Loading…
Reference in New Issue