10 runtime::{Class, Object},
17 use super::LyricsSource;
22 pub fn new() -> Self {
27 impl LyricsSource for Spotify {
28 fn name(&self) -> String {
32 fn current_track(&self) -> Option<Track> {
34 let app: Id<Object> = {
35 let cls = class!(SBApplication);
36 let bundle_identifier = NSString::alloc(nil).init_str("com.spotify.Client");
38 let workspace_class = Class::get("NSWorkspace").unwrap();
39 let shared_workspace: id = msg_send![workspace_class, sharedWorkspace];
40 let app_url: id = msg_send![shared_workspace, URLForApplicationWithBundleIdentifier:bundle_identifier];
43 let app: *mut Object =
44 msg_send![cls, applicationWithBundleIdentifier:bundle_identifier];
51 if msg_send![app, isRunning] {
52 let current_track: *mut Object = msg_send![app, currentTrack];
53 if !current_track.is_null() {
54 let name_raw: *mut Object = msg_send![current_track, name];
55 let artist_raw: *mut Object = msg_send![current_track, artist];
57 let name_ptr: *const i8 = msg_send![name_raw, UTF8String];
58 let artist_ptr: *const i8 = msg_send![artist_raw, UTF8String];
60 let name = CStr::from_ptr(name_ptr).to_string_lossy().into_owned();
61 let artist = CStr::from_ptr(artist_ptr).to_string_lossy().into_owned();
63 return Some(Track { name, artist });
70 fn disable(&self) -> Result<()> {
74 fn enable(&self) -> Result<()> {
78 fn reset(&self) -> Result<()> {