blegh
This commit is contained in:
parent
3071b23b93
commit
41200459e5
|
@ -6,6 +6,7 @@ NamespaceIndentation: All
|
||||||
SpaceBeforeCpp11BracedList: true
|
SpaceBeforeCpp11BracedList: true
|
||||||
SpacesBeforeTrailingComments: 1
|
SpacesBeforeTrailingComments: 1
|
||||||
AlignConsecutiveAssignments: true
|
AlignConsecutiveAssignments: true
|
||||||
|
IndentExternBlock: Indent
|
||||||
IncludeBlocks: Regroup
|
IncludeBlocks: Regroup
|
||||||
IncludeCategories:
|
IncludeCategories:
|
||||||
- Regex: '".*"'
|
- Regex: '".*"'
|
||||||
|
|
36
flake.nix
36
flake.nix
|
@ -46,7 +46,10 @@
|
||||||
];
|
];
|
||||||
};
|
};
|
||||||
|
|
||||||
stdenv = pkgs.stdenvAdapters.useMoldLinker pkgs.llvmPackages_18.stdenv;
|
stdenv =
|
||||||
|
if pkgs.hostPlatform.isLinux
|
||||||
|
then pkgs.stdenvAdapters.useMoldLinker pkgs.llvmPackages_18.stdenv
|
||||||
|
else pkgs.llvmPackages_18.stdenv;
|
||||||
|
|
||||||
deps = with (
|
deps = with (
|
||||||
if !stdenv.isDarwin
|
if !stdenv.isDarwin
|
||||||
|
@ -60,15 +63,16 @@
|
||||||
glib
|
glib
|
||||||
libcpr
|
libcpr
|
||||||
tomlplusplus
|
tomlplusplus
|
||||||
]
|
];
|
||||||
++ (with pkgs; (lib.optionals hostPlatform.isLinux [
|
|
||||||
sdbus-cpp
|
|
||||||
valgrind
|
|
||||||
]));
|
|
||||||
|
|
||||||
darwinPkgs = nixpkgs.lib.optionals stdenv.isDarwin (with pkgs.darwin; [
|
linuxPkgs = nixpkgs.lib.optionals stdenv.isLinux (with pkgs.llvmPackages_18; [
|
||||||
apple_sdk.frameworks.CoreFoundation
|
sdbus-cpp
|
||||||
apple_sdk.frameworks.MediaPlayer
|
valgrind
|
||||||
|
]);
|
||||||
|
|
||||||
|
darwinPkgs = nixpkgs.lib.optionals stdenv.isDarwin (with pkgs.darwin.apple_sdk.frameworks; [
|
||||||
|
Foundation
|
||||||
|
MediaPlayer
|
||||||
]);
|
]);
|
||||||
in
|
in
|
||||||
with pkgs; {
|
with pkgs; {
|
||||||
|
@ -89,10 +93,13 @@
|
||||||
tomlplusplus
|
tomlplusplus
|
||||||
];
|
];
|
||||||
|
|
||||||
buildInputs = [
|
buildInputs =
|
||||||
coost
|
[
|
||||||
fmt
|
coost
|
||||||
];
|
fmt
|
||||||
|
]
|
||||||
|
++ darwinPkgs
|
||||||
|
++ linuxPkgs;
|
||||||
|
|
||||||
configurePhase = ''
|
configurePhase = ''
|
||||||
meson setup build
|
meson setup build
|
||||||
|
@ -130,7 +137,8 @@
|
||||||
(writeScriptBin "run" "meson compile -C build && build/draconis++")
|
(writeScriptBin "run" "meson compile -C build && build/draconis++")
|
||||||
]
|
]
|
||||||
++ deps
|
++ deps
|
||||||
++ darwinPkgs;
|
++ darwinPkgs
|
||||||
|
++ linuxPkgs;
|
||||||
|
|
||||||
name = "C++";
|
name = "C++";
|
||||||
};
|
};
|
||||||
|
|
|
@ -7,7 +7,7 @@ project(
|
||||||
'cpp_std=c++20',
|
'cpp_std=c++20',
|
||||||
'default_library=static',
|
'default_library=static',
|
||||||
'warning_level=everything',
|
'warning_level=everything',
|
||||||
'buildtype=debugoptimized'
|
'buildtype=debugoptimized',
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -16,7 +16,7 @@ clangtidy = find_program('clang-tidy', required: false)
|
||||||
cpp = meson.get_compiler('cpp')
|
cpp = meson.get_compiler('cpp')
|
||||||
|
|
||||||
if host_machine.system() == 'darwin'
|
if host_machine.system() == 'darwin'
|
||||||
add_language('objcpp')
|
add_languages('objcpp')
|
||||||
|
|
||||||
objcpp = meson.get_compiler('objcpp')
|
objcpp = meson.get_compiler('objcpp')
|
||||||
|
|
||||||
|
@ -108,8 +108,8 @@ endif
|
||||||
executable(
|
executable(
|
||||||
'draconis++',
|
'draconis++',
|
||||||
sources,
|
sources,
|
||||||
objc_args,
|
objc_args: objc_args,
|
||||||
link_args,
|
link_args: link_args,
|
||||||
dependencies: deps,
|
dependencies: deps,
|
||||||
include_directories: incdir,
|
include_directories: incdir,
|
||||||
)
|
)
|
||||||
|
|
|
@ -57,24 +57,26 @@ uint64_t GetMemInfo() {
|
||||||
std::vector<std::string> GetMprisPlayers(sdbus::IConnection& connection) {
|
std::vector<std::string> GetMprisPlayers(sdbus::IConnection& connection) {
|
||||||
auto dbusProxy =
|
auto dbusProxy =
|
||||||
sdbus::createProxy(connection, DBUS_INTERFACE, DBUS_OBJECT_PATH);
|
sdbus::createProxy(connection, DBUS_INTERFACE, DBUS_OBJECT_PATH);
|
||||||
|
|
||||||
std::vector<std::string> names;
|
std::vector<std::string> names;
|
||||||
|
|
||||||
dbusProxy->callMethod(DBUS_METHOD_LIST_NAMES)
|
dbusProxy->callMethod(DBUS_METHOD_LIST_NAMES)
|
||||||
.onInterface(DBUS_INTERFACE)
|
.onInterface(DBUS_INTERFACE)
|
||||||
.storeResultsTo(names);
|
.storeResultsTo(names);
|
||||||
|
|
||||||
std::vector<std::string> mprisPlayers;
|
std::vector<std::string> mprisPlayers;
|
||||||
for (const auto& name : names) {
|
|
||||||
if (name.find(MPRIS_INTERFACE_NAME) != std::string::npos) {
|
for (const auto& name : names)
|
||||||
|
if (name.find(MPRIS_INTERFACE_NAME) != std::string::npos)
|
||||||
mprisPlayers.push_back(name);
|
mprisPlayers.push_back(name);
|
||||||
}
|
|
||||||
}
|
|
||||||
return mprisPlayers;
|
return mprisPlayers;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string GetActivePlayer(const std::vector<std::string>& mprisPlayers) {
|
std::string GetActivePlayer(const std::vector<std::string>& mprisPlayers) {
|
||||||
if (!mprisPlayers.empty()) {
|
if (!mprisPlayers.empty())
|
||||||
return mprisPlayers.front();
|
return mprisPlayers.front();
|
||||||
}
|
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -16,7 +16,10 @@ uint64_t GetMemInfo() {
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string GetNowPlaying() {
|
std::string GetNowPlaying() {
|
||||||
return GetCurrentPlayingTitle();
|
if (const char* title = GetCurrentPlayingTitle())
|
||||||
|
return title;
|
||||||
|
|
||||||
|
return "No song playing";
|
||||||
}
|
}
|
||||||
|
|
||||||
#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
|
||||||
|
|
|
@ -5,7 +5,7 @@
|
||||||
#import <dispatch/dispatch.h>
|
#import <dispatch/dispatch.h>
|
||||||
#import <objc/runtime.h>
|
#import <objc/runtime.h>
|
||||||
|
|
||||||
typedef void (*MRMediaRemoteGetNowPlayingInfoFunction)(
|
using MRMediaRemoteGetNowPlayingInfoFunction = void (*)(
|
||||||
dispatch_queue_t queue, void (^handler)(NSDictionary *information));
|
dispatch_queue_t queue, void (^handler)(NSDictionary *information));
|
||||||
|
|
||||||
@implementation NowPlayingBridge
|
@implementation NowPlayingBridge
|
||||||
|
@ -30,13 +30,13 @@ typedef void (*MRMediaRemoteGetNowPlayingInfoFunction)(
|
||||||
#pragma clang diagnostic push
|
#pragma clang diagnostic push
|
||||||
#pragma clang diagnostic ignored "-Wold-style-cast"
|
#pragma clang diagnostic ignored "-Wold-style-cast"
|
||||||
|
|
||||||
MRMediaRemoteGetNowPlayingInfoFunction MRMediaRemoteGetNowPlayingInfo =
|
auto mrMediaRemoteGetNowPlayingInfo =
|
||||||
(MRMediaRemoteGetNowPlayingInfoFunction)CFBundleGetFunctionPointerForName(
|
(MRMediaRemoteGetNowPlayingInfoFunction)CFBundleGetFunctionPointerForName(
|
||||||
bundle, CFSTR("MRMediaRemoteGetNowPlayingInfo"));
|
bundle, CFSTR("MRMediaRemoteGetNowPlayingInfo"));
|
||||||
|
|
||||||
#pragma clang diagnostic pop
|
#pragma clang diagnostic pop
|
||||||
|
|
||||||
if (!MRMediaRemoteGetNowPlayingInfo) {
|
if (!mrMediaRemoteGetNowPlayingInfo) {
|
||||||
NSLog(@"Failed to get function pointer for MRMediaRemoteGetNowPlayingInfo");
|
NSLog(@"Failed to get function pointer for MRMediaRemoteGetNowPlayingInfo");
|
||||||
CFRelease(bundle);
|
CFRelease(bundle);
|
||||||
return nil;
|
return nil;
|
||||||
|
@ -45,7 +45,7 @@ typedef void (*MRMediaRemoteGetNowPlayingInfoFunction)(
|
||||||
__block NSDictionary *nowPlayingInfo = nil;
|
__block NSDictionary *nowPlayingInfo = nil;
|
||||||
dispatch_semaphore_t semaphore = dispatch_semaphore_create(0);
|
dispatch_semaphore_t semaphore = dispatch_semaphore_create(0);
|
||||||
|
|
||||||
MRMediaRemoteGetNowPlayingInfo(
|
mrMediaRemoteGetNowPlayingInfo(
|
||||||
dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0),
|
dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0),
|
||||||
^(NSDictionary *information) {
|
^(NSDictionary *information) {
|
||||||
nowPlayingInfo = [information copy];
|
nowPlayingInfo = [information copy];
|
||||||
|
@ -61,30 +61,33 @@ typedef void (*MRMediaRemoteGetNowPlayingInfoFunction)(
|
||||||
@end
|
@end
|
||||||
|
|
||||||
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;
|
||||||
}
|
|
||||||
NSString *title =
|
NSString *title =
|
||||||
[metadata objectForKey:@"kMRMediaRemoteNowPlayingInfoTitle"];
|
[metadata objectForKey:@"kMRMediaRemoteNowPlayingInfoTitle"];
|
||||||
if (title) {
|
|
||||||
|
if (title)
|
||||||
return strdup([title UTF8String]);
|
return strdup([title UTF8String]);
|
||||||
}
|
|
||||||
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;
|
||||||
}
|
|
||||||
NSString *artist =
|
NSString *artist =
|
||||||
[metadata objectForKey:@"kMRMediaRemoteNowPlayingInfoArtist"];
|
[metadata objectForKey:@"kMRMediaRemoteNowPlayingInfoArtist"];
|
||||||
if (artist) {
|
|
||||||
|
if (artist)
|
||||||
return strdup([artist UTF8String]);
|
return strdup([artist UTF8String]);
|
||||||
}
|
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue