Add sound support for desktop notifications in Tauri v2 (#2678)

* Add sound support for desktop notifications in Tauri v2

* ci

---------

Co-authored-by: Lucas Nogueira <lucas@tauri.app>
This commit is contained in:
Keerthi
2025-08-21 13:05:27 +00:00
committed by GitHub
parent 21d721a0c2
commit 2d03e2eac2
6 changed files with 83 additions and 6 deletions
+16
View File
@@ -39,6 +39,9 @@ impl<R: Runtime> crate::NotificationBuilder<R> {
if let Some(icon) = self.data.icon {
notification = notification.icon(icon);
}
if let Some(sound) = self.data.sound {
notification = notification.sound(sound);
}
#[cfg(feature = "windows7-compat")]
{
notification.notify(&self.app)?;
@@ -102,6 +105,8 @@ mod imp {
title: Option<String>,
/// The notification icon.
icon: Option<String>,
/// The notification sound.
sound: Option<String>,
/// The notification identifier
identifier: String,
}
@@ -136,6 +141,13 @@ mod imp {
self
}
/// Sets the notification sound file.
#[must_use]
pub fn sound(mut self, sound: impl Into<String>) -> Self {
self.sound = Some(sound.into());
self
}
/// Shows the notification.
///
/// # Examples
@@ -177,6 +189,9 @@ mod imp {
} else {
notification.auto_icon();
}
if let Some(sound) = self.sound {
notification.sound_name(&sound);
}
#[cfg(windows)]
{
let exe = tauri::utils::platform::current_exe()?;
@@ -250,6 +265,7 @@ mod imp {
}
}
/// Shows the notification on Windows 7.
#[cfg(all(windows, feature = "windows7-compat"))]
fn notify_win7<R: tauri::Runtime>(self, app: &tauri::AppHandle<R>) -> crate::Result<()> {
let app_ = app.clone();
+1 -1
View File
@@ -132,7 +132,7 @@ impl<R: Runtime> NotificationBuilder<R> {
self
}
/// The sound resource name. Only available on mobile.
/// The sound resource name for the notification.
pub fn sound(mut self, sound: impl Into<String>) -> Self {
self.data.sound.replace(sound.into());
self