From e7372afa2f3ebbe49e800bfbc9ba0b9e45c1315a Mon Sep 17 00:00:00 2001 From: Mars Date: Wed, 19 Feb 2025 18:31:40 -0500 Subject: [PATCH] 1. what --- meson.build | 24 +++++++++++++++++------- src/config/config.cpp | 2 +- src/config/weather.cpp | 4 ++-- src/os/windows.cpp | 26 +++++++++++++------------- src/util/types.h | 7 +++++++ 5 files changed, 40 insertions(+), 23 deletions(-) diff --git a/meson.build b/meson.build index de03fe2..b79cc15 100644 --- a/meson.build +++ b/meson.build @@ -79,14 +79,24 @@ foreach file : source_file_names endforeach deps = [ - dependency('fmt'), - dependency('libcurl'), - dependency('tomlplusplus'), - dependency('yyjson'), - dependency('ftxui', modules: ['ftxui::screen', 'ftxui::dom', 'ftxui::component']), - dependency('reflectcpp'), + dependency('fmt', include_type: 'system', static: true), + dependency('libcurl', include_type: 'system', static: true), + dependency('yyjson', include_type: 'system', static: true), + dependency( + 'ftxui', + modules: ['ftxui::screen', 'ftxui::dom', 'ftxui::component'], + include_type: 'system', + static: true, + ), + dependency('reflectcpp', include_type: 'system', static: true), ] +if host_machine.system() == 'windows' + deps += cpp.find_library('tomlplusplus', static: true, dirs: 'C:/msys64/usr/lib') +else + deps += dependency('tomlplusplus', static: true) +endif + if host_machine.system() == 'darwin' deps += dependency('Foundation') deps += dependency('MediaPlayer') @@ -115,4 +125,4 @@ executable( objc_args: objc_args, link_args: link_args, dependencies: deps, -) +) \ No newline at end of file diff --git a/src/config/config.cpp b/src/config/config.cpp index 82aa653..981ffa7 100644 --- a/src/config/config.cpp +++ b/src/config/config.cpp @@ -35,7 +35,7 @@ fn Config::getInstance() -> Config { const Result result = rfl::toml::load(configPath.string()); if (!result) { - ERROR_LOG("Failed to load config file: {}", result.error()->what()); + ERROR_LOG("Failed to load config file: {}", result.error().what()); exit(1); } diff --git a/src/config/weather.cpp b/src/config/weather.cpp index bf0587a..1b2b407 100644 --- a/src/config/weather.cpp +++ b/src/config/weather.cpp @@ -44,7 +44,7 @@ namespace { rfl::Result result = rfl::json::read(content); if (!result) - return std::unexpected(result.error()->what()); + return std::unexpected(result.error().what()); DEBUG_LOG("Successfully read from cache file."); return *result; @@ -117,7 +117,7 @@ namespace { rfl::Result output = rfl::json::read(responseBuffer); if (!output) - return std::unexpected(output.error()->what()); + return std::unexpected(output.error().what()); return *output; } diff --git a/src/os/windows.cpp b/src/os/windows.cpp index bfaa619..449c1e5 100644 --- a/src/os/windows.cpp +++ b/src/os/windows.cpp @@ -74,13 +74,16 @@ namespace { } } -fn GetMemInfo() -> u64 { +fn GetMemInfo() -> expected { u64 mem = 0; - GetPhysicallyInstalledSystemMemory(&mem); + + if (!GetPhysicallyInstalledSystemMemory(&mem)) + return std::unexpected("Failed to get physical system memory."); + return mem * 1024; } -fn GetNowPlaying() -> string { +fn GetNowPlaying() -> expected { using namespace winrt::Windows::Media::Control; using namespace winrt::Windows::Foundation; @@ -102,14 +105,11 @@ fn GetNowPlaying() -> string { } // If we reach this point, there is no current session - return ""; - } catch (const winrt::hresult_error& e) { - ERROR_LOG("Error: {}", to_string(e.message())); - return ""; - } + return std::unexpected(NowPlayingError { NowPlayingCode::NoActivePlayer }); + } catch (const winrt::hresult_error& e) { return std::unexpected(NowPlayingError { e }); } } -fn GetOSVersion() -> string { +fn GetOSVersion() -> expected { string productName = GetRegistryValue(HKEY_LOCAL_MACHINE, R"(SOFTWARE\Microsoft\Windows NT\CurrentVersion)", "ProductName"); @@ -137,7 +137,7 @@ fn GetOSVersion() -> string { return result; } - return ""; + return std::unexpected("Failed to get OS version."); } fn GetHost() -> string { @@ -195,13 +195,13 @@ fn GetWindowManager() -> string { return windowManager; } -fn GetDesktopEnvironment() -> string { +fn GetDesktopEnvironment() -> optional { // Get version information from registry const string buildStr = GetRegistryValue(HKEY_LOCAL_MACHINE, R"(SOFTWARE\Microsoft\Windows NT\CurrentVersion)", "CurrentBuildNumber"); if (buildStr.empty()) - return "Unknown"; + return std::nullopt; try { const i32 build = stoi(buildStr); @@ -234,7 +234,7 @@ fn GetDesktopEnvironment() -> string { // Older versions return "Classic"; - } catch (...) { return "Unknown"; } + } catch (...) { return std::nullopt; } } #endif diff --git a/src/util/types.h b/src/util/types.h index 18c40e0..f8da8fd 100644 --- a/src/util/types.h +++ b/src/util/types.h @@ -3,7 +3,14 @@ #include #include #include + +#ifdef __WIN32__ +#include +#endif + +#ifdef __APPLE__ #include +#endif #ifdef __linux__ #include