diff --git a/ui/src/components/notifications.rs b/ui/src/components/notifications.rs index 2a3cdc8e..706275bd 100644 --- a/ui/src/components/notifications.rs +++ b/ui/src/components/notifications.rs @@ -40,8 +40,9 @@ impl fmt::Display for XDGNotifications { impl Component for XDGNotifications { fn draw(&mut self, _grid: &mut CellBuffer, _area: Area, _context: &mut Context) {} - fn process_event(&mut self, event: &mut UIEvent, _context: &mut Context) -> bool { + fn process_event(&mut self, event: &mut UIEvent, context: &mut Context) -> bool { if let UIEvent::Notification(ref title, ref body, ref kind) = event { + let settings = &context.runtime_settings.notifications; let mut notification = notify_rust::Notification::new(); notification .appname("meli") @@ -49,6 +50,23 @@ impl Component for XDGNotifications { .summary(title.as_ref().map(String::as_str).unwrap_or("meli")) .body(&escape_str(body)) .icon("dialog-information"); + match kind { + Some(NotificationType::NewMail) => { + notification.hint(notify_rust::hints::NotificationHint::Category( + "email".to_owned(), + )); + } + _ => {} + } + if settings.play_sound.is_true() { + if let Some(ref sound_path) = settings.sound_file { + notification.hint(notify_rust::hints::NotificationHint::SoundFile( + sound_path.to_owned(), + )); + } else { + notification.sound_name("message-new-email"); + } + } notification.show().unwrap(); } diff --git a/ui/src/conf.rs b/ui/src/conf.rs index 09c8decf..218f1458 100644 --- a/ui/src/conf.rs +++ b/ui/src/conf.rs @@ -470,6 +470,10 @@ mod default_vals { pub(in crate::conf) fn none() -> Option { None } + + pub(in crate::conf) fn internal_value_false() -> super::ToggleFlag { + super::ToggleFlag::InternalVal(false) + } } impl<'de> Deserialize<'de> for IndexStyle { diff --git a/ui/src/conf/notifications.rs b/ui/src/conf/notifications.rs index 663ab7cf..c450e2b4 100644 --- a/ui/src/conf/notifications.rs +++ b/ui/src/conf/notifications.rs @@ -19,6 +19,9 @@ * along with meli. If not, see . */ +use super::default_vals::internal_value_false; +use super::toggleflag_de; + fn none() -> Option { None } @@ -30,4 +33,8 @@ pub struct NotificationsSettings { /// Default: None #[serde(default = "none")] pub script: Option, + #[serde(deserialize_with = "toggleflag_de", default = "internal_value_false")] + pub play_sound: super::ToggleFlag, + #[serde(default = "none")] + pub sound_file: Option, }