fixed some more stuff
This commit is contained in:
parent
3cf13c45bc
commit
164a68c5ee
|
@ -43,7 +43,7 @@ foreach file : source_file_names
|
|||
endforeach
|
||||
|
||||
windows_sdk_lib_dir = 'C:/Program Files (x86)/Windows Kits/10/Lib/10.0.22621.0/um/x64'
|
||||
link_args = ['-L' + windows_sdk_lib_dir, '-lwindowsapp']
|
||||
link_args = ['-L' + windows_sdk_lib_dir, '-lwindowsapp', '-static']
|
||||
|
||||
deps = []
|
||||
|
||||
|
|
|
@ -1,6 +1,12 @@
|
|||
#include "config.h"
|
||||
|
||||
fn Config::getInstance()->const Config& {
|
||||
static const Config* INSTANCE = new Config(rfl::toml::load<Config>("./config.toml").value());
|
||||
#ifdef __WIN32__
|
||||
const string path = string(getenv("LOCALAPPDATA")) + "\\draconis++\\config.toml";
|
||||
#else
|
||||
const string path = string(getenv("HOME")) + "/.config/draconis++/config.toml";
|
||||
#endif
|
||||
// ReSharper disable once CppDFAMemoryLeak
|
||||
static const Config* INSTANCE = new Config(rfl::toml::load<Config>(path).value());
|
||||
return *INSTANCE;
|
||||
}
|
||||
|
|
|
@ -3,9 +3,12 @@
|
|||
#include <rfl/json.hpp>
|
||||
#include <rfl/json/load.hpp>
|
||||
|
||||
#include "../util/result.h"
|
||||
#include "config.h"
|
||||
|
||||
using rfl::Error;
|
||||
using rfl::Nothing;
|
||||
using rfl::Result;
|
||||
|
||||
// Function to read cache from file
|
||||
fn ReadCacheFromFile()->Result<WeatherOutput> {
|
||||
#ifdef __WIN32__
|
||||
|
@ -21,23 +24,19 @@ fn ReadCacheFromFile() -> Result<WeatherOutput> {
|
|||
|
||||
fmt::println("Reading from cache file...");
|
||||
|
||||
WeatherOutput val;
|
||||
|
||||
try {
|
||||
std::stringstream buf;
|
||||
|
||||
buf << ifs.rdbuf();
|
||||
|
||||
val = rfl::json::read<WeatherOutput>(buf.str()).value();
|
||||
} catch (Error& e) { return e; }
|
||||
Result<WeatherOutput> val = rfl::json::read<WeatherOutput>(buf.str());
|
||||
|
||||
fmt::println("Successfully read from cache file.");
|
||||
|
||||
return Ok(val);
|
||||
return val;
|
||||
}
|
||||
|
||||
// Function to write cache to file
|
||||
fn WriteCacheToFile(const WeatherOutput& data) -> Result<> {
|
||||
fn WriteCacheToFile(const WeatherOutput& data)->Result<u8> {
|
||||
fmt::println("Writing to cache file...");
|
||||
|
||||
#ifdef __WIN32__
|
||||
|
@ -55,11 +54,11 @@ fn WriteCacheToFile(const WeatherOutput& data) -> Result<> {
|
|||
|
||||
fmt::println("Successfully wrote to cache file.");
|
||||
|
||||
return Ok();
|
||||
return 0;
|
||||
}
|
||||
|
||||
fn WriteCallback(void* contents, size_t size, size_t nmemb, string* str) -> size_t {
|
||||
size_t totalSize = size * nmemb;
|
||||
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;
|
||||
}
|
||||
|
@ -75,19 +74,18 @@ fn MakeApiRequest(const string& url) -> Result<WeatherOutput> {
|
|||
curl_easy_setopt(curl, CURLOPT_URL, url.c_str());
|
||||
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, WriteCallback);
|
||||
curl_easy_setopt(curl, CURLOPT_WRITEDATA, &responseBuffer);
|
||||
CURLcode res = curl_easy_perform(curl);
|
||||
const CURLcode res = curl_easy_perform(curl);
|
||||
curl_easy_cleanup(curl);
|
||||
|
||||
if (res != CURLE_OK) {
|
||||
if (res != CURLE_OK)
|
||||
return Error(fmt::format("Failed to perform cURL request: {}", curl_easy_strerror(res)));
|
||||
}
|
||||
|
||||
fmt::println("Received response from API. Response size: {}", responseBuffer.size());
|
||||
fmt::println("Response: {}", responseBuffer);
|
||||
|
||||
WeatherOutput output = rfl::json::read<WeatherOutput>(responseBuffer).value();
|
||||
|
||||
return Ok(output); // Return an empty result for now
|
||||
return output; // Return an empty result for now
|
||||
}
|
||||
|
||||
return Error("Failed to initialize cURL.");
|
||||
|
@ -98,10 +96,9 @@ fn Weather::getWeatherInfo() const -> WeatherOutput {
|
|||
using namespace std::chrono;
|
||||
|
||||
// Check if cache is valid
|
||||
if (Result<WeatherOutput> data = ReadCacheFromFile(); data.isOk()) {
|
||||
WeatherOutput dataVal = data.value();
|
||||
|
||||
if (system_clock::now() - system_clock::time_point(seconds(dataVal.dt)) <
|
||||
if (Result<WeatherOutput> data = ReadCacheFromFile()) {
|
||||
if (WeatherOutput dataVal = *data;
|
||||
system_clock::now() - system_clock::time_point(seconds(dataVal.dt)) <
|
||||
minutes(10)) { // Assuming cache duration is always 10 minutes
|
||||
fmt::println("Cache is valid. Returning cached data.");
|
||||
|
||||
|
|
|
@ -62,7 +62,7 @@ fn main() -> i32 {
|
|||
|
||||
const auto
|
||||
[clouds,
|
||||
timezone,
|
||||
tz,
|
||||
visibility,
|
||||
main,
|
||||
coords,
|
||||
|
@ -76,6 +76,7 @@ fn main() -> i32 {
|
|||
dt,
|
||||
id,
|
||||
wind] = weatherFuture.get();
|
||||
|
||||
const i64 temp = std::lround(main.temp);
|
||||
|
||||
const bool nowPlayingEnabled = nowPlayingEnabledFuture.get();
|
||||
|
|
Loading…
Reference in a new issue