-use std::io::Result;
-
-// #[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"))]
-// mod quod_libe;
-// #[cfg(not(target_os = "macos"))]
-// mod strawberry;
-// #[cfg(not(target_os = "macos"))]
-// mod tauon;
-
-// #[cfg(target_os = "macos")]
-// use apple_music::AppleMusic;
-// #[cfg(target_os = "macos")]
-// use spotify::Spotify;
-
-// #[cfg(not(target_os = "macos"))]
-// use rhythmbox::Rhythmbox;
-// #[cfg(not(target_os = "macos"))]
-// use quod_libet::QuodLibet;
-// #[cfg(not(target_os = "macos"))]
-// use strawberry::Strawberry;
-// #[cfg(not(target_os = "macos"))]
-// use tauon::Tauon;
+use std::io::{Error, ErrorKind::Other, Result};
+
+#[cfg(target_os = "macos")]
+mod apple_music;
+#[cfg(target_os = "macos")]
+mod spotify;
+
+#[cfg(target_os = "linux")]
+mod dbus;
+
+#[cfg(target_os = "macos")]
+use apple_music::AppleMusic;
+#[cfg(target_os = "macos")]
+use spotify::Spotify;
+
+#[cfg(target_os = "linux")]
+use dbus::Dbus;
use crate::Track;
fn reset(&self) -> Result<()>;
}
-pub fn list() -> Result<()> {
- Ok(())
+pub fn list() -> Vec<String> {
+ 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<Track> {
- return None
+ let sources = available_sources();
+ for source in sources {
+ if let Some(track) = source.current_track() {
+ return Some(track);
+ }
+ }
+ None
}
pub fn available_sources() -> Vec<Box<dyn LyricsSource>> {
let mut sources: Vec<Box<dyn LyricsSource>> = 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"))]
{
- // sources.push(Box::new(Rhythmbox::new()));
- // sources.push(Box::new(QuodLibet::new()));
- // sources.push(Box::new(Strawberry::new()));
- // sources.push(Box::new(Tauon::new()));
+ sources.push(Box::new(Dbus::new()));
}
sources