X-Git-Url: https://git.r.bdr.sh/rbdr/lyricli/blobdiff_plain/b2096fb3958d9e9cdcca77931aadfb947cab24ee..44e7b4de4073e6dc25681bb2fa6977bf5869689a:/src/sources/mod.rs?ds=sidebyside diff --git a/src/sources/mod.rs b/src/sources/mod.rs index fb7af8f..78f7499 100644 --- a/src/sources/mod.rs +++ b/src/sources/mod.rs @@ -1,9 +1,10 @@ -use std::io::Result; +use std::io::{Result, Error, ErrorKind::Other}; + +#[cfg(target_os = "macos")] +mod apple_music; +#[cfg(target_os = "macos")] +mod spotify; -// #[cfg(target_os = "macos")] -// mod applie_music; -// #[cfg(target_os = "macos")] -// mod spotify; // #[cfg(not(target_os = "macos"))] // mod rhythmbox; // #[cfg(not(target_os = "macos"))] @@ -13,10 +14,10 @@ use std::io::Result; // #[cfg(not(target_os = "macos"))] // mod tauon; -// #[cfg(target_os = "macos")] -// use apple_music::AppleMusic; -// #[cfg(target_os = "macos")] -// use spotify::Spotify; +#[cfg(target_os = "macos")] +use apple_music::AppleMusic; +#[cfg(target_os = "macos")] +use spotify::Spotify; // #[cfg(not(target_os = "macos"))] // use rhythmbox::Rhythmbox; @@ -39,26 +40,47 @@ pub trait LyricsSource { fn reset(&self) -> Result<()>; } -pub fn list() -> Result<()> { - Ok(()) +pub fn list() -> Vec { + available_sources().into_iter().map(|source| source.name()).collect() } -pub fn enable(source_name: String) -> Result<()> { - println!("Enabling {}", source_name); - Ok(()) +pub fn enable(source_name: &String) -> Result<()> { + let sources = available_sources(); + for source in sources { + if &source.name() == source_name { + return source.enable() + } + } + Err(Error::new(Other, "No such source was available.")) } -pub fn disable(source_name: String) -> Result<()> { - println!("Disabling {}", source_name); - Ok(()) +pub fn disable(source_name: &String) -> Result<()> { + let sources = available_sources(); + for source in sources { + if &source.name() == source_name { + return source.disable() + } + } + Err(Error::new(Other, "No such source was available.")) } -pub fn reset(source_name: String) -> Result<()> { - println!("Reset {}", source_name); - Ok(()) +pub fn reset(source_name: &String) -> Result<()> { + let sources = available_sources(); + for source in sources { + if &source.name() == source_name { + return source.reset() + } + } + Err(Error::new(Other, "No such source was available.")) } pub fn get_track() -> Option { + let sources = available_sources(); + for source in sources { + if let Some(track) = source.current_track() { + return Some(track); + } + } return None } @@ -66,8 +88,8 @@ pub fn available_sources() -> Vec> { let mut sources: Vec> = Vec::new(); #[cfg(target_os = "macos")] { - // sources.push(Box::new(AppleMusic::new())); - // sources.push(Box::new(Spotify::new())); + sources.push(Box::new(AppleMusic::new())); + sources.push(Box::new(Spotify::new())); } #[cfg(not(target_os = "macos"))]