From a743cdabe57e36b0647d2fa409dd42d8c38ff632 Mon Sep 17 00:00:00 2001 From: Mars <mars@pupbrained.xyz> Date: Sat, 8 Jun 2024 04:57:32 -0400 Subject: [PATCH] bleh --- .clang-format | 3 +++ flake.nix | 26 ++++++------------- meson.build | 24 +++-------------- src/config/weather.cpp | 10 +++---- src/main.cpp | 15 +++-------- src/os/linux.cpp | 10 +++---- src/os/macos.cpp | 12 ++++----- ...owPlayingBridge.h => now_playing_bridge.h} | 0 ...PlayingBridge.mm => now_playing_bridge.mm} | 2 +- 9 files changed, 32 insertions(+), 70 deletions(-) rename src/os/macos/{NowPlayingBridge.h => now_playing_bridge.h} (100%) rename src/os/macos/{NowPlayingBridge.mm => now_playing_bridge.mm} (98%) diff --git a/.clang-format b/.clang-format index 079241b..a77eca4 100644 --- a/.clang-format +++ b/.clang-format @@ -1,5 +1,8 @@ --- AlignConsecutiveAssignments: true +AllowShortBlocksOnASingleLine: Always +AllowShortCompoundRequirementOnASingleLine: true +AllowShortIfStatementsOnASingleLine: WithoutElse AllowShortLoopsOnASingleLine: true BasedOnStyle: Chromium IndentAccessModifiers: false diff --git a/flake.nix b/flake.nix index abf0984..7140bd4 100644 --- a/flake.nix +++ b/flake.nix @@ -63,7 +63,9 @@ glib tomlplusplus yyjson - ]; + ] + ++ linuxPkgs + ++ darwinPkgs; linuxPkgs = nixpkgs.lib.optionals stdenv.isLinux (with pkgs; [ systemdLibs @@ -78,7 +80,7 @@ in with pkgs; { packages = rec { - draconis-cpp = stdenv.mkDerivation { + draconisplusplus = stdenv.mkDerivation { name = "draconis++"; version = "0.1.0"; src = self; @@ -89,17 +91,7 @@ pkg-config ]; - propagatedBuildInputs = [ - tomlplusplus - ]; - - buildInputs = - [ - coost - fmt - ] - ++ darwinPkgs - ++ linuxPkgs; + buildInputs = deps; configurePhase = '' meson setup build @@ -115,7 +107,7 @@ ''; }; - default = draconis-cpp; + default = draconisplusplus; }; formatter = alejandra; @@ -126,8 +118,8 @@ alejandra bear clang-tools_18 - meson lldb + meson ninja pkg-config unzip @@ -136,9 +128,7 @@ (writeScriptBin "clean" "meson setup build --wipe") (writeScriptBin "run" "meson compile -C build && build/draconis++") ] - ++ deps - ++ darwinPkgs - ++ linuxPkgs; + ++ deps; name = "C++"; }; diff --git a/meson.build b/meson.build index 2fddf49..dd4c44b 100644 --- a/meson.build +++ b/meson.build @@ -53,9 +53,7 @@ add_project_arguments( source_file_names = [ 'src/main.cpp', - 'src/os/os.h', 'src/config/config.cpp', - 'src/config/config.h', 'src/config/weather.cpp' ] @@ -66,8 +64,7 @@ endif if host_machine.system() == 'darwin' source_file_names += [ 'src/os/macos.cpp', - 'src/os/macos/NowPlayingBridge.h', - 'src/os/macos/NowPlayingBridge.mm' + 'src/os/macos/now_playing_bridge.mm', ] endif @@ -84,23 +81,10 @@ libcurl = dependency('libcurl', required: false) tomlpp = dependency('tomlplusplus', required: false) yyjson = dependency('yyjson', required: false) -if not fmt.found() - fmt = cpp.find_library('fmt', required: true) -endif - -if not libcurl.found() - libcurl = cpp.find_library('curl', required: true) -endif - -if not tomlpp.found() - tomlpp = cpp.find_library('tomlplusplus', required: true) -endif - -if not yyjson.found() - yyjson = cpp.find_library('yyjson', required: true) -endif - foreach dep : [fmt, libcurl, tomlpp, yyjson] + if not dep.found() + dep = cpp.find_library(dep.name(), required: true) + endif deps += dep endforeach diff --git a/src/config/weather.cpp b/src/config/weather.cpp index 8d2a880..879cd9d 100644 --- a/src/config/weather.cpp +++ b/src/config/weather.cpp @@ -12,8 +12,7 @@ Result<WeatherOutput> ReadCacheFromFile() { const std::string cacheFile = "/tmp/weather_cache.json"; std::ifstream ifs(cacheFile); - if (!ifs.is_open()) - return Error("Cache file not found."); + if (!ifs.is_open()) return Error("Cache file not found."); fmt::println("Reading from cache file..."); @@ -25,9 +24,7 @@ Result<WeatherOutput> ReadCacheFromFile() { buf << ifs.rdbuf(); val = rfl::json::read<WeatherOutput>(buf.str()).value(); - } catch (Error& e) { - return e; - } + } catch (Error& e) { return e; } fmt::println("Successfully read from cache file."); @@ -40,8 +37,7 @@ Result<> WriteCacheToFile(const WeatherOutput& data) { fmt::println("Writing to cache file..."); std::ofstream ofs(cacheFile); - if (!ofs.is_open()) - return Error("Failed to open cache file for writing."); + if (!ofs.is_open()) return Error("Failed to open cache file for writing."); ofs << rfl::json::write(data); diff --git a/src/main.cpp b/src/main.cpp index aa8c802..2694b90 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -28,23 +28,16 @@ struct fmt::formatter<BytesToGiB> : formatter<double> { enum DateNum { Ones, Twos, Threes, Default }; DateNum ParseDate(string const& input) { - if (input == "1" || input == "21" || input == "31") - return Ones; - - if (input == "2" || input == "22") - return Twos; - - if (input == "3" || input == "23") - return Threes; - + if (input == "1" || input == "21" || input == "31") return Ones; + if (input == "2" || input == "22") return Twos; + if (input == "3" || input == "23") return Threes; return Default; } int main() { const Config& config = Config::getInstance(); - if (config.getNowPlaying().getEnabled()) - fmt::println("{}", GetNowPlaying()); + if (config.getNowPlaying().getEnabled()) fmt::println("{}", GetNowPlaying()); fmt::println("Hello {}!", config.getGeneral().getName()); diff --git a/src/os/linux.cpp b/src/os/linux.cpp index 21aae2e..c95b1e1 100644 --- a/src/os/linux.cpp +++ b/src/os/linux.cpp @@ -1,6 +1,5 @@ #ifdef __linux__ -#include <fmt/core.h> #include <fstream> #include <iostream> #include <sdbus-c++/sdbus-c++.h> @@ -70,8 +69,7 @@ std::vector<std::string> GetMprisPlayers(sdbus::IConnection& connection) { } std::string GetActivePlayer(const std::vector<std::string>& mprisPlayers) { - if (!mprisPlayers.empty()) - return mprisPlayers.front(); + if (!mprisPlayers.empty()) return mprisPlayers.front(); return ""; } @@ -83,13 +81,11 @@ std::string GetNowPlaying() { std::vector<std::string> mprisPlayers = GetMprisPlayers(*connection); - if (mprisPlayers.empty()) - return ""; + if (mprisPlayers.empty()) return ""; std::string activePlayer = GetActivePlayer(mprisPlayers); - if (activePlayer.empty()) - return ""; + if (activePlayer.empty()) return ""; std::unique_ptr<sdbus::IProxy> playerProxy = sdbus::createProxy(*connection, activePlayer, PLAYER_OBJECT_PATH); diff --git a/src/os/macos.cpp b/src/os/macos.cpp index fcc2e82..2dfe4f9 100644 --- a/src/os/macos.cpp +++ b/src/os/macos.cpp @@ -1,14 +1,13 @@ #ifdef __APPLE__ -#include <string> #include <sys/sysctl.h> -#include "macos/NowPlayingBridge.h" +#include "macos/now_playing_bridge.h" #include "os.h" u64 GetMemInfo() { - uint64_t mem = 0; - size_t size = sizeof(mem); + u64 mem = 0; + usize size = sizeof(mem); sysctlbyname("hw.memsize", &mem, &size, nullptr, 0); @@ -16,8 +15,9 @@ u64 GetMemInfo() { } std::string GetNowPlaying() { - if (const char* title = GetCurrentPlayingTitle()) - return title; + if (const char* title = GetCurrentPlayingTitle(); + const char* artist = GetCurrentPlayingArtist()) + return "Now Playing: " + std::string(artist) + " - " + std::string(title); return "No song playing"; } diff --git a/src/os/macos/NowPlayingBridge.h b/src/os/macos/now_playing_bridge.h similarity index 100% rename from src/os/macos/NowPlayingBridge.h rename to src/os/macos/now_playing_bridge.h diff --git a/src/os/macos/NowPlayingBridge.mm b/src/os/macos/now_playing_bridge.mm similarity index 98% rename from src/os/macos/NowPlayingBridge.mm rename to src/os/macos/now_playing_bridge.mm index 0ca7bd1..052f051 100644 --- a/src/os/macos/NowPlayingBridge.mm +++ b/src/os/macos/now_playing_bridge.mm @@ -1,6 +1,6 @@ #ifdef __APPLE__ -#import "NowPlayingBridge.h" +#import "now_playing_bridge.h" #import <Foundation/Foundation.h> #import <dispatch/dispatch.h> #import <objc/runtime.h>