use std::io::Result; use objc2::{ msg_send, rc::{Retained, autoreleasepool}, runtime::AnyObject, }; use objc2_foundation::NSString; use objc2_scripting_bridge::SBApplication; use crate::Track; use super::LyricsSource; pub struct Spotify; impl Spotify { pub fn new() -> Self { Spotify } } impl LyricsSource for Spotify { fn name(&self) -> String { "spotify".to_string() } fn current_track(&self) -> Option { unsafe { let bundle_identifier = NSString::from_str("com.spotify.Client"); let app = SBApplication::applicationWithBundleIdentifier(&bundle_identifier); if let Some(app) = app && app.isRunning() { let current_track: Option> = msg_send![&app, currentTrack]; if let Some(current_track) = current_track { let name_raw: Option> = msg_send![¤t_track, name]; let artist_raw: Option> = msg_send![¤t_track, artist]; if let (Some(name_raw), Some(artist_raw)) = (name_raw, artist_raw) { let name = autoreleasepool(|pool| name_raw.to_str(pool).to_string()); let artist = autoreleasepool(|pool| artist_raw.to_str(pool).to_string()); return Some(Track { name, artist }); } } } } None } fn disable(&self) -> Result<()> { Ok(()) } fn enable(&self) -> Result<()> { Ok(()) } fn reset(&self) -> Result<()> { Ok(()) } }