diff options
| author | Ruben Beltran del Rio <git@r.bdr.sh> | 2024-03-16 17:08:52 +0100 |
|---|---|---|
| committer | Ruben Beltran del Rio <git@r.bdr.sh> | 2024-03-16 17:08:52 +0100 |
| commit | 8d584ce755e90c6f5260f7f2828e5a294004148b (patch) | |
| tree | 09eb1aa94be55b93ecd827f0b5b9e5aa42e6d7a4 /src/sources | |
| parent | f5a040da21ff2bf594e50d886b5e485cdfdc4a70 (diff) | |
Add mac command
Diffstat (limited to 'src/sources')
| -rw-r--r-- | src/sources/apple_music.rs | 17 | ||||
| -rw-r--r-- | src/sources/spotify.rs | 17 |
2 files changed, 26 insertions, 8 deletions
diff --git a/src/sources/apple_music.rs b/src/sources/apple_music.rs index cb36f5c..06412b8 100644 --- a/src/sources/apple_music.rs +++ b/src/sources/apple_music.rs @@ -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] { diff --git a/src/sources/spotify.rs b/src/sources/spotify.rs index b23ea73..e4bf19c 100644 --- a/src/sources/spotify.rs +++ b/src/sources/spotify.rs @@ -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 Spotify { 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] { |