From 6ebb7ac7fdfa68f558a193e0557da8314b528f72 Mon Sep 17 00:00:00 2001 From: Akseli Date: Sat, 23 Aug 2025 00:47:33 +0300 Subject: [PATCH] Add config option for playing sound-hints with desktop notifications (#481) --- src/config.rs | 2 ++ src/notifications.rs | 11 ++++++++++- src/tests.rs | 1 + 3 files changed, 13 insertions(+), 1 deletion(-) diff --git a/src/config.rs b/src/config.rs index 877f8e8..d6a03b6 100644 --- a/src/config.rs +++ b/src/config.rs @@ -483,6 +483,8 @@ pub struct Notifications { pub via: NotifyVia, #[serde(default = "default_true")] pub show_message: bool, + #[serde(default)] + pub sound_hint: Option, } #[derive(Clone)] diff --git a/src/notifications.rs b/src/notifications.rs index 482b984..b4938fe 100644 --- a/src/notifications.rs +++ b/src/notifications.rs @@ -51,6 +51,7 @@ pub async fn register_notifications( } let notify_via = settings.tunables.notifications.via; let show_message = settings.tunables.notifications.show_message; + let sound_hint = settings.tunables.notifications.sound_hint.clone(); let server_settings = client.notification_settings().await; let Some(startup_ts) = MilliSecondsSinceUnixEpoch::from_system_time(SystemTime::now()) else { return; @@ -61,6 +62,7 @@ pub async fn register_notifications( .register_notification_handler(move |notification, room: MatrixRoom, client: Client| { let store = store.clone(); let server_settings = server_settings.clone(); + let sound_hint = sound_hint.clone(); async move { let mode = global_or_room_mode(&server_settings, &room).await; if mode == RoomNotificationMode::Mute { @@ -90,6 +92,7 @@ pub async fn register_notifications( body.as_deref(), room_id, &store, + sound_hint.as_deref(), ) .await; }, @@ -114,10 +117,11 @@ async fn send_notification( body: Option<&str>, room_id: OwnedRoomId, store: &AsyncProgramStore, + sound_hint: Option<&str>, ) { #[cfg(feature = "desktop")] if via.desktop { - send_notification_desktop(summary, body, room_id, store).await; + send_notification_desktop(summary, body, room_id, store, sound_hint).await; } #[cfg(not(feature = "desktop"))] { @@ -140,6 +144,7 @@ async fn send_notification_desktop( body: Option<&str>, room_id: OwnedRoomId, _store: &AsyncProgramStore, + sound_hint: Option<&str>, ) { let mut desktop_notification = notify_rust::Notification::new(); desktop_notification @@ -148,6 +153,10 @@ async fn send_notification_desktop( .icon(IAMB_XDG_NAME) .action("default", "default"); + if let Some(sound_hint) = sound_hint { + desktop_notification.sound_name(sound_hint); + } + #[cfg(all(unix, not(target_os = "macos")))] desktop_notification.urgency(notify_rust::Urgency::Normal); diff --git a/src/tests.rs b/src/tests.rs index 73d3e84..4a31d64 100644 --- a/src/tests.rs +++ b/src/tests.rs @@ -196,6 +196,7 @@ pub fn mock_tunables() -> TunableValues { enabled: false, via: NotifyVia::default(), show_message: true, + sound_hint: None, }, image_preview: None, user_gutter_width: 30,