blegh
This commit is contained in:
parent
3071b23b93
commit
41200459e5
7 changed files with 57 additions and 40 deletions
|
@ -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…
Add table
Add a link
Reference in a new issue