This commit is contained in:
Mars 2025-02-19 18:31:40 -05:00
parent 9b155fd8db
commit e7372afa2f
5 changed files with 40 additions and 23 deletions

View file

@ -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,
)
)

View file

@ -35,7 +35,7 @@ fn Config::getInstance() -> Config {
const Result<Config> result = rfl::toml::load<Config>(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);
}

View file

@ -44,7 +44,7 @@ namespace {
rfl::Result<WeatherOutput> result = rfl::json::read<WeatherOutput>(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<WeatherOutput> output = rfl::json::read<WeatherOutput>(responseBuffer);
if (!output)
return std::unexpected(output.error()->what());
return std::unexpected(output.error().what());
return *output;
}

View file

@ -74,13 +74,16 @@ namespace {
}
}
fn GetMemInfo() -> u64 {
fn GetMemInfo() -> expected<u64, string> {
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<string, NowPlayingError> {
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, string> {
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<string> {
// 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

View file

@ -3,7 +3,14 @@
#include <cstddef>
#include <cstdint>
#include <string>
#ifdef __WIN32__
#include <winrt/base.h>
#endif
#ifdef __APPLE__
#include <variant>
#endif
#ifdef __linux__
#include <sdbus-c++/sdbus-c++.h>