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 {
483483 pub via: NotifyVia,
484484 #[serde(default = "default_true")]
485485 pub show_message: bool,
486 #[serde(default)]
487 pub sound_hint: Option<String>,
486488}
487489
488490#[derive(Clone)]
src/notifications.rs +10 −1
@@ -51,6 +51,7 @@ pub async fn register_notifications(
5151 }
5252 let notify_via = settings.tunables.notifications.via;
5353 let show_message = settings.tunables.notifications.show_message;
54 let sound_hint = settings.tunables.notifications.sound_hint.clone();
5455 let server_settings = client.notification_settings().await;
5556 let Some(startup_ts) = MilliSecondsSinceUnixEpoch::from_system_time(SystemTime::now()) else {
5657 return;
@@ -61,6 +62,7 @@ pub async fn register_notifications(
6162 .register_notification_handler(move |notification, room: MatrixRoom, client: Client| {
6263 let store = store.clone();
6364 let server_settings = server_settings.clone();
65 let sound_hint = sound_hint.clone();
6466 async move {
6567 let mode = global_or_room_mode(&server_settings, &room).await;
6668 if mode == RoomNotificationMode::Mute {
@@ -90,6 +92,7 @@ pub async fn register_notifications(
9092 body.as_deref(),
9193 room_id,
9294 &store,
95 sound_hint.as_deref(),
9396 )
9497 .await;
9598 },
@@ -114,10 +117,11 @@ async fn send_notification(
114117 body: Option<&str>,
115118 room_id: OwnedRoomId,
116119 store: &AsyncProgramStore,
120 sound_hint: Option<&str>,
117121) {
118122 #[cfg(feature = "desktop")]
119123 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;
121125 }
122126 #[cfg(not(feature = "desktop"))]
123127 {
@@ -140,6 +144,7 @@ async fn send_notification_desktop(
140144 body: Option<&str>,
141145 room_id: OwnedRoomId,
142146 _store: &AsyncProgramStore,
147 sound_hint: Option<&str>,
143148) {
144149 let mut desktop_notification = notify_rust::Notification::new();
145150 desktop_notification
@@ -148,6 +153,10 @@ async fn send_notification_desktop(
148153 .icon(IAMB_XDG_NAME)
149154 .action("default", "default");
150155
156 if let Some(sound_hint) = sound_hint {
157 desktop_notification.sound_name(sound_hint);
158 }
159
151160 #[cfg(all(unix, not(target_os = "macos")))]
152161 desktop_notification.urgency(notify_rust::Urgency::Normal);
153162
src/tests.rs +1
@@ -196,6 +196,7 @@ pub fn mock_tunables() -> TunableValues {
196196 enabled: false,
197197 via: NotifyVia::default(),
198198 show_message: true,
199 sound_hint: None,
199200 },
200201 image_preview: None,
201202 user_gutter_width: 30,