Setup cover image when static cover is specified or track cover is enabled
This commit is contained in:
parent
960da31218
commit
ff2dd059e8
2 changed files with 28 additions and 14 deletions
|
@ -50,8 +50,15 @@ impl NotificationsHandler {
|
||||||
events: Vec<CmusEvent>,
|
events: Vec<CmusEvent>,
|
||||||
response: &CmusQueryResponse,
|
response: &CmusQueryResponse,
|
||||||
) -> Result<(), notify_rust::error::Error> {
|
) -> 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
|
||||||
self.update_cover(&events[0], response);
|
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 {
|
for event in events {
|
||||||
self.setup_notification_timeout(&event);
|
self.setup_notification_timeout(&event);
|
||||||
|
@ -95,13 +102,20 @@ impl NotificationsHandler {
|
||||||
// Reset the notification
|
// Reset the notification
|
||||||
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
|
||||||
track_cover(
|
let track_cover = track_cover(
|
||||||
&track.path,
|
&track.path,
|
||||||
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,
|
||||||
)
|
);
|
||||||
.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
|
// Flip the change flag
|
||||||
self.cover_set = true;
|
self.cover_set = true;
|
||||||
}
|
}
|
||||||
|
@ -120,7 +134,7 @@ impl NotificationsHandler {
|
||||||
fn setup_notification_timeout(&mut self, event: &CmusEvent) {
|
fn setup_notification_timeout(&mut self, event: &CmusEvent) {
|
||||||
use CmusEvent::*;
|
use CmusEvent::*;
|
||||||
self.notification.timeout(match event {
|
self.notification.timeout(match event {
|
||||||
TrackChanged(_, _) => self.settings.timeout(),
|
TrackChanged(_, _) => self.settings.timeout(),
|
||||||
StatusChanged(_, _) => self.settings.status_notification_timeout(),
|
StatusChanged(_, _) => self.settings.status_notification_timeout(),
|
||||||
AAAMode(_, _) => self.settings.aaa_mode_notification_timeout(),
|
AAAMode(_, _) => self.settings.aaa_mode_notification_timeout(),
|
||||||
VolumeChanged(_, _) => self.settings.volume_notification_timeout(),
|
VolumeChanged(_, _) => self.settings.volume_notification_timeout(),
|
||||||
|
|
|
@ -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
|
/// 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")
|
/// (e.g. "audio-x-generic" or "spotify-client")
|
||||||
#[arg(short = 'i', long = "icon", default_value = None)]
|
#[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
|
/// 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".
|
/// 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.
|
/// 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)]
|
#[arg(short = 'w', long = "cover-path", default_value = None)]
|
||||||
cover_path: Option<String>,
|
cover_path_template: Option<String>,
|
||||||
#[cfg(feature = "lyrics")]
|
#[cfg(feature = "lyrics")]
|
||||||
/// The lyrics file path, if not given, the lyrics will be searched in the track's directory
|
/// 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.
|
/// 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),
|
timeout: Some(NOTIFICATION_TIMEOUT),
|
||||||
persistent: false,
|
persistent: false,
|
||||||
show_track_cover: true,
|
show_track_cover: true,
|
||||||
notification_static_icon: None,
|
notification_static_cover: None,
|
||||||
cover_path: None,
|
cover_path_template: None,
|
||||||
#[cfg(feature = "lyrics")]
|
#[cfg(feature = "lyrics")]
|
||||||
lyrics_path: None,
|
lyrics_path: None,
|
||||||
depth: Some(DEFAULT_MAX_DEPTH),
|
depth: Some(DEFAULT_MAX_DEPTH),
|
||||||
|
@ -342,10 +342,10 @@ impl Settings {
|
||||||
cfg.timeout = args.timeout.or(cfg.timeout);
|
cfg.timeout = args.timeout.or(cfg.timeout);
|
||||||
cfg.persistent = args.persistent || cfg.persistent;
|
cfg.persistent = args.persistent || cfg.persistent;
|
||||||
cfg.show_track_cover = args.show_track_cover || cfg.show_track_cover;
|
cfg.show_track_cover = args.show_track_cover || cfg.show_track_cover;
|
||||||
cfg.notification_static_icon = args
|
cfg.notification_static_cover = args
|
||||||
.notification_static_icon
|
.notification_static_cover
|
||||||
.or(cfg.notification_static_icon);
|
.or(cfg.notification_static_cover);
|
||||||
cfg.cover_path = args.cover_path.or(cfg.cover_path);
|
cfg.cover_path_template = args.cover_path_template.or(cfg.cover_path_template);
|
||||||
#[cfg(feature = "lyrics")]
|
#[cfg(feature = "lyrics")]
|
||||||
if args.lyrics_path != None {
|
if args.lyrics_path != None {
|
||||||
#[cfg(feature = "debug")]
|
#[cfg(feature = "debug")]
|
||||||
|
|
Loading…
Reference in a new issue