This commit is contained in:
Mars 2024-06-22 14:47:59 -04:00
parent ab097e2370
commit 875b9c7dd1
5 changed files with 23 additions and 17 deletions

View file

@ -1,12 +1,20 @@
#include <fmt/core.h>
#include "config.h" #include "config.h"
fn Config::getInstance()->const Config& { using rfl::Result;
fn Config::getInstance()->Config {
#ifdef __WIN32__ #ifdef __WIN32__
const string path = string(getenv("LOCALAPPDATA")) + "\\draconis++\\config.toml"; const string path = string(getenv("LOCALAPPDATA")) + "\\draconis++\\config.toml";
#else #else
const string path = string(getenv("HOME")) + "/.config/draconis++/config.toml"; const string path = string(getenv("HOME")) + "/.config/draconis++/config.toml";
#endif #endif
// ReSharper disable once CppDFAMemoryLeak const Result<Config> result = rfl::toml::load<Config>(path);
static const Config* INSTANCE = new Config(rfl::toml::load<Config>(path).value());
return *INSTANCE; if (result)
return result.value();
fmt::println("Failed to load config file: {}", result.error().value().what());
return {};
} }

View file

@ -30,5 +30,5 @@ struct Config {
rfl::Field<"now_playing", NowPlaying> now_playing = NowPlaying(); rfl::Field<"now_playing", NowPlaying> now_playing = NowPlaying();
rfl::Field<"weather", Weather> weather = Weather(); rfl::Field<"weather", Weather> weather = Weather();
static fn getInstance() -> const Config&; static fn getInstance()->Config;
}; };

View file

@ -6,7 +6,6 @@
#include "config.h" #include "config.h"
using rfl::Error; using rfl::Error;
using rfl::Nothing;
using rfl::Result; using rfl::Result;
// Function to read cache from file // Function to read cache from file

View file

@ -48,7 +48,7 @@ fn GetDate()->string {
fn main()->i32 { fn main()->i32 {
using std::future; using std::future;
const Config& config = Config::getInstance(); const Config config = Config::getInstance();
auto weatherFuture = auto weatherFuture =
std::async(std::launch::async, [&config]() { return config.weather.get().getWeatherInfo(); }); std::async(std::launch::async, [&config]() { return config.weather.get().getWeatherInfo(); });

View file

@ -27,9 +27,7 @@ fn GetNowPlaying()->string {
if (const Session currentSession = sessionManager.GetCurrentSession()) { if (const Session currentSession = sessionManager.GetCurrentSession()) {
// Try to get the media properties asynchronously // Try to get the media properties asynchronously
const IAsyncOperation<MediaProperties> mediaPropertiesOp = const MediaProperties mediaProperties = currentSession.TryGetMediaPropertiesAsync().get();
currentSession.TryGetMediaPropertiesAsync();
const MediaProperties mediaProperties = mediaPropertiesOp.get();
// Convert the hstring title to string // Convert the hstring title to string
return to_string(mediaProperties.Title()); return to_string(mediaProperties.Title());
@ -46,7 +44,8 @@ fn GetRegistryValue(const HKEY& hKey, const string& subKey, const string& valueN
return ""; return "";
DWORD dataSize = 0; DWORD dataSize = 0;
if (RegQueryValueExA(key, valueName.c_str(), nullptr, nullptr, nullptr, &dataSize) != ERROR_SUCCESS) { if (RegQueryValueExA(key, valueName.c_str(), nullptr, nullptr, nullptr, &dataSize) !=
ERROR_SUCCESS) {
RegCloseKey(key); RegCloseKey(key);
return ""; return "";
} }