updates/fixes

This commit is contained in:
Mars 2024-07-31 00:07:40 -04:00
parent 3ebbb2b3ec
commit 3f4b24c259
Signed by: pupbrained
GPG key ID: 0FF5B8826803F895
5 changed files with 61 additions and 33 deletions

View file

@ -23,15 +23,15 @@
then pkgs.stdenvAdapters.useMoldLinker pkgs.llvmPackages_18.stdenv
else pkgs.llvmPackages_18.stdenv;
reflect-cpp = stdenv.mkDerivation {
reflect-cpp = stdenv.mkDerivation rec {
name = "reflect-cpp";
version = "0.11.1";
version = "0.13.0";
src = pkgs.fetchFromGitHub {
owner = "getml";
repo = "reflect-cpp";
rev = "1ce78479ac9d04eb396ad972d656858eb06661d2";
hash = "sha256-8TW2OlCbQZ07HypoYQE/wo29mxJWJwLziK1BpkhdFBo=";
rev = "v${version}";
hash = "sha256-dEqdPk5ixnNILxTcdSAOhzP8fzeefMu6pqrL/WgnPlE=";
};
nativeBuildInputs = with pkgs; [cmake ninja pkg-config];
@ -43,10 +43,20 @@
];
};
sdbus-cpp = pkgs.sdbus-cpp.overrideAttrs rec {
version = "2.0.0";
src = pkgs.fetchFromGitHub {
owner = "kistler-group";
repo = "sdbus-cpp";
rev = "v${version}";
hash = "sha256-W8V5FRhV3jtERMFrZ4gf30OpIQLYoj2yYGpnYOmH2+g=";
};
};
deps = with pkgs.pkgsStatic;
[
curl
fmt
fmt_11
libiconv
tomlplusplus
yyjson
@ -55,8 +65,8 @@
++ linuxPkgs
++ darwinPkgs;
linuxPkgs = nixpkgs.lib.optionals stdenv.isLinux (with pkgs.pkgsStatic; [
glib
linuxPkgs = nixpkgs.lib.optionals stdenv.isLinux (with pkgs; [
pkgsStatic.glib
systemdLibs
sdbus-cpp
valgrind

View file

@ -1,3 +1,4 @@
#include <chrono>
#include <curl/curl.h>
#include <fmt/core.h>
#include <rfl/json.hpp>
@ -96,9 +97,9 @@ fn Weather::getWeatherInfo() const -> WeatherOutput {
// Check if cache is valid
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
WeatherOutput dataVal = *data;
if (system_clock::now() - system_clock::time_point(seconds(dataVal.dt)) < minutes(10)) {
fmt::println("Cache is valid. Returning cached data.");
return dataVal;

View file

@ -2,7 +2,6 @@
#include <rfl.hpp>
#include <rfl/toml.hpp>
#include <string>
#include "../util/types.h"

View file

@ -1,6 +1,8 @@
#include <ctime>
#include <fmt/chrono.h>
#include <fmt/core.h>
#include <fmt/format.h>
#include <string>
#include "config/config.h"
#include "os/os.h"
@ -12,26 +14,30 @@ struct BytesToGiB {
constexpr u64 GIB = 1'073'741'824;
template <>
struct fmt::formatter<BytesToGiB> : formatter<double> {
struct fmt::formatter<BytesToGiB> : fmt::formatter<double> {
template <typename FmtCtx>
fn format(const BytesToGiB BTG, FmtCtx& ctx) -> typename FmtCtx::iterator {
typename FmtCtx::iterator out =
formatter<double>::format(static_cast<double>(BTG.value) / GIB, ctx);
*out++ = 'G';
*out++ = 'i';
*out++ = 'B';
constexpr auto format(const BytesToGiB& BTG, FmtCtx& ctx) const -> typename FmtCtx::iterator {
auto out = fmt::formatter<double>::format(static_cast<double>(BTG.value) / GIB, ctx);
*out++ = 'G';
*out++ = 'i';
*out++ = 'B';
return out;
}
};
fn GetDate() -> string {
const std::tm localTime = fmt::localtime(time(nullptr));
fn GetDate() -> std::string {
// Get current local time
std::time_t now = std::time(nullptr);
std::tm localTime = *std::localtime(&now);
string date = fmt::format("{:%e}", localTime);
// Format the date using fmt::format
std::string date = fmt::format("{:%e}", localTime);
// Remove leading whitespace
if (!date.empty() && std::isspace(date.front()))
date.erase(date.begin());
// Append appropriate suffix for the date
if (date == "1" || date == "21" || date == "31")
date += "st";
else if (date == "2" || date == "22")
@ -41,7 +47,7 @@ fn GetDate() -> string {
else
date += "th";
return fmt::format("{:%B} {}, {:%-I:%0M %p}", localTime, date, localTime);
return fmt::format("{:%B} {}", localTime, date);
}
fn main() -> i32 {
@ -68,7 +74,7 @@ fn main() -> i32 {
fmt::println("Hello {}!", name);
fmt::println("Today is: {}", date);
fmt::println("Installed RAM: {:.2f}", BytesToGiB(memInfo));
fmt::println("{}", osVersion);
fmt::println("OS: {}", osVersion);
if (weather.enabled)
fmt::println("It is {}°F in {}", std::lround(weatherInfo.main.temp), weatherInfo.name);

View file

@ -1,6 +1,7 @@
#ifdef __linux__
#include <cstring>
#include <fmt/format.h>
#include <fstream>
#include <iostream>
#include <sdbus-c++/sdbus-c++.h>
@ -66,8 +67,9 @@ fn GetOSVersion() -> string {
}
fn GetMprisPlayers(sdbus::IConnection& connection) -> std::vector<string> {
const char *dbusInterface = "org.freedesktop.DBus", *dbusObjectPath = "/org/freedesktop/DBus",
*dbusMethodListNames = "ListNames";
const sdbus::ServiceName dbusInterface = sdbus::ServiceName("org.freedesktop.DBus");
const sdbus::ObjectPath dbusObjectPath = sdbus::ObjectPath("/org/freedesktop/DBus");
const char* dbusMethodListNames = "ListNames";
const std::unique_ptr<sdbus::IProxy> dbusProxy =
createProxy(connection, dbusInterface, dbusObjectPath);
@ -80,7 +82,7 @@ fn GetMprisPlayers(sdbus::IConnection& connection) -> std::vector<string> {
for (const std::basic_string<char>& name : names)
if (const char* mprisInterfaceName = "org.mpris.MediaPlayer2";
name.contains(mprisInterfaceName))
name.find(mprisInterfaceName) != std::string::npos)
mprisPlayers.push_back(name);
return mprisPlayers;
@ -110,17 +112,27 @@ fn GetNowPlaying() -> string {
if (activePlayer.empty())
return "";
std::unique_ptr<sdbus::IProxy> playerProxy =
sdbus::createProxy(*connection, activePlayer, playerObjectPath);
auto playerProxy = sdbus::createProxy(
*connection, sdbus::ServiceName(activePlayer), sdbus::ObjectPath(playerObjectPath)
);
std::map<string, sdbus::Variant> metadata =
sdbus::Variant metadataVariant =
playerProxy->getProperty("Metadata").onInterface(playerInterfaceName);
if (const auto iter = metadata.find("xesam:title");
if (metadataVariant.containsValueOfType<std::map<std::string, sdbus::Variant>>()) {
const auto& metadata = metadataVariant.get<std::map<std::string, sdbus::Variant>>();
iter != metadata.end() && iter->second.containsValueOfType<string>())
return iter->second.get<string>();
} catch (const sdbus::Error& e) { std::cerr << "Error: " << e.what() << '\n'; }
auto iter = metadata.find("xesam:title");
if (iter != metadata.end() && iter->second.containsValueOfType<std::string>())
return iter->second.get<std::string>();
}
} catch (const sdbus::Error& e) {
if (e.getName() != "com.github.altdesktop.playerctld.NoActivePlayer")
return fmt::format("Error: {}", e.what());
return "No active player";
}
return "";
}