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
+14 -4
View File
@@ -1,16 +1,21 @@
<script>
import { sendNotification } from '@tauri-apps/plugin-notification'
export let onMessage
let sound = ''
// send the notification directly
// the backend is responsible for checking the permission
function _sendNotification() {
new Notification('Notification title', {
body: 'This is the notification body'
sendNotification({
title: 'Notification title',
body: 'This is the notification body',
sound: sound || null
})
}
// alternatively, check the permission ourselves
function sendNotification() {
function triggerNotification() {
if (Notification.permission === 'default') {
Notification.requestPermission()
.then(function (response) {
@@ -29,6 +34,11 @@
}
</script>
<button class="btn" id="notification" on:click={sendNotification}>
<input
class="input grow"
placeholder="Notification sound..."
bind:value={sound}
/>
<button class="btn" id="notification" on:click={triggerNotification}>
Send test notification
</button>