mirror of
https://github.com/tauri-apps/plugins-workspace.git
synced 2026-04-27 11:56:05 +02:00
e438e0a62d
Co-authored-by: Amr Bashir <amr.bashir2015@gmail.com>
35 lines
919 B
Svelte
35 lines
919 B
Svelte
<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>
|