From 6dd18ac26e5faca7ca8669855d5e92f594d202f6 Mon Sep 17 00:00:00 2001 From: pupbrained Date: Mon, 17 Mar 2025 13:37:12 -0400 Subject: [PATCH] i am NOT awake enough for this --- src/config/config.h | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) 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"); } }