This commit is contained in:
Mars 2024-07-30 19:50:45 -04:00
parent dff976ed0e
commit 3ebbb2b3ec
Signed by: pupbrained
GPG key ID: 874E22DF2F9DFCB5
6 changed files with 58 additions and 52 deletions

View file

@ -2,27 +2,26 @@
"nodes": { "nodes": {
"nixpkgs": { "nixpkgs": {
"locked": { "locked": {
"lastModified": 1718149104, "lastModified": 1722375055,
"narHash": "sha256-Ds1QpobBX2yoUDx9ZruqVGJ/uQPgcXoYuobBguyKEh8=", "narHash": "sha256-TXtpKGKpaa7ZivMgB0y+63ZLITXPXIAzof6hqw1pqHA=",
"owner": "NixOS", "owner": "NixOS",
"repo": "nixpkgs", "repo": "nixpkgs",
"rev": "e913ae340076bbb73d9f4d3d065c2bca7caafb16", "rev": "d8c09e3ff18ad95f0765fdfc21f4698dea7ab670",
"type": "github" "type": "github"
}, },
"original": { "original": {
"owner": "NixOS", "owner": "NixOS",
"ref": "nixpkgs-unstable",
"repo": "nixpkgs", "repo": "nixpkgs",
"type": "github" "type": "github"
} }
}, },
"nixpkgs_2": { "nixpkgs_2": {
"locked": { "locked": {
"lastModified": 1708475490, "lastModified": 1720957393,
"narHash": "sha256-g1v0TsWBQPX97ziznfJdWhgMyMGtoBFs102xSYO4syU=", "narHash": "sha256-oedh2RwpjEa+TNxhg5Je9Ch6d3W1NKi7DbRO1ziHemA=",
"owner": "nixos", "owner": "nixos",
"repo": "nixpkgs", "repo": "nixpkgs",
"rev": "0e74ca98a74bc7270d28838369593635a5db3260", "rev": "693bc46d169f5af9c992095736e82c3488bf7dbb",
"type": "github" "type": "github"
}, },
"original": { "original": {
@ -59,11 +58,11 @@
"nixpkgs": "nixpkgs_2" "nixpkgs": "nixpkgs_2"
}, },
"locked": { "locked": {
"lastModified": 1718271476, "lastModified": 1722330636,
"narHash": "sha256-35hUMmFesmchb+u7heKHLG5B6c8fBOcSYo0jj0CHLes=", "narHash": "sha256-uru7JzOa33YlSRwf9sfXpJG+UAV+bnBEYMjrzKrQZFw=",
"owner": "numtide", "owner": "numtide",
"repo": "treefmt-nix", "repo": "treefmt-nix",
"rev": "e75ba0a6bb562d2ce275db28f6a36a2e4fd81391", "rev": "768acdb06968e53aa1ee8de207fd955335c754b7",
"type": "github" "type": "github"
}, },
"original": { "original": {

View file

@ -2,7 +2,7 @@
description = "C/C++ environment"; description = "C/C++ environment";
inputs = { inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable"; nixpkgs.url = "github:NixOS/nixpkgs";
treefmt-nix.url = "github:numtide/treefmt-nix"; treefmt-nix.url = "github:numtide/treefmt-nix";
utils.url = "github:numtide/flake-utils"; utils.url = "github:numtide/flake-utils";
}; };
@ -43,35 +43,29 @@
]; ];
}; };
deps = with ( deps = with pkgs.pkgsStatic;
if !stdenv.isDarwin
then pkgs.pkgsStatic
else pkgs # TODO: Remove when fixed on darwin
);
[ [
curl
fmt fmt
glib libiconv
tomlplusplus tomlplusplus
yyjson yyjson
reflect-cpp reflect-cpp
] ]
++ (
if !stdenv.isDarwin && system == "x86_64-linux"
then [pkgsStatic.curl]
else [pkgs.curl]
)
++ linuxPkgs ++ linuxPkgs
++ darwinPkgs; ++ darwinPkgs;
linuxPkgs = nixpkgs.lib.optionals stdenv.isLinux (with pkgs; [ linuxPkgs = nixpkgs.lib.optionals stdenv.isLinux (with pkgs.pkgsStatic; [
glib
systemdLibs systemdLibs
sdbus-cpp sdbus-cpp
valgrind valgrind
]); ]);
darwinPkgs = nixpkgs.lib.optionals stdenv.isDarwin (with pkgs.darwin.apple_sdk.frameworks; [ darwinPkgs = nixpkgs.lib.optionals stdenv.isDarwin (with pkgs.pkgsStatic.darwin.apple_sdk.frameworks; [
Foundation Foundation
MediaPlayer MediaPlayer
SystemConfiguration
]); ]);
in in
with pkgs; { with pkgs; {

View file

@ -2,7 +2,7 @@ project(
'draconis++', 'cpp', 'draconis++', 'cpp',
version: '0.1.0', version: '0.1.0',
default_options: [ default_options: [
'cpp_std=c++23', 'cpp_std=c++20',
'default_library=static', 'default_library=static',
'warning_level=everything', 'warning_level=everything',
'buildtype=release' 'buildtype=release'
@ -79,15 +79,17 @@ foreach file : source_file_names
endforeach endforeach
deps = [ deps = [
dependency('fmt', static: host_machine.system() != 'darwin'), dependency('fmt'),
dependency('libcurl', static: host_machine.system() != 'darwin'), dependency('libcurl'),
dependency('tomlplusplus', static: host_machine.system() != 'darwin'), dependency('tomlplusplus'),
dependency('yyjson', static: host_machine.system() != 'darwin') dependency('yyjson')
] ]
if host_machine.system() == 'darwin' if host_machine.system() == 'darwin'
deps += dependency('Foundation') deps += dependency('Foundation')
deps += dependency('MediaPlayer') deps += dependency('MediaPlayer')
deps += dependency('SystemConfiguration')
deps += dependency('iconv')
elif host_machine.system() == 'linux' elif host_machine.system() == 'linux'
deps += dependency('sdbus-c++') deps += dependency('sdbus-c++')
endif endif
@ -97,7 +99,6 @@ link_args = []
if host_machine.system() == 'darwin' if host_machine.system() == 'darwin'
objc_args += ['-fobjc-arc'] objc_args += ['-fobjc-arc']
link_args += ['-framework', 'Foundation', '-framework', 'MediaPlayer']
elif host_machine.system() == 'windows' elif host_machine.system() == 'windows'
windows_sdk_lib_dir = 'C:/Program Files (x86)/Windows Kits/10/Lib/10.0.22621.0/um/x64' 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', '-static'] link_args += ['-L' + windows_sdk_lib_dir, '-lwindowsapp', '-static']

View file

@ -1,26 +1,43 @@
#include <cstdlib>
#include <filesystem>
#include <fmt/core.h> #include <fmt/core.h>
#include <string>
#include "config.h" #include "config.h"
using rfl::Result; using rfl::Result;
namespace fs = std::filesystem;
inline fn GetConfigPath() -> string { inline fn GetConfigPath() -> std::string {
return getenv( #ifdef _WIN32
#ifdef __WIN32__ const char* localAppData = std::getenv("LOCALAPPDATA");
"LOCALAPPDATA"
if (!localAppData)
throw std::runtime_error("Environment variable LOCALAPPDATA is not set");
return localAppData;
#else #else
"HOME" const char* home = std::getenv("HOME");
if (!home)
throw std::runtime_error("Environment variable HOME is not set");
return std::string(home) + "/.config";
#endif #endif
);
} }
fn Config::getInstance() -> Config { fn Config::getInstance() -> Config {
const string path = GetConfigPath() + "\\draconis++\\config.toml"; try {
const Result<Config> result = rfl::toml::load<Config>(path); fs::path configPath = GetConfigPath();
configPath /= "draconis++/config.toml";
if (result) const Result<Config> result = rfl::toml::load<Config>(configPath.string());
return result.value();
if (result)
return result.value();
fmt::println("Failed to load config file: {}", result.error().value().what());
} catch (const std::exception& e) { fmt::println("Error getting config path: {}", e.what()); }
fmt::println("Failed to load config file: {}", result.error().value().what());
return {}; return {};
} }

View file

@ -48,7 +48,8 @@ fn main() -> i32 {
const Config& config = Config::getInstance(); const Config& config = Config::getInstance();
// Fetching weather information // Fetching weather information
auto weatherInfo = config.weather.get().getWeatherInfo(); auto weather = config.weather.get();
WeatherOutput weatherInfo = weather.getWeatherInfo();
// Fetching OS version // Fetching OS version
std::string osVersion = GetOSVersion(); std::string osVersion = GetOSVersion();
@ -69,17 +70,11 @@ fn main() -> i32 {
fmt::println("Installed RAM: {:.2f}", BytesToGiB(memInfo)); fmt::println("Installed RAM: {:.2f}", BytesToGiB(memInfo));
fmt::println("{}", osVersion); fmt::println("{}", osVersion);
if (config.weather.get().enabled) { if (weather.enabled)
const auto& [clouds, tz, visibility, main, coords, rain, snow, base, townName, weather, sys, cod, dt, id, wind] = fmt::println("It is {}°F in {}", std::lround(weatherInfo.main.temp), weatherInfo.name);
weatherInfo;
i64 temp = std::lround(main.temp);
fmt::println("It is {}°F in {}", temp, townName); if (nowPlayingEnabled)
}
if (nowPlayingEnabled) {
fmt::println("{}", GetNowPlaying()); fmt::println("{}", GetNowPlaying());
}
return 0; return 0;
} }

View file

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