mirror of
https://github.com/tauri-apps/plugins-workspace.git
synced 2026-04-29 12:06:01 +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:
@@ -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.
|
||||
|
||||
Reference in New Issue
Block a user