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
+39
View File
@@ -95,6 +95,45 @@ export async function enqueueNotification(title, body) {
}
```
### Notification with Sound
You can add sound to your notifications on all platforms (desktop and mobile):
```javascript
import { sendNotification } from '@tauri-apps/plugin-notification'
import { platform } from '@tauri-apps/api/os'
// Basic notification with sound
sendNotification({
title: 'New Message',
body: 'You have a new message',
sound: 'notification.wav' // Path to sound file
})
// Platform-specific sounds
async function sendPlatformSpecificNotification() {
const platformName = platform()
let soundPath
if (platformName === 'darwin') {
// On macOS: use system sounds or sound files in the app bundle
soundPath = 'Ping' // macOS system sound
} else if (platformName === 'linux') {
// On Linux: use XDG theme sounds or file paths
soundPath = 'message-new-instant' // XDG theme sound
} else {
// On Windows: use file paths
soundPath = 'notification.wav'
}
sendNotification({
title: 'Platform-specific Notification',
body: 'This notification uses platform-specific sound',
sound: soundPath
})
}
```
## Contributing
PRs accepted. Please make sure to read the Contributing Guide before making a pull request.