This commit is contained in:
Mars 2025-04-19 23:49:55 -04:00
commit a5cdc09156
5 changed files with 33 additions and 16 deletions

View file

@ -33,16 +33,16 @@ namespace {
possiblePaths.push_back(fs::path(".") / "config.toml");
#else
// Unix/Linux paths in order of preference
if (auto result = getEnv("XDG_CONFIG_HOME"); result)
possiblePaths.push_back(fs::path(*result) / "draconis++" / "config.toml");
if (auto result = GetEnv("XDG_CONFIG_HOME"); result)
possiblePaths.emplace_back(fs::path(*result) / "draconis++" / "config.toml");
if (auto result = getEnv("HOME"); result) {
possiblePaths.push_back(fs::path(*result) / ".config" / "draconis++" / "config.toml");
possiblePaths.push_back(fs::path(*result) / ".draconis++" / "config.toml");
if (auto result = GetEnv("HOME"); result) {
possiblePaths.emplace_back(fs::path(*result) / ".config" / "draconis++" / "config.toml");
possiblePaths.emplace_back(fs::path(*result) / ".draconis++" / "config.toml");
}
// System-wide config
possiblePaths.push_back(fs::path("/etc/draconis++/config.toml"));
possiblePaths.emplace_back("/etc/draconis++/config.toml");
#endif
// Check if any of these configs already exist

View file

@ -60,9 +60,23 @@ struct Weather {
static fn fromToml(const toml::table& tbl) -> Weather {
Weather weather;
weather.enabled = tbl["enabled"].value<bool>().value_or(false);
weather.show_town_name = tbl["show_town_name"].value<bool>().value_or(false);
weather.api_key = tbl["api_key"].value<string>().value_or("");
weather.enabled = tbl["enabled"].value_or<bool>(false);
if (auto apiKey = tbl["api_key"].value<string>()) {
const string& keyVal = apiKey.value();
if (keyVal.empty())
weather.enabled = false;
weather.api_key = keyVal;
} else {
weather.enabled = false;
}
if (!weather.enabled)
return weather;
weather.show_town_name = tbl["show_town_name"].value_or<bool>(false);
weather.units = tbl["units"].value<string>().value_or("metric");
if (const toml::node_view<const toml::node> location = tbl["location"]) {
@ -74,6 +88,8 @@ struct Weather {
coords.lat = coord->get("lat")->value<double>().value();
coords.lon = coord->get("lon")->value<double>().value();
weather.location = coords;
} else {
throw std::runtime_error("Invalid location type");
}
}

View file

@ -8,6 +8,7 @@
#include <fmt/color.h>
#include <fmt/format.h>
#include <source_location>
#include <utility>
#include "types.h"

View file

@ -2,10 +2,10 @@
#include <cstddef>
#include <cstdint>
#include <expected>
#include <string>
#ifdef _WIN32
#include <expected>
// ReSharper disable once CppUnusedIncludeDirective
#include <guiddef.h>
#include <variant>