From dff976ed0e810202bb7512e78e09a5e2b2cd0e3a Mon Sep 17 00:00:00 2001 From: Mars Date: Tue, 2 Jul 2024 05:54:06 -0400 Subject: [PATCH] osme stuf --- meson.build | 2 +- src/config/config.cpp | 13 +++++++--- src/config/config.h | 4 +-- src/config/weather.cpp | 10 ++++---- src/main.cpp | 57 ++++++++++++++++-------------------------- src/os/macos.cpp | 2 +- src/os/windows.cpp | 4 +++ 7 files changed, 44 insertions(+), 48 deletions(-) diff --git a/meson.build b/meson.build index 2deba65..d3e188a 100644 --- a/meson.build +++ b/meson.build @@ -5,7 +5,7 @@ project( 'cpp_std=c++23', 'default_library=static', 'warning_level=everything', - 'buildtype=debugoptimized' + 'buildtype=release' ] ) diff --git a/src/config/config.cpp b/src/config/config.cpp index 80fcd65..bb366c7 100644 --- a/src/config/config.cpp +++ b/src/config/config.cpp @@ -4,12 +4,18 @@ using rfl::Result; -fn Config::getInstance() -> Config { +inline fn GetConfigPath() -> string { + return getenv( #ifdef __WIN32__ - const string path = string(getenv("LOCALAPPDATA")) + "\\draconis++\\config.toml"; + "LOCALAPPDATA" #else - const string path = string(getenv("HOME")) + "/.config/draconis++/config.toml"; + "HOME" #endif + ); +} + +fn Config::getInstance() -> Config { + const string path = GetConfigPath() + "\\draconis++\\config.toml"; const Result result = rfl::toml::load(path); if (result) @@ -18,4 +24,3 @@ fn Config::getInstance() -> Config { fmt::println("Failed to load config file: {}", result.error().value().what()); return {}; } - diff --git a/src/config/config.h b/src/config/config.h index 9153e9b..f3e5e0b 100644 --- a/src/config/config.h +++ b/src/config/config.h @@ -24,7 +24,7 @@ struct Weather { string api_key; string units; - [[nodiscard]] fn getWeatherInfo() const->WeatherOutput; + [[nodiscard]] fn getWeatherInfo() const -> WeatherOutput; }; struct Config { @@ -32,5 +32,5 @@ struct Config { rfl::Field<"now_playing", NowPlaying> now_playing = NowPlaying(); rfl::Field<"weather", Weather> weather = Weather(); - static fn getInstance()->Config; + static fn getInstance() -> Config; }; diff --git a/src/config/weather.cpp b/src/config/weather.cpp index bda8cc7..3503697 100644 --- a/src/config/weather.cpp +++ b/src/config/weather.cpp @@ -9,7 +9,7 @@ using rfl::Error; using rfl::Result; // Function to read cache from file -fn ReadCacheFromFile()->Result { +fn ReadCacheFromFile() -> Result { #ifdef __WIN32__ const char* tempPath = getenv("TEMP"); const string path = string(tempPath) + "\\weather_cache.json"; @@ -35,7 +35,7 @@ fn ReadCacheFromFile()->Result { } // Function to write cache to file -fn WriteCacheToFile(const WeatherOutput& data)->Result { +fn WriteCacheToFile(const WeatherOutput& data) -> Result { fmt::println("Writing to cache file..."); #ifdef __WIN32__ @@ -56,14 +56,14 @@ fn WriteCacheToFile(const WeatherOutput& data)->Result { return 0; } -fn WriteCallback(void* contents, const size_t size, const size_t nmemb, string* str)->size_t { +fn WriteCallback(void* contents, const size_t size, const size_t nmemb, string* str) -> size_t { const size_t totalSize = size * nmemb; str->append(static_cast(contents), totalSize); return totalSize; } // Function to make API request -fn MakeApiRequest(const string& url)->Result { +fn MakeApiRequest(const string& url) -> Result { fmt::println("Making API request to URL: {}", url); CURL* curl = curl_easy_init(); @@ -91,7 +91,7 @@ fn MakeApiRequest(const string& url)->Result { } // Core function to get weather information -fn Weather::getWeatherInfo() const->WeatherOutput { +fn Weather::getWeatherInfo() const -> WeatherOutput { using namespace std::chrono; // Check if cache is valid diff --git a/src/main.cpp b/src/main.cpp index f87ee1d..71f6f01 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1,7 +1,6 @@ #include #include #include -#include #include "config/config.h" #include "os/os.h" @@ -46,53 +45,41 @@ fn GetDate() -> string { } fn main() -> i32 { - using std::future; + const Config& config = Config::getInstance(); - const Config config = Config::getInstance(); + // Fetching weather information + auto weatherInfo = config.weather.get().getWeatherInfo(); - auto weatherFuture = - std::async(std::launch::async, [&config]() { return config.weather.get().getWeatherInfo(); }); + // Fetching OS version + std::string osVersion = GetOSVersion(); - auto osVersionFuture = std::async(std::launch::async, GetOSVersion); - auto nowPlayingEnabledFuture = - std::async(std::launch::async, [&config]() { return config.now_playing.get().enabled; }); + // Checking if now playing is enabled + bool nowPlayingEnabled = config.now_playing.get().enabled; - future dateFuture = std::async(std::launch::async, GetDate); - future memInfoFuture = std::async(std::launch::async, GetMemInfo); + // Fetching current date + std::string date = GetDate(); - const bool nowPlayingEnabled = nowPlayingEnabledFuture.get(); - const string version = osVersionFuture.get(); - const string date = dateFuture.get(); - const string name = config.general.get().name.get(); - const u64 mem = memInfoFuture.get(); + // Fetching memory info + u64 memInfo = GetMemInfo(); + + const std::string& name = config.general.get().name.get(); fmt::println("Hello {}!", name); fmt::println("Today is: {}", date); - fmt::println("Installed RAM: {:.2f}", BytesToGiB(mem)); - fmt::println("{}", version); + fmt::println("Installed RAM: {:.2f}", BytesToGiB(memInfo)); + fmt::println("{}", osVersion); if (config.weather.get().enabled) { - const auto - [clouds, - tz, - visibility, - main, - coords, - rain, - snow, - base, - townName, - weather, - sys, - cod, - dt, - id, - wind] = weatherFuture.get(); - const i64 temp = std::lround(main.temp); + const auto& [clouds, tz, visibility, main, coords, rain, snow, base, townName, weather, sys, cod, dt, id, wind] = + weatherInfo; + i64 temp = std::lround(main.temp); fmt::println("It is {}°F in {}", temp, townName); } - if (nowPlayingEnabled) + if (nowPlayingEnabled) { fmt::println("{}", GetNowPlaying()); + } + + return 0; } diff --git a/src/os/macos.cpp b/src/os/macos.cpp index f9c8e3a..c9bb246 100644 --- a/src/os/macos.cpp +++ b/src/os/macos.cpp @@ -21,6 +21,6 @@ fn GetNowPlaying() -> string { return "No song playing"; } -fn GetOSVersion() -> const char* { return GetMacOSVersion(); }; +fn GetOSVersion() -> const char* { return GetMacOSVersion(); } #endif diff --git a/src/os/windows.cpp b/src/os/windows.cpp index 20618ea..857e530 100644 --- a/src/os/windows.cpp +++ b/src/os/windows.cpp @@ -1,3 +1,5 @@ +#ifdef __WIN32__ + #include #include #include @@ -105,3 +107,5 @@ fn GetOSVersion() -> string { return ""; } + +#endif