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