]> git.r.bdr.sh - rbdr/lyricli/blobdiff - src/sources/apple_music.rs
Attempt multiple builds instead of cross-compiling
[rbdr/lyricli] / src / sources / apple_music.rs
index cb36f5c4d2fa980be4820c0980132e2ee4c28f29..06412b88a02a7cbf114c9f746c17eb678b94cafb 100644 (file)
@@ -1,8 +1,8 @@
 use std::ffi::CStr;
 use std::io::Result;
 
-use cocoa::{base::nil, foundation::NSString};
-use objc::{class, msg_send, sel, sel_impl, runtime::Object};
+use cocoa::{base::{nil, id}, foundation::NSString};
+use objc::{class, msg_send, sel, sel_impl, runtime::{Class, Object}};
 use objc_id::Id;
 
 use crate::Track;
@@ -28,8 +28,17 @@ impl LyricsSource for AppleMusic {
             let app: Id<Object> = {
                 let cls = class!(SBApplication);
                 let bundle_identifier = NSString::alloc(nil).init_str("com.apple.Music"); 
-                let app: *mut Object = msg_send![cls, applicationWithBundleIdentifier:bundle_identifier];
-                Id::from_ptr(app)
+
+                let workspace_class = Class::get("NSWorkspace").unwrap();
+                let shared_workspace: id = msg_send![workspace_class, sharedWorkspace];
+                let app_url: id = msg_send![shared_workspace, URLForApplicationWithBundleIdentifier:bundle_identifier];
+
+                if app_url != nil {
+                    let app: *mut Object = msg_send![cls, applicationWithBundleIdentifier:bundle_identifier];
+                    Id::from_ptr(app)
+                } else {
+                    return None
+                }
             };
 
             if msg_send![app, isRunning] {