osme stuf

This commit is contained in:
Mars 2024-07-02 05:54:06 -04:00
parent 4f039f9c79
commit dff976ed0e
7 changed files with 44 additions and 48 deletions

View file

@ -5,7 +5,7 @@ project(
'cpp_std=c++23',
'default_library=static',
'warning_level=everything',
'buildtype=debugoptimized'
'buildtype=release'
]
)

View file

@ -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 {};
}

View file

@ -24,7 +24,7 @@ struct Weather {
string api_key;
string units;
[[nodiscard]] fn getWeatherInfo() const->WeatherOutput;
[[nodiscard]] fn getWeatherInfo() const -> WeatherOutput;
};
struct Config {
@ -32,5 +32,5 @@ struct Config {
rfl::Field<"now_playing", NowPlaying> now_playing = NowPlaying();
rfl::Field<"weather", Weather> weather = Weather();
static fn getInstance()->Config;
static fn getInstance() -> Config;
};

View file

@ -9,7 +9,7 @@ using rfl::Error;
using rfl::Result;
// Function to read cache from file
fn ReadCacheFromFile()->Result<WeatherOutput> {
fn ReadCacheFromFile() -> Result<WeatherOutput> {
#ifdef __WIN32__
const char* tempPath = getenv("TEMP");
const string path = string(tempPath) + "\\weather_cache.json";
@ -35,7 +35,7 @@ fn ReadCacheFromFile()->Result<WeatherOutput> {
}
// Function to write cache to file
fn WriteCacheToFile(const WeatherOutput& data)->Result<u8> {
fn WriteCacheToFile(const WeatherOutput& data) -> Result<u8> {
fmt::println("Writing to cache file...");
#ifdef __WIN32__
@ -56,14 +56,14 @@ fn WriteCacheToFile(const WeatherOutput& data)->Result<u8> {
return 0;
}
fn WriteCallback(void* contents, const size_t size, const size_t nmemb, string* str)->size_t {
fn WriteCallback(void* contents, const size_t size, const size_t nmemb, string* str) -> size_t {
const size_t totalSize = size * nmemb;
str->append(static_cast<char*>(contents), totalSize);
return totalSize;
}
// Function to make API request
fn MakeApiRequest(const string& url)->Result<WeatherOutput> {
fn MakeApiRequest(const string& url) -> Result<WeatherOutput> {
fmt::println("Making API request to URL: {}", url);
CURL* curl = curl_easy_init();
@ -91,7 +91,7 @@ fn MakeApiRequest(const string& url)->Result<WeatherOutput> {
}
// Core function to get weather information
fn Weather::getWeatherInfo() const->WeatherOutput {
fn Weather::getWeatherInfo() const -> WeatherOutput {
using namespace std::chrono;
// Check if cache is valid

View file

@ -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;
}

View file

@ -21,6 +21,6 @@ fn GetNowPlaying() -> string {
return "No song playing";
}
fn GetOSVersion() -> const char* { return GetMacOSVersion(); };
fn GetOSVersion() -> const char* { return GetMacOSVersion(); }
#endif

View file

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