Setup cover image when static cover is specified or track cover is enabled

This commit is contained in:
Anas Elgarhy 2023-02-22 19:19:47 +02:00
parent 960da31218
commit ff2dd059e8
No known key found for this signature in database
GPG key ID: 0501802A1D496528
2 changed files with 28 additions and 14 deletions

View file

@ -50,8 +50,15 @@ impl NotificationsHandler {
events: Vec<CmusEvent>,
response: &CmusQueryResponse,
) -> Result<(), notify_rust::error::Error> {
//FIXME: Should check if the user has enabled the cover feature or use a static cover.
// Setup the notification cover
if self.settings.show_track_cover {
self.update_cover(&events[0], response);
} else if self.settings.notification_static_cover.is_some() && !self.cover_set {
self.setup_the_notification();
self.notification
.image_path(self.settings.notification_static_cover.as_ref().unwrap());
self.cover_set = true;
}
for event in events {
self.setup_notification_timeout(&event);
@ -95,13 +102,20 @@ impl NotificationsHandler {
// Reset the notification
self.setup_the_notification();
// Get the track cover and set it to notification
track_cover(
let track_cover = track_cover(
&track.path,
self.settings.depth(),
self.settings.force_use_external_cover,
self.settings.no_use_external_cover,
)
.set_notification_image(&mut self.notification);
);
if track_cover != TrackCover::None {
track_cover.set_notification_image(&mut self.notification);
} else if self.settings.notification_static_cover.is_some() {
self.notification
.image_path(self.settings.notification_static_cover.as_ref().unwrap());
}
// Flip the change flag
self.cover_set = true;
}

View file

@ -49,7 +49,7 @@ pub struct Settings {
/// you can give it the full path to an image file or a name of an icon from the current icon theme
/// (e.g. "audio-x-generic" or "spotify-client")
#[arg(short = 'i', long = "icon", default_value = None)]
notification_static_icon: Option<String>,
pub notification_static_cover: Option<String>,
/// The path to look for the cover image, if not given, the cover will be searched in the track's directory
/// for an image file with the name "cover".
///
@ -61,7 +61,7 @@ pub struct Settings {
///
/// If you not specify the full path, the cover will be started from the track's directory.
#[arg(short = 'w', long = "cover-path", default_value = None)]
cover_path: Option<String>,
cover_path_template: Option<String>,
#[cfg(feature = "lyrics")]
/// The lyrics file path, if not given, the lyrics will be searched in the track's directory
/// for a text file with the name "lyrics", or with the same name as the track.
@ -257,8 +257,8 @@ impl Default for Settings {
timeout: Some(NOTIFICATION_TIMEOUT),
persistent: false,
show_track_cover: true,
notification_static_icon: None,
cover_path: None,
notification_static_cover: None,
cover_path_template: None,
#[cfg(feature = "lyrics")]
lyrics_path: None,
depth: Some(DEFAULT_MAX_DEPTH),
@ -342,10 +342,10 @@ impl Settings {
cfg.timeout = args.timeout.or(cfg.timeout);
cfg.persistent = args.persistent || cfg.persistent;
cfg.show_track_cover = args.show_track_cover || cfg.show_track_cover;
cfg.notification_static_icon = args
.notification_static_icon
.or(cfg.notification_static_icon);
cfg.cover_path = args.cover_path.or(cfg.cover_path);
cfg.notification_static_cover = args
.notification_static_cover
.or(cfg.notification_static_cover);
cfg.cover_path_template = args.cover_path_template.or(cfg.cover_path_template);
#[cfg(feature = "lyrics")]
if args.lyrics_path != None {
#[cfg(feature = "debug")]