Remove notifications' dependency on 'cover' (#706)
* Move functions from 'cover' to 'utils' * Remove notify dependency on 'cover' * Enable clipboard and notifications in CI/CD * remove extra newline
This commit is contained in:
2
.github/workflows/cd.yml
vendored
2
.github/workflows/cd.yml
vendored
@@ -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
|
||||
|
||||
2
.github/workflows/ci.yml
vendored
2
.github/workflows/ci.yml
vendored
@@ -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
|
||||
|
||||
10
src/queue.rs
10
src/queue.rs
@@ -410,14 +410,14 @@ impl Queue {
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "notify")]
|
||||
pub fn send_notification(track_name: &str, _cover_url: Option<String>) {
|
||||
#[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<String>) {
|
||||
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);
|
||||
}
|
||||
|
||||
@@ -166,7 +166,7 @@ impl CoverView {
|
||||
}
|
||||
|
||||
fn cache_path(&self, url: String) -> Option<PathBuf> {
|
||||
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(())
|
||||
}
|
||||
|
||||
17
src/utils.rs
17
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(())
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user