diff --git a/flake.lock b/flake.lock index d20ca05..33ac666 100644 --- a/flake.lock +++ b/flake.lock @@ -2,11 +2,11 @@ "nodes": { "nixpkgs": { "locked": { - "lastModified": 1741678040, - "narHash": "sha256-rmBsz7BBcDwfvDkxnKHmolKceGJrr0nyz5PQYZg0kMk=", + "lastModified": 1744536153, + "narHash": "sha256-awS2zRgF4uTwrOKwwiJcByDzDOdo3Q1rPZbiHQg/N38=", "owner": "NixOS", "repo": "nixpkgs", - "rev": "3ee8818da146871cd570b164fc4f438f78479a50", + "rev": "18dd725c29603f582cf1900e0d25f9f1063dbf11", "type": "github" }, "original": { @@ -59,11 +59,11 @@ "nixpkgs": "nixpkgs_2" }, "locked": { - "lastModified": 1739829690, - "narHash": "sha256-mL1szCeIsjh6Khn3nH2cYtwO5YXG6gBiTw1A30iGeDU=", + "lastModified": 1743748085, + "narHash": "sha256-uhjnlaVTWo5iD3LXics1rp9gaKgDRQj6660+gbUU3cE=", "owner": "numtide", "repo": "treefmt-nix", - "rev": "3d0579f5cc93436052d94b73925b48973a104204", + "rev": "815e4121d6a5d504c0f96e5be2dd7f871e4fd99d", "type": "github" }, "original": { diff --git a/src/config/config.cpp b/src/config/config.cpp index 9c3a3b2..bed2d87 100644 --- a/src/config/config.cpp +++ b/src/config/config.cpp @@ -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 diff --git a/src/config/config.h b/src/config/config.h index 5b44c7d..6826edb 100644 --- a/src/config/config.h +++ b/src/config/config.h @@ -60,9 +60,23 @@ struct Weather { static fn fromToml(const toml::table& tbl) -> Weather { Weather weather; - weather.enabled = tbl["enabled"].value().value_or(false); - weather.show_town_name = tbl["show_town_name"].value().value_or(false); - weather.api_key = tbl["api_key"].value().value_or(""); + weather.enabled = tbl["enabled"].value_or(false); + + if (auto apiKey = tbl["api_key"].value()) { + 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(false); weather.units = tbl["units"].value().value_or("metric"); if (const toml::node_view location = tbl["location"]) { @@ -74,6 +88,8 @@ struct Weather { coords.lat = coord->get("lat")->value().value(); coords.lon = coord->get("lon")->value().value(); weather.location = coords; + } else { + throw std::runtime_error("Invalid location type"); } } diff --git a/src/util/macros.h b/src/util/macros.h index 96a6b35..5033b8e 100644 --- a/src/util/macros.h +++ b/src/util/macros.h @@ -8,6 +8,7 @@ #include #include #include +#include #include "types.h" diff --git a/src/util/types.h b/src/util/types.h index e9d5314..1b99c91 100644 --- a/src/util/types.h +++ b/src/util/types.h @@ -2,10 +2,10 @@ #include #include +#include #include #ifdef _WIN32 -#include // ReSharper disable once CppUnusedIncludeDirective #include #include