You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
tauri-plugins-workspace/examples/api/src/views/Notifications.svelte

35 lines
919 B

<script>
export let onMessage
// send the notification directly
// the backend is responsible for checking the permission
function _sendNotification() {
new Notification('Notification title', {
body: 'This is the notification body'
})
}
// alternatively, check the permission ourselves
function sendNotification() {
if (Notification.permission === 'default') {
Notification.requestPermission()
.then(function (response) {
if (response === 'granted') {
_sendNotification()
} else {
onMessage('Permission is ' + response)
}
})
.catch(onMessage)
} else if (Notification.permission === 'granted') {
_sendNotification()
} else {
onMessage('Permission is denied')
}
}
</script>
<button class="btn" id="notification" on:click={sendNotification}>
Send test notification
</button>