Commit: Update notification implementation to use Track struct instead of track path
This commit is contained in:
parent
ff2dd059e8
commit
561ff70374
2 changed files with 18 additions and 12 deletions
26
src/lib.rs
26
src/lib.rs
|
@ -1,6 +1,6 @@
|
||||||
#![feature(assert_matches)]
|
#![feature(assert_matches)]
|
||||||
|
|
||||||
use crate::cmus::TemplateProcessor;
|
use crate::cmus::{TemplateProcessor, Track};
|
||||||
#[cfg(feature = "debug")]
|
#[cfg(feature = "debug")]
|
||||||
use log::{debug, info};
|
use log::{debug, info};
|
||||||
use std::path::Path;
|
use std::path::Path;
|
||||||
|
@ -153,26 +153,26 @@ impl TrackCover {
|
||||||
/// If the track has an embedded cover, and `force_use_external_cover` is `true`, the function will search for an external cover.
|
/// If the track has an embedded cover, and `force_use_external_cover` is `true`, the function will search for an external cover.
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn track_cover(
|
pub fn track_cover(
|
||||||
track_path: &str,
|
track: &Track,
|
||||||
max_depth: u8,
|
max_depth: u8,
|
||||||
force_use_external_cover: bool,
|
force_use_external_cover: bool,
|
||||||
no_use_external_cover: bool,
|
no_use_external_cover: bool,
|
||||||
) -> TrackCover {
|
) -> TrackCover {
|
||||||
if !force_use_external_cover {
|
if !force_use_external_cover {
|
||||||
#[cfg(feature = "debug")]
|
#[cfg(feature = "debug")]
|
||||||
info!("Trying to get the embedded cover of \"{track_path}\".");
|
info!("Trying to get the embedded cover of \"{track_path}\".", track_path = track.path);
|
||||||
if let Ok(Some(cover)) = get_embedded_art(track_path) {
|
if let Ok(Some(cover)) = get_embedded_art(&track.path) {
|
||||||
return TrackCover::Embedded(cover);
|
return TrackCover::Embedded(cover);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if !no_use_external_cover {
|
if !no_use_external_cover {
|
||||||
#[cfg(feature = "debug")]
|
#[cfg(feature = "debug")]
|
||||||
info!("Trying to get the external cover of \"{track_path}\".");
|
info!("Trying to get the external cover of \"{track_path}\".", track_path = track.path);
|
||||||
if let Ok(Some(cover)) = search_for(
|
if let Ok(Some(cover)) = search_for(
|
||||||
track_path,
|
&track.path,
|
||||||
max_depth,
|
max_depth,
|
||||||
®ex::Regex::new(r".*\.(jpg|jpeg|png|gif)$").unwrap(),
|
®ex::Regex::new(&format!(r"(cover|{track_name}).*\.(jpg|jpeg|png|gif)$", track_name = track.get_name())).unwrap(),
|
||||||
) {
|
) {
|
||||||
#[cfg(feature = "debug")]
|
#[cfg(feature = "debug")]
|
||||||
info!("Found the external cover \"{cover}\".");
|
info!("Found the external cover \"{cover}\".");
|
||||||
|
@ -186,7 +186,7 @@ pub fn track_cover(
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(feature = "debug")]
|
#[cfg(feature = "debug")]
|
||||||
info!("Could not get the cover of \"{track_path}\".");
|
info!("Could not get the cover of \"{track_path}\".", track_path = track.path);
|
||||||
|
|
||||||
TrackCover::None
|
TrackCover::None
|
||||||
}
|
}
|
||||||
|
@ -226,9 +226,11 @@ mod tests {
|
||||||
use std::assert_matches::assert_matches;
|
use std::assert_matches::assert_matches;
|
||||||
use std::str::FromStr;
|
use std::str::FromStr;
|
||||||
use test_context::{test_context, TestContext};
|
use test_context::{test_context, TestContext};
|
||||||
|
use crate::cmus::player_settings::PlayerSettings;
|
||||||
|
|
||||||
struct TestContextWithFullTrack {
|
struct TestContextWithFullTrack {
|
||||||
track: cmus::Track,
|
track: Track,
|
||||||
|
player_settings: PlayerSettings,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl TestContext for TestContextWithFullTrack {
|
impl TestContext for TestContextWithFullTrack {
|
||||||
|
@ -238,6 +240,10 @@ mod tests {
|
||||||
"../tests/samples/cmus-remote-output-with-all-tags.txt"
|
"../tests/samples/cmus-remote-output-with-all-tags.txt"
|
||||||
))
|
))
|
||||||
.unwrap(),
|
.unwrap(),
|
||||||
|
player_settings: PlayerSettings::from_str(include_str!(
|
||||||
|
"../tests/samples/player_settings_mode-artist_vol-46_repeat-false_repeat_current-false_shuffle-tracks.txt"
|
||||||
|
))
|
||||||
|
.unwrap(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -246,7 +252,7 @@ mod tests {
|
||||||
#[test]
|
#[test]
|
||||||
fn test_process_path_template(ctx: &TestContextWithFullTrack) {
|
fn test_process_path_template(ctx: &TestContextWithFullTrack) {
|
||||||
let cover_path_template = String::from("{title}/{artist}/{album}/{tracknumber}");
|
let cover_path_template = String::from("{title}/{artist}/{album}/{tracknumber}");
|
||||||
let cover_path = process_template_placeholders(&cover_path_template, &ctx.track);
|
let cover_path = process_template_placeholders(cover_path_template, &ctx.track, &ctx.player_settings);
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
cover_path,
|
cover_path,
|
||||||
|
|
|
@ -71,8 +71,8 @@ impl NotificationsHandler {
|
||||||
Action::Show => {
|
Action::Show => {
|
||||||
let _ = self.notification.show()?;
|
let _ = self.notification.show()?;
|
||||||
}
|
}
|
||||||
|
Action::Update => todo!("Update notification"),
|
||||||
Action::None => {}
|
Action::None => {}
|
||||||
_ => todo!(),
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -103,7 +103,7 @@ impl NotificationsHandler {
|
||||||
self.setup_the_notification();
|
self.setup_the_notification();
|
||||||
// Get the track cover and set it to notification
|
// Get the track cover and set it to notification
|
||||||
let track_cover = track_cover(
|
let track_cover = track_cover(
|
||||||
&track.path,
|
track,
|
||||||
self.settings.depth(),
|
self.settings.depth(),
|
||||||
self.settings.force_use_external_cover,
|
self.settings.force_use_external_cover,
|
||||||
self.settings.no_use_external_cover,
|
self.settings.no_use_external_cover,
|
||||||
|
|
Loading…
Reference in a new issue