mirror of
https://github.com/tauri-apps/plugins-workspace.git
synced 2026-04-23 11:36:13 +02:00
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:
@@ -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();
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user