]> git.r.bdr.sh - rbdr/lyricli/blobdiff - src/sources/spotify.rs
Remove the openssl stuff
[rbdr/lyricli] / src / sources / spotify.rs
index b23ea736150a05b490c9df3df55eb24c03bf979c..e4bf19ce687ba42b2c6ffc99153b573a8933f773 100644 (file)
@@ -1,8 +1,8 @@
 use std::ffi::CStr;
 use std::io::Result;
 
 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;
 use objc_id::Id;
 
 use crate::Track;
@@ -28,8 +28,17 @@ impl LyricsSource for Spotify {
             let app: Id<Object> = {
                 let cls = class!(SBApplication);
                 let bundle_identifier = NSString::alloc(nil).init_str("com.spotify.Client"); 
             let app: Id<Object> = {
                 let cls = class!(SBApplication);
                 let bundle_identifier = NSString::alloc(nil).init_str("com.spotify.Client"); 
-                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] {
             };
 
             if msg_send![app, isRunning] {