Download packages/tauri-plugins/examples/api/src/views/Notifications.svelte from echodict/readest: direct link, hf CLI and curl.
- Browser
- Download file 1.14 kB
-
https://huggingface.co/datasets/echodict/readest/resolve/main/packages/tauri-plugins/examples/api/src/views/Notifications.svelte
- Command line
-
hf download hf://datasets/echodict/readest/packages/tauri-plugins/examples/api/src/views/Notifications.svelte
-
curl -L -o Notifications.svelte https://huggingface.co/datasets/echodict/readest/resolve/main/packages/tauri-plugins/examples/api/src/views/Notifications.svelte
1.14 kB
| <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() { | |
| sendNotification({ | |
| title: 'Notification title', | |
| body: 'This is the notification body', | |
| sound: sound || null | |
| }) | |
| } | |
| // alternatively, check the permission ourselves | |
| function triggerNotification() { | |
| 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> | |
| <input | |
| class="input grow" | |
| placeholder="Notification sound..." | |
| bind:value={sound} | |
| /> | |
| <button class="btn" id="notification" on:click={triggerNotification}> | |
| Send test notification | |
| </button> | |