osme stuf
This commit is contained in:
parent
4f039f9c79
commit
dff976ed0e
|
@ -5,7 +5,7 @@ project(
|
|||
'cpp_std=c++23',
|
||||
'default_library=static',
|
||||
'warning_level=everything',
|
||||
'buildtype=debugoptimized'
|
||||
'buildtype=release'
|
||||
]
|
||||
)
|
||||
|
||||
|
|
|
@ -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<Config> result = rfl::toml::load<Config>(path);
|
||||
|
||||
if (result)
|
||||
|
@ -18,4 +24,3 @@ fn Config::getInstance() -> Config {
|
|||
fmt::println("Failed to load config file: {}", result.error().value().what());
|
||||
return {};
|
||||
}
|
||||
|
||||
|
|
57
src/main.cpp
57
src/main.cpp
|
@ -1,7 +1,6 @@
|
|||
#include <ctime>
|
||||
#include <fmt/chrono.h>
|
||||
#include <fmt/core.h>
|
||||
#include <future>
|
||||
|
||||
#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<string> dateFuture = std::async(std::launch::async, GetDate);
|
||||
future<u64> 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;
|
||||
}
|
||||
|
|
|
@ -21,6 +21,6 @@ fn GetNowPlaying() -> string {
|
|||
return "No song playing";
|
||||
}
|
||||
|
||||
fn GetOSVersion() -> const char* { return GetMacOSVersion(); };
|
||||
fn GetOSVersion() -> const char* { return GetMacOSVersion(); }
|
||||
|
||||
#endif
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
#ifdef __WIN32__
|
||||
|
||||
#include <exception>
|
||||
#include <windows.h>
|
||||
#include <winrt/Windows.Foundation.h>
|
||||
|
@ -105,3 +107,5 @@ fn GetOSVersion() -> string {
|
|||
|
||||
return "";
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
Loading…
Reference in a new issue