Commit 6ebb7ac7fd

6ebb7ac7fdfa68f558a193e0557da8314b528f72

parent: 1bb93c18fb

Unregistered key

Akseli <akselmo@akselmo.dev> · 2025-08-22 21:47 UTC
committer: <noreply@github.com>

Add config option for playing sound-hints with desktop notifications (#481)

Layout: unified · split

src/config.rs +2
@@ -483,6 +483,8 @@ pub struct Notifications {
483 pub via: NotifyVia, 483 pub via: NotifyVia,
484 #[serde(default = "default_true")] 484 #[serde(default = "default_true")]
485 pub show_message: bool, 485 pub show_message: bool,
486 #[serde(default)]
487 pub sound_hint: Option<String>,
486} 488}
487 489
488#[derive(Clone)] 490#[derive(Clone)]
src/notifications.rs +10 −1
@@ -51,6 +51,7 @@ pub async fn register_notifications(
51 } 51 }
52 let notify_via = settings.tunables.notifications.via; 52 let notify_via = settings.tunables.notifications.via;
53 let show_message = settings.tunables.notifications.show_message; 53 let show_message = settings.tunables.notifications.show_message;
54 let sound_hint = settings.tunables.notifications.sound_hint.clone();
54 let server_settings = client.notification_settings().await; 55 let server_settings = client.notification_settings().await;
55 let Some(startup_ts) = MilliSecondsSinceUnixEpoch::from_system_time(SystemTime::now()) else { 56 let Some(startup_ts) = MilliSecondsSinceUnixEpoch::from_system_time(SystemTime::now()) else {
56 return; 57 return;
@@ -61,6 +62,7 @@ pub async fn register_notifications(
61 .register_notification_handler(move |notification, room: MatrixRoom, client: Client| { 62 .register_notification_handler(move |notification, room: MatrixRoom, client: Client| {
62 let store = store.clone(); 63 let store = store.clone();
63 let server_settings = server_settings.clone(); 64 let server_settings = server_settings.clone();
65 let sound_hint = sound_hint.clone();
64 async move { 66 async move {
65 let mode = global_or_room_mode(&server_settings, &room).await; 67 let mode = global_or_room_mode(&server_settings, &room).await;
66 if mode == RoomNotificationMode::Mute { 68 if mode == RoomNotificationMode::Mute {
@@ -90,6 +92,7 @@ pub async fn register_notifications(
90 body.as_deref(), 92 body.as_deref(),
91 room_id, 93 room_id,
92 &store, 94 &store,
95 sound_hint.as_deref(),
93 ) 96 )
94 .await; 97 .await;
95 }, 98 },
@@ -114,10 +117,11 @@ async fn send_notification(
114 body: Option<&str>, 117 body: Option<&str>,
115 room_id: OwnedRoomId, 118 room_id: OwnedRoomId,
116 store: &AsyncProgramStore, 119 store: &AsyncProgramStore,
120 sound_hint: Option<&str>,
117) { 121) {
118 #[cfg(feature = "desktop")] 122 #[cfg(feature = "desktop")]
119 if via.desktop { 123 if via.desktop {
120 send_notification_desktop(summary, body, room_id, store).await; 124 send_notification_desktop(summary, body, room_id, store, sound_hint).await;
121 } 125 }
122 #[cfg(not(feature = "desktop"))] 126 #[cfg(not(feature = "desktop"))]
123 { 127 {
@@ -140,6 +144,7 @@ async fn send_notification_desktop(
140 body: Option<&str>, 144 body: Option<&str>,
141 room_id: OwnedRoomId, 145 room_id: OwnedRoomId,
142 _store: &AsyncProgramStore, 146 _store: &AsyncProgramStore,
147 sound_hint: Option<&str>,
143) { 148) {
144 let mut desktop_notification = notify_rust::Notification::new(); 149 let mut desktop_notification = notify_rust::Notification::new();
145 desktop_notification 150 desktop_notification
@@ -148,6 +153,10 @@ async fn send_notification_desktop(
148 .icon(IAMB_XDG_NAME) 153 .icon(IAMB_XDG_NAME)
149 .action("default", "default"); 154 .action("default", "default");
150 155
156 if let Some(sound_hint) = sound_hint {
157 desktop_notification.sound_name(sound_hint);
158 }
159
151 #[cfg(all(unix, not(target_os = "macos")))] 160 #[cfg(all(unix, not(target_os = "macos")))]
152 desktop_notification.urgency(notify_rust::Urgency::Normal); 161 desktop_notification.urgency(notify_rust::Urgency::Normal);
153 162
src/tests.rs +1
@@ -196,6 +196,7 @@ pub fn mock_tunables() -> TunableValues {
196 enabled: false, 196 enabled: false,
197 via: NotifyVia::default(), 197 via: NotifyVia::default(),
198 show_message: true, 198 show_message: true,
199 sound_hint: None,
199 }, 200 },
200 image_preview: None, 201 image_preview: None,
201 user_gutter_width: 30, 202 user_gutter_width: 30,