This commit is contained in:
Mars 2024-06-18 04:10:36 -04:00
parent 11096c5ec7
commit 1926ef4a92
Signed by: pupbrained
GPG key ID: 0FF5B8826803F895
4 changed files with 30 additions and 18 deletions

View file

@ -23,6 +23,7 @@ if host_machine.system() == 'darwin'
add_project_arguments( add_project_arguments(
objcpp.get_supported_arguments([ objcpp.get_supported_arguments([
'-Wno-c++20-compat', '-Wno-c++20-compat',
'-Wno-c++20-extensions',
'-Wno-c++98-compat', '-Wno-c++98-compat',
'-Wno-c++98-compat-pedantic', '-Wno-c++98-compat-pedantic',
'-Wno-disabled-macro-expansion', '-Wno-disabled-macro-expansion',
@ -39,6 +40,7 @@ endif
add_project_arguments( add_project_arguments(
cpp.get_supported_arguments([ cpp.get_supported_arguments([
'-Wno-c++20-compat', '-Wno-c++20-compat',
'-Wno-c++20-extensions',
'-Wno-c++98-compat', '-Wno-c++98-compat',
'-Wno-c++98-compat-pedantic', '-Wno-c++98-compat-pedantic',
'-Wno-disabled-macro-expansion', '-Wno-disabled-macro-expansion',

View file

@ -7,6 +7,8 @@
#include "util/result.h" #include "util/result.h"
using WeatherOutput = Weather::WeatherOutput;
DEFINE_GETTER(Weather, const Weather::Location, Location) DEFINE_GETTER(Weather, const Weather::Location, Location)
DEFINE_GETTER(Weather, const std::string, ApiKey) DEFINE_GETTER(Weather, const std::string, ApiKey)
DEFINE_GETTER(Weather, const std::string, Units) DEFINE_GETTER(Weather, const std::string, Units)
@ -24,8 +26,6 @@ fn WeatherImpl::from_class(const Weather& weather) noexcept -> WeatherImpl {
fn WeatherImpl::to_class() const -> Weather { return { location, api_key, units }; } fn WeatherImpl::to_class() const -> Weather { return { location, api_key, units }; }
using WeatherOutput = Weather::WeatherOutput;
// Function to read cache from file // Function to read cache from file
fn ReadCacheFromFile() -> Result<WeatherOutput> { fn ReadCacheFromFile() -> Result<WeatherOutput> {
std::ifstream ifs("/tmp/weather_cache.json"); std::ifstream ifs("/tmp/weather_cache.json");

View file

@ -80,18 +80,17 @@ class Weather {
using Location = std::variant<std::string, Coords>; using Location = std::variant<std::string, Coords>;
private:
Location m_Location;
std::string m_ApiKey;
std::string m_Units;
public:
Weather(Location location, std::string api_key, std::string units); Weather(Location location, std::string api_key, std::string units);
[[nodiscard]] fn getWeatherInfo() const -> WeatherOutput; [[nodiscard]] fn getWeatherInfo() const -> WeatherOutput;
[[nodiscard]] fn getLocation() const -> const Location; [[nodiscard]] fn getLocation() const -> const Location;
[[nodiscard]] fn getApiKey() const -> const std::string; [[nodiscard]] fn getApiKey() const -> const std::string;
[[nodiscard]] fn getUnits() const -> const std::string; [[nodiscard]] fn getUnits() const -> const std::string;
private:
Location m_Location;
std::string m_ApiKey;
std::string m_Units;
}; };
DEF_IMPL(Weather, Weather::Location location; std::string api_key; std::string units) DEF_IMPL(Weather, Weather::Location location; std::string api_key; std::string units)

View file

@ -1,6 +1,7 @@
#include <ctime> #include <ctime>
#include <fmt/chrono.h> #include <fmt/chrono.h>
#include <fmt/core.h> #include <fmt/core.h>
#include <future>
#include "config/config.h" #include "config/config.h"
#include "os/os.h" #include "os/os.h"
@ -50,26 +51,36 @@ fn main() -> int {
using WeatherOutput = Weather::WeatherOutput; using WeatherOutput = Weather::WeatherOutput;
const Config& config = Config::getInstance(); const Config& config = Config::getInstance();
WeatherOutput json = config.getWeather().getWeatherInfo();
const long temp = std::lround(json.main.temp); auto weatherFuture =
const string townName = json.name; std::async(std::launch::async, [&config]() { return config.getWeather().getWeatherInfo(); });
const char* version = GetOSVersion(); auto osVersionFuture = std::async(std::launch::async, GetOSVersion);
const string name = config.getGeneral().getName(); auto nowPlayingEnabledFuture =
const bool nowPlayingEnabled = config.getNowPlaying().getEnabled(); std::async(std::launch::async, [&config]() { return config.getNowPlaying().getEnabled(); });
auto dateFuture = std::async(std::launch::async, GetDate);
auto memInfoFuture = std::async(std::launch::async, GetMemInfo);
WeatherOutput json = weatherFuture.get();
const long temp = std::lround(json.main.temp);
const std::string townName = json.name;
const char* version = osVersionFuture.get();
const std::string name = config.getGeneral().getName();
const bool nowPlayingEnabled = nowPlayingEnabledFuture.get();
fmt::println("Hello {}!", name); fmt::println("Hello {}!", name);
fmt::println("Today is: {}", GetDate()); fmt::println("Today is: {}", dateFuture.get());
fmt::println("It is {}°F in {}", temp, townName); fmt::println("It is {}°F in {}", temp, townName);
fmt::println("Installed RAM: {:.2f}", BytesToGiB { GetMemInfo() }); fmt::println("Installed RAM: {:.2f} GiB", BytesToGiB(memInfoFuture.get()));
fmt::println("{}", version); fmt::println("{}", version);
if (nowPlayingEnabled) if (nowPlayingEnabled) {
fmt::println("{}", GetNowPlaying()); fmt::println("{}", GetNowPlaying());
}
delete[] version; delete[] version;
delete &config;
return 0; return 0;
} }