4 use cocoa::{base::{nil, id}, foundation::NSString};
5 use objc::{class, msg_send, sel, sel_impl, runtime::{Class, Object}};
10 use super::LyricsSource;
15 pub fn new() -> Self {
20 impl LyricsSource for Spotify {
22 fn name(&self) -> 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.spotify.Client");
32 let workspace_class = Class::get("NSWorkspace").unwrap();
33 let shared_workspace: id = msg_send![workspace_class, sharedWorkspace];
34 let app_url: id = msg_send![shared_workspace, URLForApplicationWithBundleIdentifier:bundle_identifier];
37 let app: *mut Object = msg_send![cls, applicationWithBundleIdentifier:bundle_identifier];
44 if msg_send![app, isRunning] {
45 let current_track: *mut Object = msg_send![app, currentTrack];
46 if !current_track.is_null() {
47 let name_raw: *mut Object = msg_send![current_track, name];
48 let artist_raw: *mut Object = msg_send![current_track, artist];
50 let name_ptr: *const i8 = msg_send![name_raw, UTF8String];
51 let artist_ptr: *const i8 = msg_send![artist_raw, UTF8String];
53 let name = CStr::from_ptr(name_ptr).to_string_lossy().into_owned();
54 let artist = CStr::from_ptr(artist_ptr).to_string_lossy().into_owned();
67 fn disable(&self) -> Result<()> {
71 fn enable(&self) -> Result<()> {
75 fn reset(&self) -> Result<()> {