diff --git a/.github/workflows/cd.yml b/.github/workflows/cd.yml index 67b9249..a39fc87 100644 --- a/.github/workflows/cd.yml +++ b/.github/workflows/cd.yml @@ -46,7 +46,7 @@ jobs: - build_target: windows-x86_64 os: windows-latest target: x86_64-pc-windows-msvc - features: '--no-default-features --features rodio_backend,pancurses_backend' + features: '--no-default-features --features rodio_backend,pancurses_backend,share_clipboard,notify' steps: - name: Install Rust toolchain uses: actions-rs/toolchain@v1 diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 3da212c..d5be13f 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -28,7 +28,7 @@ jobs: os: windows-latest artifact_suffix: windows-x86_64 target: x86_64-pc-windows-msvc - features: '--no-default-features --features rodio_backend,cursive/pancurses-backend' + features: '--no-default-features --features rodio_backend,pancurses_backend,share_clipboard,notify' steps: - name: Install Rust toolchain uses: actions-rs/toolchain@v1 diff --git a/src/queue.rs b/src/queue.rs index 170c034..cb1c545 100644 --- a/src/queue.rs +++ b/src/queue.rs @@ -410,14 +410,14 @@ impl Queue { } } +#[cfg(feature = "notify")] pub fn send_notification(track_name: &str, _cover_url: Option) { - #[cfg(all(feature = "notify", feature = "cover"))] let res = if let Some(u) = _cover_url { // download album cover image - let path = ui::cover::cache_path_for_url(u.to_string()); + let path = crate::utils::cache_path_for_url(u.to_string()); if !path.exists() { - if let Err(e) = ui::cover::download(u.to_string(), path.clone()) { + if let Err(e) = crate::utils::download(u.to_string(), path.clone()) { error!("Failed to download cover: {}", e); } } @@ -430,10 +430,6 @@ pub fn send_notification(track_name: &str, _cover_url: Option) { Notification::new().summary(track_name).show() }; - #[cfg(all(feature = "notify", not(feature = "cover")))] - let res = Notification::new().summary(track_name).show(); - - #[cfg(feature = "notify")] if let Err(e) = res { error!("Failed to send notification cover: {}", e); } diff --git a/src/ui/cover.rs b/src/ui/cover.rs index 2e809ab..4cd7940 100644 --- a/src/ui/cover.rs +++ b/src/ui/cover.rs @@ -166,7 +166,7 @@ impl CoverView { } fn cache_path(&self, url: String) -> Option { - let path = cache_path_for_url(url.clone()); + let path = crate::utils::cache_path_for_url(url.clone()); let mut loading = self.loading.write().unwrap(); if loading.contains(&url) { @@ -181,7 +181,7 @@ impl CoverView { let loading_thread = self.loading.clone(); std::thread::spawn(move || { - if let Err(e) = download(url.clone(), path.clone()) { + if let Err(e) = crate::utils::download(url.clone(), path.clone()) { error!("Failed to download cover: {}", e); } let mut loading = loading_thread.write().unwrap(); @@ -289,20 +289,3 @@ impl ViewExt for CoverView { Ok(CommandResult::Ignored) } } - -pub fn cache_path_for_url(url: String) -> PathBuf { - let mut path = crate::config::cache_path("covers"); - path.push(url.split('/').last().unwrap()); - path -} - -pub fn download(url: String, path: PathBuf) -> Result<(), std::io::Error> { - let mut resp = reqwest::blocking::get(&url) - .map_err(|e| std::io::Error::new(std::io::ErrorKind::Other, e))?; - - std::fs::create_dir_all(path.parent().unwrap())?; - let mut file = File::create(path)?; - - std::io::copy(&mut resp, &mut file)?; - Ok(()) -} diff --git a/src/utils.rs b/src/utils.rs index 692afe9..ac5c1c3 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -19,3 +19,20 @@ pub fn format_duration(d: &std::time::Duration) -> String { s.trim_end().to_string() } + +pub fn cache_path_for_url(url: String) -> std::path::PathBuf { + let mut path = crate::config::cache_path("covers"); + path.push(url.split('/').last().unwrap()); + path +} + +pub fn download(url: String, path: std::path::PathBuf) -> Result<(), std::io::Error> { + let mut resp = reqwest::blocking::get(&url) + .map_err(|e| std::io::Error::new(std::io::ErrorKind::Other, e))?; + + std::fs::create_dir_all(path.parent().unwrap())?; + let mut file = std::fs::File::create(path)?; + + std::io::copy(&mut resp, &mut file)?; + Ok(()) +}