updates/fixes
This commit is contained in:
parent
3ebbb2b3ec
commit
3f4b24c259
24
flake.nix
24
flake.nix
|
@ -23,15 +23,15 @@
|
||||||
then pkgs.stdenvAdapters.useMoldLinker pkgs.llvmPackages_18.stdenv
|
then pkgs.stdenvAdapters.useMoldLinker pkgs.llvmPackages_18.stdenv
|
||||||
else pkgs.llvmPackages_18.stdenv;
|
else pkgs.llvmPackages_18.stdenv;
|
||||||
|
|
||||||
reflect-cpp = stdenv.mkDerivation {
|
reflect-cpp = stdenv.mkDerivation rec {
|
||||||
name = "reflect-cpp";
|
name = "reflect-cpp";
|
||||||
version = "0.11.1";
|
version = "0.13.0";
|
||||||
|
|
||||||
src = pkgs.fetchFromGitHub {
|
src = pkgs.fetchFromGitHub {
|
||||||
owner = "getml";
|
owner = "getml";
|
||||||
repo = "reflect-cpp";
|
repo = "reflect-cpp";
|
||||||
rev = "1ce78479ac9d04eb396ad972d656858eb06661d2";
|
rev = "v${version}";
|
||||||
hash = "sha256-8TW2OlCbQZ07HypoYQE/wo29mxJWJwLziK1BpkhdFBo=";
|
hash = "sha256-dEqdPk5ixnNILxTcdSAOhzP8fzeefMu6pqrL/WgnPlE=";
|
||||||
};
|
};
|
||||||
|
|
||||||
nativeBuildInputs = with pkgs; [cmake ninja pkg-config];
|
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;
|
deps = with pkgs.pkgsStatic;
|
||||||
[
|
[
|
||||||
curl
|
curl
|
||||||
fmt
|
fmt_11
|
||||||
libiconv
|
libiconv
|
||||||
tomlplusplus
|
tomlplusplus
|
||||||
yyjson
|
yyjson
|
||||||
|
@ -55,8 +65,8 @@
|
||||||
++ linuxPkgs
|
++ linuxPkgs
|
||||||
++ darwinPkgs;
|
++ darwinPkgs;
|
||||||
|
|
||||||
linuxPkgs = nixpkgs.lib.optionals stdenv.isLinux (with pkgs.pkgsStatic; [
|
linuxPkgs = nixpkgs.lib.optionals stdenv.isLinux (with pkgs; [
|
||||||
glib
|
pkgsStatic.glib
|
||||||
systemdLibs
|
systemdLibs
|
||||||
sdbus-cpp
|
sdbus-cpp
|
||||||
valgrind
|
valgrind
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
#include <chrono>
|
||||||
#include <curl/curl.h>
|
#include <curl/curl.h>
|
||||||
#include <fmt/core.h>
|
#include <fmt/core.h>
|
||||||
#include <rfl/json.hpp>
|
#include <rfl/json.hpp>
|
||||||
|
@ -96,9 +97,9 @@ fn Weather::getWeatherInfo() const -> WeatherOutput {
|
||||||
|
|
||||||
// Check if cache is valid
|
// Check if cache is valid
|
||||||
if (Result<WeatherOutput> data = ReadCacheFromFile()) {
|
if (Result<WeatherOutput> data = ReadCacheFromFile()) {
|
||||||
if (WeatherOutput dataVal = *data;
|
WeatherOutput dataVal = *data;
|
||||||
system_clock::now() - system_clock::time_point(seconds(dataVal.dt)) <
|
|
||||||
minutes(10)) { // Assuming cache duration is always 10 minutes
|
if (system_clock::now() - system_clock::time_point(seconds(dataVal.dt)) < minutes(10)) {
|
||||||
fmt::println("Cache is valid. Returning cached data.");
|
fmt::println("Cache is valid. Returning cached data.");
|
||||||
|
|
||||||
return dataVal;
|
return dataVal;
|
||||||
|
|
|
@ -2,7 +2,6 @@
|
||||||
|
|
||||||
#include <rfl.hpp>
|
#include <rfl.hpp>
|
||||||
#include <rfl/toml.hpp>
|
#include <rfl/toml.hpp>
|
||||||
#include <string>
|
|
||||||
|
|
||||||
#include "../util/types.h"
|
#include "../util/types.h"
|
||||||
|
|
||||||
|
|
30
src/main.cpp
30
src/main.cpp
|
@ -1,6 +1,8 @@
|
||||||
#include <ctime>
|
#include <ctime>
|
||||||
#include <fmt/chrono.h>
|
#include <fmt/chrono.h>
|
||||||
#include <fmt/core.h>
|
#include <fmt/core.h>
|
||||||
|
#include <fmt/format.h>
|
||||||
|
#include <string>
|
||||||
|
|
||||||
#include "config/config.h"
|
#include "config/config.h"
|
||||||
#include "os/os.h"
|
#include "os/os.h"
|
||||||
|
@ -12,26 +14,30 @@ struct BytesToGiB {
|
||||||
constexpr u64 GIB = 1'073'741'824;
|
constexpr u64 GIB = 1'073'741'824;
|
||||||
|
|
||||||
template <>
|
template <>
|
||||||
struct fmt::formatter<BytesToGiB> : formatter<double> {
|
struct fmt::formatter<BytesToGiB> : fmt::formatter<double> {
|
||||||
template <typename FmtCtx>
|
template <typename FmtCtx>
|
||||||
fn format(const BytesToGiB BTG, FmtCtx& ctx) -> typename FmtCtx::iterator {
|
constexpr auto format(const BytesToGiB& BTG, FmtCtx& ctx) const -> typename FmtCtx::iterator {
|
||||||
typename FmtCtx::iterator out =
|
auto out = fmt::formatter<double>::format(static_cast<double>(BTG.value) / GIB, ctx);
|
||||||
formatter<double>::format(static_cast<double>(BTG.value) / GIB, ctx);
|
*out++ = 'G';
|
||||||
*out++ = 'G';
|
*out++ = 'i';
|
||||||
*out++ = 'i';
|
*out++ = 'B';
|
||||||
*out++ = 'B';
|
|
||||||
return out;
|
return out;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
fn GetDate() -> string {
|
fn GetDate() -> std::string {
|
||||||
const std::tm localTime = fmt::localtime(time(nullptr));
|
// 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()))
|
if (!date.empty() && std::isspace(date.front()))
|
||||||
date.erase(date.begin());
|
date.erase(date.begin());
|
||||||
|
|
||||||
|
// Append appropriate suffix for the date
|
||||||
if (date == "1" || date == "21" || date == "31")
|
if (date == "1" || date == "21" || date == "31")
|
||||||
date += "st";
|
date += "st";
|
||||||
else if (date == "2" || date == "22")
|
else if (date == "2" || date == "22")
|
||||||
|
@ -41,7 +47,7 @@ fn GetDate() -> string {
|
||||||
else
|
else
|
||||||
date += "th";
|
date += "th";
|
||||||
|
|
||||||
return fmt::format("{:%B} {}, {:%-I:%0M %p}", localTime, date, localTime);
|
return fmt::format("{:%B} {}", localTime, date);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn main() -> i32 {
|
fn main() -> i32 {
|
||||||
|
@ -68,7 +74,7 @@ fn main() -> i32 {
|
||||||
fmt::println("Hello {}!", name);
|
fmt::println("Hello {}!", name);
|
||||||
fmt::println("Today is: {}", date);
|
fmt::println("Today is: {}", date);
|
||||||
fmt::println("Installed RAM: {:.2f}", BytesToGiB(memInfo));
|
fmt::println("Installed RAM: {:.2f}", BytesToGiB(memInfo));
|
||||||
fmt::println("{}", osVersion);
|
fmt::println("OS: {}", osVersion);
|
||||||
|
|
||||||
if (weather.enabled)
|
if (weather.enabled)
|
||||||
fmt::println("It is {}°F in {}", std::lround(weatherInfo.main.temp), weatherInfo.name);
|
fmt::println("It is {}°F in {}", std::lround(weatherInfo.main.temp), weatherInfo.name);
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
#ifdef __linux__
|
#ifdef __linux__
|
||||||
|
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
|
#include <fmt/format.h>
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <sdbus-c++/sdbus-c++.h>
|
#include <sdbus-c++/sdbus-c++.h>
|
||||||
|
@ -66,8 +67,9 @@ fn GetOSVersion() -> string {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn GetMprisPlayers(sdbus::IConnection& connection) -> std::vector<string> {
|
fn GetMprisPlayers(sdbus::IConnection& connection) -> std::vector<string> {
|
||||||
const char *dbusInterface = "org.freedesktop.DBus", *dbusObjectPath = "/org/freedesktop/DBus",
|
const sdbus::ServiceName dbusInterface = sdbus::ServiceName("org.freedesktop.DBus");
|
||||||
*dbusMethodListNames = "ListNames";
|
const sdbus::ObjectPath dbusObjectPath = sdbus::ObjectPath("/org/freedesktop/DBus");
|
||||||
|
const char* dbusMethodListNames = "ListNames";
|
||||||
|
|
||||||
const std::unique_ptr<sdbus::IProxy> dbusProxy =
|
const std::unique_ptr<sdbus::IProxy> dbusProxy =
|
||||||
createProxy(connection, dbusInterface, dbusObjectPath);
|
createProxy(connection, dbusInterface, dbusObjectPath);
|
||||||
|
@ -80,7 +82,7 @@ fn GetMprisPlayers(sdbus::IConnection& connection) -> std::vector<string> {
|
||||||
|
|
||||||
for (const std::basic_string<char>& name : names)
|
for (const std::basic_string<char>& name : names)
|
||||||
if (const char* mprisInterfaceName = "org.mpris.MediaPlayer2";
|
if (const char* mprisInterfaceName = "org.mpris.MediaPlayer2";
|
||||||
name.contains(mprisInterfaceName))
|
name.find(mprisInterfaceName) != std::string::npos)
|
||||||
mprisPlayers.push_back(name);
|
mprisPlayers.push_back(name);
|
||||||
|
|
||||||
return mprisPlayers;
|
return mprisPlayers;
|
||||||
|
@ -110,17 +112,27 @@ fn GetNowPlaying() -> string {
|
||||||
if (activePlayer.empty())
|
if (activePlayer.empty())
|
||||||
return "";
|
return "";
|
||||||
|
|
||||||
std::unique_ptr<sdbus::IProxy> playerProxy =
|
auto playerProxy = sdbus::createProxy(
|
||||||
sdbus::createProxy(*connection, activePlayer, playerObjectPath);
|
*connection, sdbus::ServiceName(activePlayer), sdbus::ObjectPath(playerObjectPath)
|
||||||
|
);
|
||||||
|
|
||||||
std::map<string, sdbus::Variant> metadata =
|
sdbus::Variant metadataVariant =
|
||||||
playerProxy->getProperty("Metadata").onInterface(playerInterfaceName);
|
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>())
|
auto iter = metadata.find("xesam:title");
|
||||||
return iter->second.get<string>();
|
|
||||||
} catch (const sdbus::Error& e) { std::cerr << "Error: " << e.what() << '\n'; }
|
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 "";
|
return "";
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue