remove playerctl lol
This commit is contained in:
parent
500138ce67
commit
3071b23b93
55
flake.nix
55
flake.nix
|
@ -46,9 +46,27 @@
|
||||||
];
|
];
|
||||||
};
|
};
|
||||||
|
|
||||||
stdenv = pkgs.llvmPackages_18.stdenv;
|
stdenv = pkgs.stdenvAdapters.useMoldLinker pkgs.llvmPackages_18.stdenv;
|
||||||
|
|
||||||
darwinPkgs = nixpkgs.lib.optionals pkgs.stdenv.isDarwin (with pkgs.darwin; [
|
deps = with (
|
||||||
|
if !stdenv.isDarwin
|
||||||
|
then pkgs.pkgsStatic
|
||||||
|
else pkgs
|
||||||
|
); # TODO: Remove when fixed on darwin
|
||||||
|
|
||||||
|
[
|
||||||
|
coost
|
||||||
|
fmt
|
||||||
|
glib
|
||||||
|
libcpr
|
||||||
|
tomlplusplus
|
||||||
|
]
|
||||||
|
++ (with pkgs; (lib.optionals hostPlatform.isLinux [
|
||||||
|
sdbus-cpp
|
||||||
|
valgrind
|
||||||
|
]));
|
||||||
|
|
||||||
|
darwinPkgs = nixpkgs.lib.optionals stdenv.isDarwin (with pkgs.darwin; [
|
||||||
apple_sdk.frameworks.CoreFoundation
|
apple_sdk.frameworks.CoreFoundation
|
||||||
apple_sdk.frameworks.MediaPlayer
|
apple_sdk.frameworks.MediaPlayer
|
||||||
]);
|
]);
|
||||||
|
@ -66,15 +84,10 @@
|
||||||
pkg-config
|
pkg-config
|
||||||
];
|
];
|
||||||
|
|
||||||
propagatedBuildInputs =
|
propagatedBuildInputs = [
|
||||||
[
|
libcpr
|
||||||
libcpr
|
tomlplusplus
|
||||||
tomlplusplus
|
];
|
||||||
]
|
|
||||||
++ (lib.optionals pkgs.hostPlatform.isLinux [
|
|
||||||
glib
|
|
||||||
playerctl
|
|
||||||
]);
|
|
||||||
|
|
||||||
buildInputs = [
|
buildInputs = [
|
||||||
coost
|
coost
|
||||||
|
@ -107,24 +120,16 @@
|
||||||
bear
|
bear
|
||||||
clang-tools_18
|
clang-tools_18
|
||||||
meson
|
meson
|
||||||
|
lldb
|
||||||
ninja
|
ninja
|
||||||
pkg-config
|
pkg-config
|
||||||
|
unzip
|
||||||
|
|
||||||
coost
|
(writeScriptBin "build" "meson compile -C build")
|
||||||
fmt
|
(writeScriptBin "clean" "meson setup build --wipe")
|
||||||
glib
|
(writeScriptBin "run" "meson compile -C build && build/draconis++")
|
||||||
libcpr
|
|
||||||
tomlplusplus
|
|
||||||
]
|
|
||||||
++ (lib.optionals pkgs.hostPlatform.isLinux [playerctl])
|
|
||||||
++ darwinPkgs;
|
|
||||||
|
|
||||||
buildInputs =
|
|
||||||
[
|
|
||||||
coost
|
|
||||||
libcpr
|
|
||||||
tomlplusplus
|
|
||||||
]
|
]
|
||||||
|
++ deps
|
||||||
++ darwinPkgs;
|
++ darwinPkgs;
|
||||||
|
|
||||||
name = "C++";
|
name = "C++";
|
||||||
|
|
55
meson.build
55
meson.build
|
@ -1,5 +1,5 @@
|
||||||
project(
|
project(
|
||||||
'draconis++', ['cpp', 'objcpp'],
|
'draconis++', 'cpp',
|
||||||
version: '0.1.0',
|
version: '0.1.0',
|
||||||
default_options: [
|
default_options: [
|
||||||
'objc_std=c++20',
|
'objc_std=c++20',
|
||||||
|
@ -14,21 +14,26 @@ project(
|
||||||
clangtidy = find_program('clang-tidy', required: false)
|
clangtidy = find_program('clang-tidy', required: false)
|
||||||
|
|
||||||
cpp = meson.get_compiler('cpp')
|
cpp = meson.get_compiler('cpp')
|
||||||
objcpp = meson.get_compiler('objcpp')
|
|
||||||
|
|
||||||
add_project_arguments(
|
if host_machine.system() == 'darwin'
|
||||||
objcpp.get_supported_arguments([
|
add_language('objcpp')
|
||||||
'-Wno-c++20-compat',
|
|
||||||
'-Wno-c++98-compat',
|
objcpp = meson.get_compiler('objcpp')
|
||||||
'-Wno-c++98-compat-pedantic',
|
|
||||||
'-Wno-missing-prototypes',
|
add_project_arguments(
|
||||||
'-Wno-padded',
|
objcpp.get_supported_arguments([
|
||||||
'-Wno-pre-c++20-compat-pedantic',
|
'-Wno-c++20-compat',
|
||||||
'-Wno-switch-default',
|
'-Wno-c++98-compat',
|
||||||
'-Wunused-function',
|
'-Wno-c++98-compat-pedantic',
|
||||||
]),
|
'-Wno-missing-prototypes',
|
||||||
language: 'objcpp'
|
'-Wno-padded',
|
||||||
)
|
'-Wno-pre-c++20-compat-pedantic',
|
||||||
|
'-Wno-switch-default',
|
||||||
|
'-Wunused-function',
|
||||||
|
]),
|
||||||
|
language: 'objcpp'
|
||||||
|
)
|
||||||
|
endif
|
||||||
|
|
||||||
add_project_arguments(
|
add_project_arguments(
|
||||||
cpp.get_supported_arguments([
|
cpp.get_supported_arguments([
|
||||||
|
@ -77,12 +82,14 @@ deps += cpp.find_library('curl')
|
||||||
deps += cpp.find_library('tomlplusplus')
|
deps += cpp.find_library('tomlplusplus')
|
||||||
deps += dependency('coost')
|
deps += dependency('coost')
|
||||||
deps += dependency('fmt')
|
deps += dependency('fmt')
|
||||||
deps += dependency('Foundation')
|
|
||||||
deps += dependency('MediaPlayer')
|
|
||||||
|
|
||||||
|
if host_machine.system() == 'darwin'
|
||||||
|
deps += dependency('Foundation')
|
||||||
|
deps += dependency('MediaPlayer')
|
||||||
|
endif
|
||||||
|
|
||||||
if host_machine.system() == 'linux'
|
if host_machine.system() == 'linux'
|
||||||
deps += dependency('playerctl')
|
deps += dependency('sdbus-c++')
|
||||||
endif
|
endif
|
||||||
|
|
||||||
incdir = include_directories(
|
incdir = include_directories(
|
||||||
|
@ -90,11 +97,19 @@ incdir = include_directories(
|
||||||
is_system: true # Ignores warnings from include dir
|
is_system: true # Ignores warnings from include dir
|
||||||
)
|
)
|
||||||
|
|
||||||
|
objc_args = []
|
||||||
|
link_args = []
|
||||||
|
|
||||||
|
if host_machine.system() == 'darwin'
|
||||||
|
objc_args += ['-fobjc-arc']
|
||||||
|
link_args += ['-framework', 'Foundation', '-framework', 'MediaPlayer']
|
||||||
|
endif
|
||||||
|
|
||||||
executable(
|
executable(
|
||||||
'draconis++',
|
'draconis++',
|
||||||
sources,
|
sources,
|
||||||
|
objc_args,
|
||||||
|
link_args,
|
||||||
dependencies: deps,
|
dependencies: deps,
|
||||||
include_directories: incdir,
|
include_directories: incdir,
|
||||||
objc_args: ['-fobjc-arc'],
|
|
||||||
link_args: ['-framework', 'Foundation', '-framework', 'MediaPlayer']
|
|
||||||
)
|
)
|
||||||
|
|
|
@ -45,8 +45,6 @@ DateNum ParseDate(string const& input) {
|
||||||
int main(int argc, char** argv) {
|
int main(int argc, char** argv) {
|
||||||
flag::parse(argc, argv);
|
flag::parse(argc, argv);
|
||||||
|
|
||||||
LOG << "hello " << 23;
|
|
||||||
|
|
||||||
const Config& config = Config::getInstance();
|
const Config& config = Config::getInstance();
|
||||||
|
|
||||||
if (config.getNowPlaying().getEnabled())
|
if (config.getNowPlaying().getEnabled())
|
||||||
|
|
|
@ -2,12 +2,22 @@
|
||||||
|
|
||||||
#include <fmt/core.h>
|
#include <fmt/core.h>
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
#include <playerctl/playerctl.h>
|
#include <iostream>
|
||||||
|
#include <sdbus-c++/sdbus-c++.h>
|
||||||
|
#include <string>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
#include "os.h"
|
#include "os.h"
|
||||||
|
|
||||||
using std::string;
|
using std::string;
|
||||||
|
|
||||||
|
static const char *DBUS_INTERFACE = "org.freedesktop.DBus",
|
||||||
|
*DBUS_OBJECT_PATH = "/org/freedesktop/DBus",
|
||||||
|
*DBUS_METHOD_LIST_NAMES = "ListNames",
|
||||||
|
*MPRIS_INTERFACE_NAME = "org.mpris.MediaPlayer2",
|
||||||
|
*PLAYER_OBJECT_PATH = "/org/mpris/MediaPlayer2",
|
||||||
|
*PLAYER_INTERFACE_NAME = "org.mpris.MediaPlayer2.Player";
|
||||||
|
|
||||||
uint64_t ParseLineAsNumber(const string& input) {
|
uint64_t ParseLineAsNumber(const string& input) {
|
||||||
// Find the first number
|
// Find the first number
|
||||||
string::size_type start = 0;
|
string::size_type start = 0;
|
||||||
|
@ -44,46 +54,59 @@ uint64_t GetMemInfo() {
|
||||||
return MeminfoParse(std::ifstream("/proc/meminfo")) * 1024;
|
return MeminfoParse(std::ifstream("/proc/meminfo")) * 1024;
|
||||||
}
|
}
|
||||||
|
|
||||||
PlayerctlPlayer* InitPlayerctl() {
|
std::vector<std::string> GetMprisPlayers(sdbus::IConnection& connection) {
|
||||||
// Create a player manager
|
auto dbusProxy =
|
||||||
PlayerctlPlayerManager* playerManager = playerctl_player_manager_new(nullptr);
|
sdbus::createProxy(connection, DBUS_INTERFACE, DBUS_OBJECT_PATH);
|
||||||
|
std::vector<std::string> names;
|
||||||
|
dbusProxy->callMethod(DBUS_METHOD_LIST_NAMES)
|
||||||
|
.onInterface(DBUS_INTERFACE)
|
||||||
|
.storeResultsTo(names);
|
||||||
|
|
||||||
// Create an empty player list
|
std::vector<std::string> mprisPlayers;
|
||||||
GList* availablePlayers = nullptr;
|
for (const auto& name : names) {
|
||||||
|
if (name.find(MPRIS_INTERFACE_NAME) != std::string::npos) {
|
||||||
// Get the list of available players and put it in the player list
|
mprisPlayers.push_back(name);
|
||||||
g_object_get(playerManager, "player-names", &availablePlayers, nullptr);
|
}
|
||||||
|
}
|
||||||
// If no players are available, return nullptr
|
return mprisPlayers;
|
||||||
if (!availablePlayers)
|
|
||||||
return nullptr;
|
|
||||||
|
|
||||||
// Get the first player
|
|
||||||
PlayerctlPlayerName* playerName =
|
|
||||||
static_cast<PlayerctlPlayerName*>(availablePlayers->data);
|
|
||||||
|
|
||||||
// Create the player
|
|
||||||
PlayerctlPlayer* const currentPlayer =
|
|
||||||
playerctl_player_new_from_name(playerName, nullptr);
|
|
||||||
|
|
||||||
// If no player is available, return nullptr
|
|
||||||
if (!currentPlayer)
|
|
||||||
return nullptr;
|
|
||||||
|
|
||||||
// Manage the player
|
|
||||||
playerctl_player_manager_manage_player(playerManager, currentPlayer);
|
|
||||||
|
|
||||||
// Unref the player
|
|
||||||
g_object_unref(currentPlayer);
|
|
||||||
|
|
||||||
return currentPlayer;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
string GetNowPlaying() {
|
std::string GetActivePlayer(const std::vector<std::string>& mprisPlayers) {
|
||||||
if (PlayerctlPlayer* currentPlayer = InitPlayerctl())
|
if (!mprisPlayers.empty()) {
|
||||||
return playerctl_player_get_title(currentPlayer, nullptr);
|
return mprisPlayers.front();
|
||||||
|
}
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
|
||||||
return "Could not get now playing info";
|
std::string GetNowPlaying() {
|
||||||
|
try {
|
||||||
|
auto connection = sdbus::createSessionBusConnection();
|
||||||
|
auto mprisPlayers = GetMprisPlayers(*connection);
|
||||||
|
|
||||||
|
if (mprisPlayers.empty())
|
||||||
|
return "";
|
||||||
|
|
||||||
|
std::string activePlayer = GetActivePlayer(mprisPlayers);
|
||||||
|
|
||||||
|
if (activePlayer.empty())
|
||||||
|
return "";
|
||||||
|
|
||||||
|
auto playerProxy =
|
||||||
|
sdbus::createProxy(*connection, activePlayer, PLAYER_OBJECT_PATH);
|
||||||
|
|
||||||
|
std::map<std::string, sdbus::Variant> metadata =
|
||||||
|
playerProxy->getProperty("Metadata").onInterface(PLAYER_INTERFACE_NAME);
|
||||||
|
|
||||||
|
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) {
|
||||||
|
std::cerr << "Error: " << e.what() << std::endl;
|
||||||
|
}
|
||||||
|
|
||||||
|
return "";
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -16,7 +16,7 @@ uint64_t GetMemInfo() {
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string GetNowPlaying() {
|
std::string GetNowPlaying() {
|
||||||
return getCurrentPlayingTitle();
|
return GetCurrentPlayingTitle();
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -8,7 +8,7 @@
|
||||||
@end
|
@end
|
||||||
#else
|
#else
|
||||||
extern "C" {
|
extern "C" {
|
||||||
const char* getCurrentPlayingTitle();
|
const char* GetCurrentPlayingTitle();
|
||||||
const char* getCurrentPlayingArtist();
|
const char* GetCurrentPlayingArtist();
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -62,7 +62,7 @@ typedef void (*MRMediaRemoteGetNowPlayingInfoFunction)(
|
||||||
|
|
||||||
extern "C" {
|
extern "C" {
|
||||||
|
|
||||||
const char *getCurrentPlayingTitle() {
|
const char *GetCurrentPlayingTitle() {
|
||||||
NSDictionary *metadata = [NowPlayingBridge currentPlayingMetadata];
|
NSDictionary *metadata = [NowPlayingBridge currentPlayingMetadata];
|
||||||
if (metadata == nil) {
|
if (metadata == nil) {
|
||||||
return nullptr;
|
return nullptr;
|
||||||
|
@ -75,7 +75,7 @@ const char *getCurrentPlayingTitle() {
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
const char *getCurrentPlayingArtist() {
|
const char *GetCurrentPlayingArtist() {
|
||||||
NSDictionary *metadata = [NowPlayingBridge currentPlayingMetadata];
|
NSDictionary *metadata = [NowPlayingBridge currentPlayingMetadata];
|
||||||
if (metadata == nil) {
|
if (metadata == nil) {
|
||||||
return nullptr;
|
return nullptr;
|
||||||
|
|
Loading…
Reference in a new issue