From ff2dd059e8d9b3c0eb05659fdcfe55ce14a68054 Mon Sep 17 00:00:00 2001 From: Anas Elgarhy Date: Wed, 22 Feb 2023 19:19:47 +0200 Subject: [PATCH] Setup cover image when static cover is specified or track cover is enabled --- src/notification.rs | 26 ++++++++++++++++++++------ src/settings.rs | 16 ++++++++-------- 2 files changed, 28 insertions(+), 14 deletions(-) diff --git a/src/notification.rs b/src/notification.rs index 62b9f13..fa88806 100644 --- a/src/notification.rs +++ b/src/notification.rs @@ -50,8 +50,15 @@ impl NotificationsHandler { events: Vec, response: &CmusQueryResponse, ) -> Result<(), notify_rust::error::Error> { - //FIXME: Should check if the user has enabled the cover feature or use a static cover. - self.update_cover(&events[0], response); + // 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; } @@ -120,7 +134,7 @@ impl NotificationsHandler { fn setup_notification_timeout(&mut self, event: &CmusEvent) { use CmusEvent::*; self.notification.timeout(match event { - TrackChanged(_, _) => self.settings.timeout(), + TrackChanged(_, _) => self.settings.timeout(), StatusChanged(_, _) => self.settings.status_notification_timeout(), AAAMode(_, _) => self.settings.aaa_mode_notification_timeout(), VolumeChanged(_, _) => self.settings.volume_notification_timeout(), diff --git a/src/settings.rs b/src/settings.rs index 3c2878b..47c6992 100644 --- a/src/settings.rs +++ b/src/settings.rs @@ -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, + pub notification_static_cover: Option, /// 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, + cover_path_template: Option, #[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")]