some cleanup and stuff
This commit is contained in:
parent
138191227f
commit
afbba70f92
|
@ -10,6 +10,7 @@ AllowShortLoopsOnASingleLine: true
|
||||||
BasedOnStyle: Chromium
|
BasedOnStyle: Chromium
|
||||||
BinPackArguments: false
|
BinPackArguments: false
|
||||||
BinPackParameters: false
|
BinPackParameters: false
|
||||||
|
FixNamespaceComments: false
|
||||||
IndentAccessModifiers: false
|
IndentAccessModifiers: false
|
||||||
IndentExternBlock: Indent
|
IndentExternBlock: Indent
|
||||||
NamespaceIndentation: All
|
NamespaceIndentation: All
|
||||||
|
|
|
@ -13,6 +13,7 @@ Checks: >
|
||||||
-hicpp-*,
|
-hicpp-*,
|
||||||
-llvm-include-order,
|
-llvm-include-order,
|
||||||
-llvm-include-order,
|
-llvm-include-order,
|
||||||
|
-llvm-namespace-comment,
|
||||||
-llvmlibc-*,
|
-llvmlibc-*,
|
||||||
-misc-non-private-member-variables-in-classes,
|
-misc-non-private-member-variables-in-classes,
|
||||||
-readability-braces-around-statements,
|
-readability-braces-around-statements,
|
||||||
|
|
12
flake.lock
12
flake.lock
|
@ -2,11 +2,11 @@
|
||||||
"nodes": {
|
"nodes": {
|
||||||
"nixpkgs": {
|
"nixpkgs": {
|
||||||
"locked": {
|
"locked": {
|
||||||
"lastModified": 1717646450,
|
"lastModified": 1718149104,
|
||||||
"narHash": "sha256-KE+UmfSVk5PG8jdKdclPVcMrUB8yVZHbsjo7ZT1Bm3c=",
|
"narHash": "sha256-Ds1QpobBX2yoUDx9ZruqVGJ/uQPgcXoYuobBguyKEh8=",
|
||||||
"owner": "NixOS",
|
"owner": "NixOS",
|
||||||
"repo": "nixpkgs",
|
"repo": "nixpkgs",
|
||||||
"rev": "818dbe2f96df233d2041739d6079bb616d3e5597",
|
"rev": "e913ae340076bbb73d9f4d3d065c2bca7caafb16",
|
||||||
"type": "github"
|
"type": "github"
|
||||||
},
|
},
|
||||||
"original": {
|
"original": {
|
||||||
|
@ -59,11 +59,11 @@
|
||||||
"nixpkgs": "nixpkgs_2"
|
"nixpkgs": "nixpkgs_2"
|
||||||
},
|
},
|
||||||
"locked": {
|
"locked": {
|
||||||
"lastModified": 1717850719,
|
"lastModified": 1718271476,
|
||||||
"narHash": "sha256-npYqVg+Wk4oxnWrnVG7416fpfrlRhp/lQ6wQ4DHI8YE=",
|
"narHash": "sha256-35hUMmFesmchb+u7heKHLG5B6c8fBOcSYo0jj0CHLes=",
|
||||||
"owner": "numtide",
|
"owner": "numtide",
|
||||||
"repo": "treefmt-nix",
|
"repo": "treefmt-nix",
|
||||||
"rev": "4fc1c45a5f50169f9f29f6a98a438fb910b834ed",
|
"rev": "e75ba0a6bb562d2ce275db28f6a36a2e4fd81391",
|
||||||
"type": "github"
|
"type": "github"
|
||||||
},
|
},
|
||||||
"original": {
|
"original": {
|
||||||
|
|
3
include/util/macros.h
Normal file
3
include/util/macros.h
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
#define fn auto
|
||||||
|
#define DEFINE_GETTER(class_name, type, name) \
|
||||||
|
fn class_name::get##name() const->type { return m_##name; }
|
|
@ -3,8 +3,6 @@
|
||||||
#include <cstddef>
|
#include <cstddef>
|
||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
|
|
||||||
#define fn auto
|
|
||||||
|
|
||||||
// Unsigned integers
|
// Unsigned integers
|
||||||
using u8 = std::uint8_t;
|
using u8 = std::uint8_t;
|
||||||
using u16 = std::uint16_t;
|
using u16 = std::uint16_t;
|
||||||
|
|
|
@ -4,7 +4,7 @@ project(
|
||||||
default_options: [
|
default_options: [
|
||||||
'objc_std=c++20',
|
'objc_std=c++20',
|
||||||
'objcpp_std=c++20',
|
'objcpp_std=c++20',
|
||||||
'cpp_std=c++23',
|
'cpp_std=c++20',
|
||||||
'default_library=static',
|
'default_library=static',
|
||||||
'warning_level=everything',
|
'warning_level=everything',
|
||||||
'buildtype=debugoptimized'
|
'buildtype=debugoptimized'
|
||||||
|
|
|
@ -1,32 +1,12 @@
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
|
|
||||||
#define DEFINE_GETTER(class_name, type, name) \
|
// -------------
|
||||||
fn class_name::get##name() const->type { return m_##name; }
|
// -- Weather --
|
||||||
|
// -------------
|
||||||
DEFINE_GETTER(Config, const General, General)
|
|
||||||
DEFINE_GETTER(Config, const NowPlaying, NowPlaying)
|
|
||||||
DEFINE_GETTER(Config, const Weather, Weather)
|
|
||||||
DEFINE_GETTER(General, const std::string, Name)
|
|
||||||
DEFINE_GETTER(NowPlaying, bool, Enabled)
|
|
||||||
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)
|
||||||
|
|
||||||
fn Config::getInstance() -> const Config& {
|
|
||||||
static const auto* INSTANCE =
|
|
||||||
new Config(rfl::toml::load<Config>("./config.toml").value());
|
|
||||||
return *INSTANCE;
|
|
||||||
}
|
|
||||||
|
|
||||||
Config::Config(General general, NowPlaying now_playing, Weather weather)
|
|
||||||
: m_General(std::move(general)),
|
|
||||||
m_NowPlaying(now_playing),
|
|
||||||
m_Weather(std::move(weather)) {}
|
|
||||||
|
|
||||||
General::General(std::string name) : m_Name(std::move(name)) {}
|
|
||||||
|
|
||||||
NowPlaying::NowPlaying(bool enabled) : m_Enabled(enabled) {}
|
|
||||||
|
|
||||||
Weather::Weather(Location location, std::string api_key, std::string units)
|
Weather::Weather(Location location, std::string api_key, std::string units)
|
||||||
: m_Location(std::move(location)),
|
: m_Location(std::move(location)),
|
||||||
m_ApiKey(std::move(api_key)),
|
m_ApiKey(std::move(api_key)),
|
||||||
|
@ -43,22 +23,56 @@ fn WeatherImpl::from_class(const Weather& weather) noexcept -> WeatherImpl {
|
||||||
fn WeatherImpl::to_class() const -> Weather {
|
fn WeatherImpl::to_class() const -> Weather {
|
||||||
return {location, api_key, units};
|
return {location, api_key, units};
|
||||||
}
|
}
|
||||||
|
// ------------
|
||||||
|
|
||||||
|
// -------------
|
||||||
|
// -- General --
|
||||||
|
// -------------
|
||||||
|
DEFINE_GETTER(General, const std::string, Name)
|
||||||
|
|
||||||
|
General::General(std::string name) : m_Name(std::move(name)) {}
|
||||||
|
|
||||||
fn GeneralImpl::from_class(const General& general) noexcept -> GeneralImpl {
|
fn GeneralImpl::from_class(const General& general) noexcept -> GeneralImpl {
|
||||||
return {general.getName()};
|
return {general.getName()};
|
||||||
}
|
}
|
||||||
|
|
||||||
fn GeneralImpl::to_class() const -> General { return {name}; }
|
fn GeneralImpl::to_class() const -> General { return {name}; }
|
||||||
|
// -------------
|
||||||
|
|
||||||
// clang-format off
|
// ----------------
|
||||||
fn NowPlayingImpl::from_class(
|
// -- NowPlaying --
|
||||||
const NowPlaying& now_playing
|
// ----------------
|
||||||
|
DEFINE_GETTER(NowPlaying, bool, Enabled)
|
||||||
|
|
||||||
|
NowPlaying::NowPlaying(bool enabled) : m_Enabled(enabled) {}
|
||||||
|
|
||||||
|
fn NowPlayingImpl::from_class(const NowPlaying& now_playing
|
||||||
) noexcept -> NowPlayingImpl {
|
) noexcept -> NowPlayingImpl {
|
||||||
return {.enabled = now_playing.getEnabled()};
|
return {.enabled = now_playing.getEnabled()};
|
||||||
}
|
}
|
||||||
//clang-format on
|
|
||||||
|
|
||||||
fn NowPlayingImpl::to_class() const -> NowPlaying { return {enabled.value_or(false)}; }
|
fn NowPlayingImpl::to_class() const -> NowPlaying {
|
||||||
|
return {enabled.value_or(false)};
|
||||||
|
}
|
||||||
|
// ----------------
|
||||||
|
|
||||||
|
// ------------
|
||||||
|
// -- Config --
|
||||||
|
// ------------
|
||||||
|
DEFINE_GETTER(Config, const General, General)
|
||||||
|
DEFINE_GETTER(Config, const NowPlaying, NowPlaying)
|
||||||
|
DEFINE_GETTER(Config, const Weather, Weather)
|
||||||
|
|
||||||
|
Config::Config(General general, NowPlaying now_playing, Weather weather)
|
||||||
|
: m_General(std::move(general)),
|
||||||
|
m_NowPlaying(now_playing),
|
||||||
|
m_Weather(std::move(weather)) {}
|
||||||
|
|
||||||
|
fn Config::getInstance() -> const Config& {
|
||||||
|
static const auto* INSTANCE =
|
||||||
|
new Config(rfl::toml::load<Config>("./config.toml").value());
|
||||||
|
return *INSTANCE;
|
||||||
|
}
|
||||||
|
|
||||||
fn ConfigImpl::from_class(const Config& config) noexcept -> ConfigImpl {
|
fn ConfigImpl::from_class(const Config& config) noexcept -> ConfigImpl {
|
||||||
return {
|
return {
|
||||||
|
@ -71,3 +85,4 @@ fn ConfigImpl::from_class(const Config& config) noexcept -> ConfigImpl {
|
||||||
fn ConfigImpl::to_class() const -> Config {
|
fn ConfigImpl::to_class() const -> Config {
|
||||||
return {general, now_playing, weather};
|
return {general, now_playing, weather};
|
||||||
}
|
}
|
||||||
|
// ------------
|
||||||
|
|
|
@ -4,104 +4,11 @@
|
||||||
#include <rfl.hpp>
|
#include <rfl.hpp>
|
||||||
#include <rfl/toml.hpp>
|
#include <rfl/toml.hpp>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <variant>
|
|
||||||
|
|
||||||
#include "util/numtypes.h"
|
#include "util/macros.h"
|
||||||
|
#include "weather.h"
|
||||||
|
|
||||||
class Weather {
|
// TODO: Make config values optional and supply defaults
|
||||||
public:
|
|
||||||
using degrees = rfl::Validator<u16, rfl::Minimum<0>, rfl::Maximum<360>>;
|
|
||||||
using percentage = rfl::Validator<i8, rfl::Minimum<0>, rfl::Maximum<100>>;
|
|
||||||
|
|
||||||
struct Condition {
|
|
||||||
std::string description;
|
|
||||||
std::string icon;
|
|
||||||
std::string main;
|
|
||||||
usize id;
|
|
||||||
};
|
|
||||||
|
|
||||||
struct Main {
|
|
||||||
f64 feels_like;
|
|
||||||
f64 temp;
|
|
||||||
f64 temp_max;
|
|
||||||
f64 temp_min;
|
|
||||||
isize pressure;
|
|
||||||
percentage humidity;
|
|
||||||
std::optional<isize> grnd_level;
|
|
||||||
std::optional<isize> sea_level;
|
|
||||||
};
|
|
||||||
|
|
||||||
struct Wind {
|
|
||||||
degrees deg;
|
|
||||||
f64 speed;
|
|
||||||
std::optional<f64> gust;
|
|
||||||
};
|
|
||||||
|
|
||||||
struct Precipitation {
|
|
||||||
rfl::Rename<"1h", f64> one_hour;
|
|
||||||
rfl::Rename<"3h", f64> three_hours;
|
|
||||||
};
|
|
||||||
|
|
||||||
struct Sys {
|
|
||||||
std::string country;
|
|
||||||
usize id;
|
|
||||||
usize sunrise;
|
|
||||||
usize sunset;
|
|
||||||
usize type;
|
|
||||||
};
|
|
||||||
|
|
||||||
struct Clouds {
|
|
||||||
percentage all;
|
|
||||||
};
|
|
||||||
|
|
||||||
struct Coords {
|
|
||||||
double lat;
|
|
||||||
double lon;
|
|
||||||
};
|
|
||||||
|
|
||||||
struct WeatherOutput {
|
|
||||||
Clouds clouds;
|
|
||||||
isize timezone;
|
|
||||||
isize visibility;
|
|
||||||
Main main;
|
|
||||||
rfl::Rename<"coord", Coords> coords;
|
|
||||||
std::optional<Precipitation> rain;
|
|
||||||
std::optional<Precipitation> snow;
|
|
||||||
std::string base;
|
|
||||||
std::string name;
|
|
||||||
std::vector<Condition> weather;
|
|
||||||
Sys sys;
|
|
||||||
usize cod;
|
|
||||||
usize dt;
|
|
||||||
usize id;
|
|
||||||
Wind wind;
|
|
||||||
};
|
|
||||||
|
|
||||||
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);
|
|
||||||
|
|
||||||
[[nodiscard]] fn getWeatherInfo() const -> WeatherOutput;
|
|
||||||
[[nodiscard]] fn getLocation() const -> const Location;
|
|
||||||
[[nodiscard]] fn getApiKey() const -> const std::string;
|
|
||||||
[[nodiscard]] fn getUnits() const -> const std::string;
|
|
||||||
};
|
|
||||||
|
|
||||||
struct WeatherImpl {
|
|
||||||
Weather::Location location;
|
|
||||||
std::string api_key;
|
|
||||||
std::string units;
|
|
||||||
|
|
||||||
static fn from_class(const Weather& weather) noexcept -> WeatherImpl;
|
|
||||||
|
|
||||||
[[nodiscard]] fn to_class() const -> Weather;
|
|
||||||
};
|
|
||||||
|
|
||||||
class General {
|
class General {
|
||||||
private:
|
private:
|
||||||
|
@ -168,15 +75,6 @@ struct ConfigImpl {
|
||||||
|
|
||||||
// Parsers for Config classes
|
// Parsers for Config classes
|
||||||
namespace rfl::parsing {
|
namespace rfl::parsing {
|
||||||
template <class ReaderType, class WriterType, class ProcessorsType>
|
|
||||||
struct Parser<ReaderType, WriterType, Weather, ProcessorsType>
|
|
||||||
: public CustomParser<
|
|
||||||
ReaderType,
|
|
||||||
WriterType,
|
|
||||||
ProcessorsType,
|
|
||||||
Weather,
|
|
||||||
WeatherImpl> {};
|
|
||||||
|
|
||||||
template <class ReaderType, class WriterType, class ProcessorsType>
|
template <class ReaderType, class WriterType, class ProcessorsType>
|
||||||
struct Parser<ReaderType, WriterType, General, ProcessorsType>
|
struct Parser<ReaderType, WriterType, General, ProcessorsType>
|
||||||
: public CustomParser<
|
: public CustomParser<
|
||||||
|
@ -203,4 +101,4 @@ namespace rfl::parsing {
|
||||||
ProcessorsType,
|
ProcessorsType,
|
||||||
Config,
|
Config,
|
||||||
ConfigImpl> {};
|
ConfigImpl> {};
|
||||||
} // namespace rfl::parsing
|
}
|
||||||
|
|
|
@ -2,16 +2,16 @@
|
||||||
#include <fmt/core.h>
|
#include <fmt/core.h>
|
||||||
#include <rfl/json.hpp>
|
#include <rfl/json.hpp>
|
||||||
#include <rfl/json/load.hpp>
|
#include <rfl/json/load.hpp>
|
||||||
#include <util/result.h>
|
|
||||||
|
|
||||||
#include "config.h"
|
#include "weather.h"
|
||||||
|
|
||||||
|
#include "util/result.h"
|
||||||
|
|
||||||
using WeatherOutput = Weather::WeatherOutput;
|
using WeatherOutput = Weather::WeatherOutput;
|
||||||
|
|
||||||
// Function to read cache from file
|
// Function to read cache from file
|
||||||
fn ReadCacheFromFile() -> Result<WeatherOutput> {
|
fn ReadCacheFromFile() -> Result<WeatherOutput> {
|
||||||
const std::string cacheFile = "/tmp/weather_cache.json";
|
std::ifstream ifs("/tmp/weather_cache.json");
|
||||||
std::ifstream ifs(cacheFile);
|
|
||||||
|
|
||||||
if (!ifs.is_open())
|
if (!ifs.is_open())
|
||||||
return Error("Cache file not found.");
|
return Error("Cache file not found.");
|
||||||
|
@ -35,9 +35,9 @@ fn ReadCacheFromFile() -> Result<WeatherOutput> {
|
||||||
|
|
||||||
// Function to write cache to file
|
// Function to write cache to file
|
||||||
fn WriteCacheToFile(const WeatherOutput& data) -> Result<> {
|
fn WriteCacheToFile(const WeatherOutput& data) -> Result<> {
|
||||||
const std::string cacheFile = "/tmp/weather_cache.json";
|
|
||||||
fmt::println("Writing to cache file...");
|
fmt::println("Writing to cache file...");
|
||||||
std::ofstream ofs(cacheFile);
|
|
||||||
|
std::ofstream ofs("/tmp/weather_cache.json");
|
||||||
|
|
||||||
if (!ofs.is_open())
|
if (!ofs.is_open())
|
||||||
return Error("Failed to open cache file for writing.");
|
return Error("Failed to open cache file for writing.");
|
||||||
|
@ -49,7 +49,8 @@ fn WriteCacheToFile(const WeatherOutput& data) -> Result<> {
|
||||||
return Ok();
|
return Ok();
|
||||||
}
|
}
|
||||||
|
|
||||||
fn WriteCallback(void* contents, size_t size, size_t nmemb, std::string* str) -> size_t {
|
fn WriteCallback(void* contents, size_t size, size_t nmemb, std::string* str)
|
||||||
|
-> size_t {
|
||||||
size_t totalSize = size * nmemb;
|
size_t totalSize = size * nmemb;
|
||||||
str->append(static_cast<char*>(contents), totalSize);
|
str->append(static_cast<char*>(contents), totalSize);
|
||||||
return totalSize;
|
return totalSize;
|
||||||
|
@ -59,7 +60,7 @@ fn WriteCallback(void* contents, size_t size, size_t nmemb, std::string* str) ->
|
||||||
fn MakeApiRequest(const std::string& url) -> Result<WeatherOutput> {
|
fn MakeApiRequest(const std::string& url) -> Result<WeatherOutput> {
|
||||||
fmt::println("Making API request to URL: {}", url);
|
fmt::println("Making API request to URL: {}", url);
|
||||||
|
|
||||||
CURL* curl = curl_easy_init();
|
CURL* curl = curl_easy_init();
|
||||||
std::string responseBuffer;
|
std::string responseBuffer;
|
||||||
|
|
||||||
if (curl) {
|
if (curl) {
|
||||||
|
@ -70,10 +71,14 @@ fn MakeApiRequest(const std::string& url) -> Result<WeatherOutput> {
|
||||||
curl_easy_cleanup(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)));
|
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(
|
||||||
|
"Received response from API. Response size: {}", responseBuffer.size()
|
||||||
|
);
|
||||||
|
|
||||||
WeatherOutput output =
|
WeatherOutput output =
|
||||||
rfl::json::read<WeatherOutput>(responseBuffer).value();
|
rfl::json::read<WeatherOutput>(responseBuffer).value();
|
||||||
|
|
116
src/config/weather.h
Normal file
116
src/config/weather.h
Normal file
|
@ -0,0 +1,116 @@
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <fmt/core.h>
|
||||||
|
#include <rfl.hpp>
|
||||||
|
#include <rfl/toml.hpp>
|
||||||
|
#include <string>
|
||||||
|
#include <variant>
|
||||||
|
|
||||||
|
#include "util/macros.h"
|
||||||
|
#include "util/numtypes.h"
|
||||||
|
|
||||||
|
class Weather {
|
||||||
|
public:
|
||||||
|
using degrees = rfl::Validator<u16, rfl::Minimum<0>, rfl::Maximum<360>>;
|
||||||
|
using percentage = rfl::Validator<i8, rfl::Minimum<0>, rfl::Maximum<100>>;
|
||||||
|
|
||||||
|
struct Condition {
|
||||||
|
std::string description;
|
||||||
|
std::string icon;
|
||||||
|
std::string main;
|
||||||
|
usize id;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct Main {
|
||||||
|
f64 feels_like;
|
||||||
|
f64 temp;
|
||||||
|
f64 temp_max;
|
||||||
|
f64 temp_min;
|
||||||
|
isize pressure;
|
||||||
|
percentage humidity;
|
||||||
|
std::optional<isize> grnd_level;
|
||||||
|
std::optional<isize> sea_level;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct Wind {
|
||||||
|
degrees deg;
|
||||||
|
f64 speed;
|
||||||
|
std::optional<f64> gust;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct Precipitation {
|
||||||
|
rfl::Rename<"1h", f64> one_hour;
|
||||||
|
rfl::Rename<"3h", f64> three_hours;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct Sys {
|
||||||
|
std::string country;
|
||||||
|
usize id;
|
||||||
|
usize sunrise;
|
||||||
|
usize sunset;
|
||||||
|
usize type;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct Clouds {
|
||||||
|
percentage all;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct Coords {
|
||||||
|
double lat;
|
||||||
|
double lon;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct WeatherOutput {
|
||||||
|
Clouds clouds;
|
||||||
|
isize timezone;
|
||||||
|
isize visibility;
|
||||||
|
Main main;
|
||||||
|
rfl::Rename<"coord", Coords> coords;
|
||||||
|
std::optional<Precipitation> rain;
|
||||||
|
std::optional<Precipitation> snow;
|
||||||
|
std::string base;
|
||||||
|
std::string name;
|
||||||
|
std::vector<Condition> weather;
|
||||||
|
Sys sys;
|
||||||
|
usize cod;
|
||||||
|
usize dt;
|
||||||
|
usize id;
|
||||||
|
Wind wind;
|
||||||
|
};
|
||||||
|
|
||||||
|
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);
|
||||||
|
|
||||||
|
[[nodiscard]] fn getWeatherInfo() const -> WeatherOutput;
|
||||||
|
[[nodiscard]] fn getLocation() const -> const Location;
|
||||||
|
[[nodiscard]] fn getApiKey() const -> const std::string;
|
||||||
|
[[nodiscard]] fn getUnits() const -> const std::string;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct WeatherImpl {
|
||||||
|
Weather::Location location;
|
||||||
|
std::string api_key;
|
||||||
|
std::string units;
|
||||||
|
|
||||||
|
static fn from_class(const Weather& weather) noexcept -> WeatherImpl;
|
||||||
|
|
||||||
|
[[nodiscard]] fn to_class() const -> Weather;
|
||||||
|
};
|
||||||
|
|
||||||
|
namespace rfl::parsing {
|
||||||
|
template <class ReaderType, class WriterType, class ProcessorsType>
|
||||||
|
struct Parser<ReaderType, WriterType, Weather, ProcessorsType>
|
||||||
|
: public CustomParser<
|
||||||
|
ReaderType,
|
||||||
|
WriterType,
|
||||||
|
ProcessorsType,
|
||||||
|
Weather,
|
||||||
|
WeatherImpl> {};
|
||||||
|
}
|
|
@ -9,7 +9,7 @@
|
||||||
+ (NSString*)macOSVersion;
|
+ (NSString*)macOSVersion;
|
||||||
@end
|
@end
|
||||||
#else
|
#else
|
||||||
#include "util/numtypes.h"
|
#include "util/macros.h"
|
||||||
|
|
||||||
extern "C" {
|
extern "C" {
|
||||||
fn GetCurrentPlayingTitle() -> const char*;
|
fn GetCurrentPlayingTitle() -> const char*;
|
||||||
|
|
|
@ -80,8 +80,13 @@ using MRMediaRemoteGetNowPlayingInfoFunction = void (*)(
|
||||||
}
|
}
|
||||||
|
|
||||||
// Dictionary to map macOS versions to their respective names
|
// Dictionary to map macOS versions to their respective names
|
||||||
NSDictionary<NSNumber*, NSString*>* versionNames =
|
NSDictionary<NSNumber*, NSString*>* versionNames = @{
|
||||||
@{@11 : @"Big Sur", @12 : @"Monterey", @13 : @"Ventura", @14 : @"Sonoma"};
|
@11 : @"Big Sur",
|
||||||
|
@12 : @"Monterey",
|
||||||
|
@13 : @"Ventura",
|
||||||
|
@14 : @"Sonoma",
|
||||||
|
@15 : @"Sequoia"
|
||||||
|
};
|
||||||
|
|
||||||
NSNumber* majorVersionNumber = @(osVersion.majorVersion);
|
NSNumber* majorVersionNumber = @(osVersion.majorVersion);
|
||||||
NSString* versionName = versionNames[majorVersionNumber];
|
NSString* versionName = versionNames[majorVersionNumber];
|
||||||
|
@ -96,7 +101,7 @@ using MRMediaRemoteGetNowPlayingInfoFunction = void (*)(
|
||||||
}
|
}
|
||||||
@end
|
@end
|
||||||
|
|
||||||
#include "util/numtypes.h"
|
#include "util/macros.h"
|
||||||
|
|
||||||
extern "C" {
|
extern "C" {
|
||||||
fn GetCurrentPlayingTitle() -> const char* {
|
fn GetCurrentPlayingTitle() -> const char* {
|
||||||
|
|
|
@ -2,8 +2,9 @@
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
|
#include "util/macros.h"
|
||||||
#include "util/numtypes.h"
|
#include "util/numtypes.h"
|
||||||
|
|
||||||
u64 GetMemInfo();
|
fn GetMemInfo() -> u64;
|
||||||
std::string GetNowPlaying();
|
fn GetNowPlaying() -> std::string;
|
||||||
const char* GetOSVersion();
|
fn GetOSVersion() -> const char*;
|
||||||
|
|
Loading…
Reference in a new issue