weh
This commit is contained in:
parent
693fa17d10
commit
500138ce67
331 changed files with 12348 additions and 60593 deletions
|
@ -1,8 +1,9 @@
|
|||
#ifdef __linux__
|
||||
|
||||
#include <fmt/core.h>
|
||||
#include <playerctl/playerctl.h>
|
||||
#include <fstream>
|
||||
#include <playerctl/playerctl.h>
|
||||
|
||||
#include "os.h"
|
||||
|
||||
using std::string;
|
||||
|
|
|
@ -1,12 +1,14 @@
|
|||
#ifdef __APPLE__
|
||||
|
||||
#include <sys/sysctl.h>
|
||||
#include <string>
|
||||
#include <sys/sysctl.h>
|
||||
|
||||
#include "macos/NowPlayingBridge.h"
|
||||
#include "os.h"
|
||||
|
||||
uint64_t GetMemInfo() {
|
||||
uint64_t mem = 0;
|
||||
size_t size = sizeof(mem);
|
||||
size_t size = sizeof(mem);
|
||||
|
||||
sysctlbyname("hw.memsize", &mem, &size, nullptr, 0);
|
||||
|
||||
|
@ -14,7 +16,7 @@ uint64_t GetMemInfo() {
|
|||
}
|
||||
|
||||
std::string GetNowPlaying() {
|
||||
return "";
|
||||
return getCurrentPlayingTitle();
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
14
src/os/macos/NowPlayingBridge.h
Normal file
14
src/os/macos/NowPlayingBridge.h
Normal file
|
@ -0,0 +1,14 @@
|
|||
// NowPlayingBridge.h
|
||||
|
||||
#ifdef __OBJC__
|
||||
#import <Foundation/Foundation.h>
|
||||
|
||||
@interface NowPlayingBridge : NSObject
|
||||
+ (NSDictionary*)currentPlayingMetadata;
|
||||
@end
|
||||
#else
|
||||
extern "C" {
|
||||
const char* getCurrentPlayingTitle();
|
||||
const char* getCurrentPlayingArtist();
|
||||
}
|
||||
#endif
|
90
src/os/macos/NowPlayingBridge.mm
Normal file
90
src/os/macos/NowPlayingBridge.mm
Normal file
|
@ -0,0 +1,90 @@
|
|||
// NowPlayingBridge.mm
|
||||
|
||||
#import "NowPlayingBridge.h"
|
||||
#import <Foundation/Foundation.h>
|
||||
#import <dispatch/dispatch.h>
|
||||
#import <objc/runtime.h>
|
||||
|
||||
typedef void (*MRMediaRemoteGetNowPlayingInfoFunction)(
|
||||
dispatch_queue_t queue, void (^handler)(NSDictionary *information));
|
||||
|
||||
@implementation NowPlayingBridge
|
||||
|
||||
+ (NSDictionary *)currentPlayingMetadata {
|
||||
#pragma clang diagnostic push
|
||||
#pragma clang diagnostic ignored "-Wold-style-cast"
|
||||
|
||||
CFURLRef ref = (__bridge CFURLRef)
|
||||
[NSURL fileURLWithPath:
|
||||
@"/System/Library/PrivateFrameworks/MediaRemote.framework"];
|
||||
|
||||
#pragma clang diagnostic pop
|
||||
|
||||
CFBundleRef bundle = CFBundleCreate(kCFAllocatorDefault, ref);
|
||||
|
||||
if (!bundle) {
|
||||
NSLog(@"Failed to load MediaRemote framework");
|
||||
return nil;
|
||||
}
|
||||
|
||||
#pragma clang diagnostic push
|
||||
#pragma clang diagnostic ignored "-Wold-style-cast"
|
||||
|
||||
MRMediaRemoteGetNowPlayingInfoFunction MRMediaRemoteGetNowPlayingInfo =
|
||||
(MRMediaRemoteGetNowPlayingInfoFunction)CFBundleGetFunctionPointerForName(
|
||||
bundle, CFSTR("MRMediaRemoteGetNowPlayingInfo"));
|
||||
|
||||
#pragma clang diagnostic pop
|
||||
|
||||
if (!MRMediaRemoteGetNowPlayingInfo) {
|
||||
NSLog(@"Failed to get function pointer for MRMediaRemoteGetNowPlayingInfo");
|
||||
CFRelease(bundle);
|
||||
return nil;
|
||||
}
|
||||
|
||||
__block NSDictionary *nowPlayingInfo = nil;
|
||||
dispatch_semaphore_t semaphore = dispatch_semaphore_create(0);
|
||||
|
||||
MRMediaRemoteGetNowPlayingInfo(
|
||||
dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0),
|
||||
^(NSDictionary *information) {
|
||||
nowPlayingInfo = [information copy];
|
||||
dispatch_semaphore_signal(semaphore);
|
||||
});
|
||||
|
||||
dispatch_semaphore_wait(semaphore, DISPATCH_TIME_FOREVER);
|
||||
|
||||
CFRelease(bundle);
|
||||
return nowPlayingInfo;
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
extern "C" {
|
||||
|
||||
const char *getCurrentPlayingTitle() {
|
||||
NSDictionary *metadata = [NowPlayingBridge currentPlayingMetadata];
|
||||
if (metadata == nil) {
|
||||
return nullptr;
|
||||
}
|
||||
NSString *title =
|
||||
[metadata objectForKey:@"kMRMediaRemoteNowPlayingInfoTitle"];
|
||||
if (title) {
|
||||
return strdup([title UTF8String]);
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
const char *getCurrentPlayingArtist() {
|
||||
NSDictionary *metadata = [NowPlayingBridge currentPlayingMetadata];
|
||||
if (metadata == nil) {
|
||||
return nullptr;
|
||||
}
|
||||
NSString *artist =
|
||||
[metadata objectForKey:@"kMRMediaRemoteNowPlayingInfoArtist"];
|
||||
if (artist) {
|
||||
return strdup([artist UTF8String]);
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue