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