4 use cocoa::{base::nil, foundation::NSString};
5 use objc::{class, msg_send, sel, sel_impl, runtime::Object};
10 use super::LyricsSource;
12 pub struct AppleMusic;
15 pub fn new() -> Self {
20 impl LyricsSource for AppleMusic {
22 fn name(&self) -> String {
23 "apple_music".to_string()
26 fn current_track(&self) -> Option<Track> {
28 let app: Id<Object> = {
29 let cls = class!(SBApplication);
30 let bundle_identifier = NSString::alloc(nil).init_str("com.apple.Music");
31 let app: *mut Object = msg_send![cls, applicationWithBundleIdentifier:bundle_identifier];
35 if msg_send![app, isRunning] {
36 let current_track: *mut Object = msg_send![app, currentTrack];
37 if !current_track.is_null() {
38 let name_raw: *mut Object = msg_send![current_track, name];
39 let artist_raw: *mut Object = msg_send![current_track, artist];
41 let name_ptr: *const i8 = msg_send![name_raw, UTF8String];
42 let artist_ptr: *const i8 = msg_send![artist_raw, UTF8String];
44 let name = CStr::from_ptr(name_ptr).to_string_lossy().into_owned();
45 let artist = CStr::from_ptr(artist_ptr).to_string_lossy().into_owned();
58 fn disable(&self) -> Result<()> {
62 fn enable(&self) -> Result<()> {
66 fn reset(&self) -> Result<()> {