bleh
This commit is contained in:
parent
dff976ed0e
commit
3ebbb2b3ec
6 changed files with 58 additions and 52 deletions
|
@ -1,26 +1,43 @@
|
|||
#include <cstdlib>
|
||||
#include <filesystem>
|
||||
#include <fmt/core.h>
|
||||
#include <string>
|
||||
|
||||
#include "config.h"
|
||||
|
||||
using rfl::Result;
|
||||
namespace fs = std::filesystem;
|
||||
|
||||
inline fn GetConfigPath() -> string {
|
||||
return getenv(
|
||||
#ifdef __WIN32__
|
||||
"LOCALAPPDATA"
|
||||
inline fn GetConfigPath() -> std::string {
|
||||
#ifdef _WIN32
|
||||
const char* localAppData = std::getenv("LOCALAPPDATA");
|
||||
|
||||
if (!localAppData)
|
||||
throw std::runtime_error("Environment variable LOCALAPPDATA is not set");
|
||||
|
||||
return localAppData;
|
||||
#else
|
||||
"HOME"
|
||||
const char* home = std::getenv("HOME");
|
||||
|
||||
if (!home)
|
||||
throw std::runtime_error("Environment variable HOME is not set");
|
||||
|
||||
return std::string(home) + "/.config";
|
||||
#endif
|
||||
);
|
||||
}
|
||||
|
||||
fn Config::getInstance() -> Config {
|
||||
const string path = GetConfigPath() + "\\draconis++\\config.toml";
|
||||
const Result<Config> result = rfl::toml::load<Config>(path);
|
||||
try {
|
||||
fs::path configPath = GetConfigPath();
|
||||
configPath /= "draconis++/config.toml";
|
||||
|
||||
if (result)
|
||||
return result.value();
|
||||
const Result<Config> result = rfl::toml::load<Config>(configPath.string());
|
||||
|
||||
if (result)
|
||||
return result.value();
|
||||
|
||||
fmt::println("Failed to load config file: {}", result.error().value().what());
|
||||
} catch (const std::exception& e) { fmt::println("Error getting config path: {}", e.what()); }
|
||||
|
||||
fmt::println("Failed to load config file: {}", result.error().value().what());
|
||||
return {};
|
||||
}
|
||||
|
|
15
src/main.cpp
15
src/main.cpp
|
@ -48,7 +48,8 @@ fn main() -> i32 {
|
|||
const Config& config = Config::getInstance();
|
||||
|
||||
// Fetching weather information
|
||||
auto weatherInfo = config.weather.get().getWeatherInfo();
|
||||
auto weather = config.weather.get();
|
||||
WeatherOutput weatherInfo = weather.getWeatherInfo();
|
||||
|
||||
// Fetching OS version
|
||||
std::string osVersion = GetOSVersion();
|
||||
|
@ -69,17 +70,11 @@ fn main() -> i32 {
|
|||
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] =
|
||||
weatherInfo;
|
||||
i64 temp = std::lround(main.temp);
|
||||
if (weather.enabled)
|
||||
fmt::println("It is {}°F in {}", std::lround(weatherInfo.main.temp), weatherInfo.name);
|
||||
|
||||
fmt::println("It is {}°F in {}", temp, townName);
|
||||
}
|
||||
|
||||
if (nowPlayingEnabled) {
|
||||
if (nowPlayingEnabled)
|
||||
fmt::println("{}", GetNowPlaying());
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -21,6 +21,6 @@ fn GetNowPlaying() -> string {
|
|||
return "No song playing";
|
||||
}
|
||||
|
||||
fn GetOSVersion() -> const char* { return GetMacOSVersion(); }
|
||||
fn GetOSVersion() -> string { return GetMacOSVersion(); }
|
||||
|
||||
#endif
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue