Add config option for playing sound-hints with desktop notifications (#481)
This commit is contained in:
@@ -483,6 +483,8 @@ pub struct Notifications {
|
|||||||
pub via: NotifyVia,
|
pub via: NotifyVia,
|
||||||
#[serde(default = "default_true")]
|
#[serde(default = "default_true")]
|
||||||
pub show_message: bool,
|
pub show_message: bool,
|
||||||
|
#[serde(default)]
|
||||||
|
pub sound_hint: Option<String>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
|
|||||||
@@ -51,6 +51,7 @@ pub async fn register_notifications(
|
|||||||
}
|
}
|
||||||
let notify_via = settings.tunables.notifications.via;
|
let notify_via = settings.tunables.notifications.via;
|
||||||
let show_message = settings.tunables.notifications.show_message;
|
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 server_settings = client.notification_settings().await;
|
||||||
let Some(startup_ts) = MilliSecondsSinceUnixEpoch::from_system_time(SystemTime::now()) else {
|
let Some(startup_ts) = MilliSecondsSinceUnixEpoch::from_system_time(SystemTime::now()) else {
|
||||||
return;
|
return;
|
||||||
@@ -61,6 +62,7 @@ pub async fn register_notifications(
|
|||||||
.register_notification_handler(move |notification, room: MatrixRoom, client: Client| {
|
.register_notification_handler(move |notification, room: MatrixRoom, client: Client| {
|
||||||
let store = store.clone();
|
let store = store.clone();
|
||||||
let server_settings = server_settings.clone();
|
let server_settings = server_settings.clone();
|
||||||
|
let sound_hint = sound_hint.clone();
|
||||||
async move {
|
async move {
|
||||||
let mode = global_or_room_mode(&server_settings, &room).await;
|
let mode = global_or_room_mode(&server_settings, &room).await;
|
||||||
if mode == RoomNotificationMode::Mute {
|
if mode == RoomNotificationMode::Mute {
|
||||||
@@ -90,6 +92,7 @@ pub async fn register_notifications(
|
|||||||
body.as_deref(),
|
body.as_deref(),
|
||||||
room_id,
|
room_id,
|
||||||
&store,
|
&store,
|
||||||
|
sound_hint.as_deref(),
|
||||||
)
|
)
|
||||||
.await;
|
.await;
|
||||||
},
|
},
|
||||||
@@ -114,10 +117,11 @@ async fn send_notification(
|
|||||||
body: Option<&str>,
|
body: Option<&str>,
|
||||||
room_id: OwnedRoomId,
|
room_id: OwnedRoomId,
|
||||||
store: &AsyncProgramStore,
|
store: &AsyncProgramStore,
|
||||||
|
sound_hint: Option<&str>,
|
||||||
) {
|
) {
|
||||||
#[cfg(feature = "desktop")]
|
#[cfg(feature = "desktop")]
|
||||||
if via.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"))]
|
#[cfg(not(feature = "desktop"))]
|
||||||
{
|
{
|
||||||
@@ -140,6 +144,7 @@ async fn send_notification_desktop(
|
|||||||
body: Option<&str>,
|
body: Option<&str>,
|
||||||
room_id: OwnedRoomId,
|
room_id: OwnedRoomId,
|
||||||
_store: &AsyncProgramStore,
|
_store: &AsyncProgramStore,
|
||||||
|
sound_hint: Option<&str>,
|
||||||
) {
|
) {
|
||||||
let mut desktop_notification = notify_rust::Notification::new();
|
let mut desktop_notification = notify_rust::Notification::new();
|
||||||
desktop_notification
|
desktop_notification
|
||||||
@@ -148,6 +153,10 @@ async fn send_notification_desktop(
|
|||||||
.icon(IAMB_XDG_NAME)
|
.icon(IAMB_XDG_NAME)
|
||||||
.action("default", "default");
|
.action("default", "default");
|
||||||
|
|
||||||
|
if let Some(sound_hint) = sound_hint {
|
||||||
|
desktop_notification.sound_name(sound_hint);
|
||||||
|
}
|
||||||
|
|
||||||
#[cfg(all(unix, not(target_os = "macos")))]
|
#[cfg(all(unix, not(target_os = "macos")))]
|
||||||
desktop_notification.urgency(notify_rust::Urgency::Normal);
|
desktop_notification.urgency(notify_rust::Urgency::Normal);
|
||||||
|
|
||||||
|
|||||||
@@ -196,6 +196,7 @@ pub fn mock_tunables() -> TunableValues {
|
|||||||
enabled: false,
|
enabled: false,
|
||||||
via: NotifyVia::default(),
|
via: NotifyVia::default(),
|
||||||
show_message: true,
|
show_message: true,
|
||||||
|
sound_hint: None,
|
||||||
},
|
},
|
||||||
image_preview: None,
|
image_preview: None,
|
||||||
user_gutter_width: 30,
|
user_gutter_width: 30,
|
||||||
|
|||||||
Reference in New Issue
Block a user