notification
Send toast notifications (brief auto-expiring OS window element) to your user. Can also be used with the Notification Web API.
Re-exports PermissionState
Default: 3;High: 4;Low: 2;Min: 1;None: 0;Day: "day";Hour: "hour";Minute: "minute";Month: "month";Second: "second";Not supported on iOS.
TwoWeeks: "twoWeeks";Week: "week";Year: "year";Private: 0;Public: 1;Secret: -1;new Schedule(): Schedule| Property | Type | Defined in |
|---|---|---|
at | undefined | object | |
every | undefined | object | |
interval | undefined | object |
static at( date, repeating, allowWhileIdle): Schedule| Parameter | Type | Default value |
|---|---|---|
date | Date | undefined |
repeating | boolean | false |
allowWhileIdle | boolean | false |
static every( kind, count, allowWhileIdle): Schedule| Parameter | Type | Default value |
|---|---|---|
kind | ScheduleEvery | undefined |
count | number | undefined |
allowWhileIdle | boolean | false |
static interval(interval, allowWhileIdle): Schedule| Parameter | Type | Default value |
|---|---|---|
interval | ScheduleInterval | undefined |
allowWhileIdle | boolean | false |
| Property | Type | Defined in |
|---|---|---|
destructive? | boolean | |
foreground? | boolean | |
id | string | |
input? | boolean | |
inputButtonTitle? | string | |
inputPlaceholder? | string | |
requiresAuthentication? | boolean | |
title | string |
| Property | Type | Description | Defined in |
|---|---|---|---|
actions | Action[] | The list of associated actions | |
allowInCarPlay? | boolean | - | |
customDismissAction? | boolean | - | |
hiddenPreviewsBodyPlaceholder? | string | - | |
hiddenPreviewsShowSubtitle? | boolean | - | |
hiddenPreviewsShowTitle? | boolean | - | |
id | string | The identifier of this action type |
| Property | Type | Defined in |
|---|---|---|
actionTypeId? | string | |
attachments | Attachment[] | |
body? | string | |
data | Record<string, string> | |
extra | Record<string, unknown> | |
group? | string | |
groupSummary | boolean | |
id | number | |
schedule? | Schedule | |
sound? | string | |
tag? | string | |
title? | string |
Attachment of a notification.
| Property | Type | Description | Defined in |
|---|---|---|---|
id | string | Attachment identifier. | |
url | string | Attachment URL. Accepts the asset and file protocols. |
| Property | Type | Defined in |
|---|---|---|
description? | string | |
id | string | |
importance? | Importance | |
lightColor? | string | |
lights? | boolean | |
name | string | |
sound? | string | |
vibration? | boolean | |
visibility? | Visibility |
Options to send a notification.
| Property | Type | Description | Defined in |
|---|---|---|---|
actionTypeId? | string | Defines an action type for this notification. | |
attachments? | Attachment[] | Notification attachments. | |
autoCancel? | boolean | Automatically cancel the notification when the user clicks on it. | |
body? | string | Optional notification body. | |
channelId? | string | Identifier of the Channel that deliveres this notification. If the channel does not exist, the notification won’t fire. Make sure the channel exists with listChannels and createChannel. | |
extra? | Record<string, unknown> | Extra payload to store in the notification. | |
group? | string | Identifier used to group multiple notifications. https://developer.apple.com/documentation/usernotifications/unmutablenotificationcontent/1649872-threadidentifier | |
groupSummary? | boolean | Instructs the system that this notification is the summary of a group on Android. | |
icon? | string | Notification icon. On Android the icon must be placed in the app’s res/drawable folder. | |
iconColor? | string | Icon color on Android. | |
id? | number | The notification identifier to reference this object later. Must be a 32-bit integer. | |
inboxLines? | string[] | List of lines to add to the notification. Changes the notification style to inbox. Cannot be used with largeBody. Only supports up to 5 lines. | |
largeBody? | string | Multiline text. Changes the notification style to big text. Cannot be used with inboxLines. | |
largeIcon? | string | Notification large icon (Android). The icon must be placed in the app’s res/drawable folder. | |
number? | number | Sets the number of items this notification represents on Android. | |
ongoing? | boolean | If true, the notification cannot be dismissed by the user on Android. An application service must manage the dismissal of the notification. It is typically used to indicate a background task that is pending (e.g. a file download) or the user is engaged with (e.g. playing music). | |
schedule? | Schedule | Schedule this notification to fire on a later time or a fixed interval. | |
silent? | boolean | Changes the notification presentation to be silent on iOS (no badge, no sound, not listed). | |
sound? | string | The sound resource name. Only available on mobile. | |
summary? | string | Detail text for the notification with largeBody, inboxLines or groupSummary. | |
title | string | Notification title. | |
visibility? | Visibility | Notification visibility. |
| Property | Type | Defined in |
|---|---|---|
body? | string | |
id | number | |
schedule | Schedule | |
title? | string |
function active(): Promise<ActiveNotification[]>Retrieves the list of active notifications.
A promise resolving to the list of active notifications.
import { active } from '@crabnebula/taurify-api/notification';const activeNotifications = await active();function cancel(notifications): Promise<void>Cancels the pending notifications with the given list of identifiers.
| Parameter | Type |
|---|---|
notifications | number[] |
Promise<void>
A promise indicating the success or failure of the operation.
import { cancel } from '@crabnebula/taurify-api/notification';await cancel([-34234, 23432, 4311]);function cancelAll(): Promise<void>Cancels all pending notifications.
Promise<void>
A promise indicating the success or failure of the operation.
import { cancelAll } from '@crabnebula/taurify-api/notification';await cancelAll();function channels(): Promise<Channel[]>Retrieves the list of notification channels.
A promise resolving to the list of notification channels.
import { channels } from '@crabnebula/taurify-api/notification';const notificationChannels = await channels();function createChannel(channel): Promise<void>Creates a notification channel.
| Parameter | Type |
|---|---|
channel | Channel |
Promise<void>
A promise indicating the success or failure of the operation.
import { createChannel, Importance, Visibility } from '@crabnebula/taurify-api/notification';await createChannel({ id: 'new-messages', name: 'New Messages', lights: true, vibration: true, importance: Importance.Default, visibility: Visibility.Private});function isPermissionGranted(): Promise<boolean>Checks if the permission to send notifications is granted.
Promise<boolean>
import { isPermissionGranted } from '@crabnebula/taurify-api/notification';const permissionGranted = await isPermissionGranted();function onAction(cb): Promise<PluginListener>| Parameter | Type |
|---|---|
cb | (notification) => void |
function onNotificationReceived(cb): Promise<PluginListener>| Parameter | Type |
|---|---|
cb | (notification) => void |
function pending(): Promise<PendingNotification[]>Retrieves the list of pending notifications.
Promise<PendingNotification[]>
A promise resolving to the list of pending notifications.
import { pending } from '@crabnebula/taurify-api/notification';const pendingNotifications = await pending();function registerActionTypes(types): Promise<void>Register actions that are performed when the user clicks on the notification.
| Parameter | Type |
|---|---|
types | ActionType[] |
Promise<void>
A promise indicating the success or failure of the operation.
import { registerActionTypes } from '@crabnebula/taurify-api/notification';await registerActionTypes([{ id: 'tauri', actions: [{ id: 'my-action', title: 'Settings' }]}])function removeActive(notifications): Promise<void>Removes the active notifications with the given list of identifiers.
| Parameter | Type |
|---|---|
notifications | object[] |
Promise<void>
A promise indicating the success or failure of the operation.
import { cancel } from '@crabnebula/taurify-api/notification';await cancel([-34234, 23432, 4311])function removeAllActive(): Promise<void>Removes all active notifications.
Promise<void>
A promise indicating the success or failure of the operation.
import { removeAllActive } from '@crabnebula/taurify-api/notification';await removeAllActive()function removeChannel(id): Promise<void>Removes the channel with the given identifier.
| Parameter | Type |
|---|---|
id | string |
Promise<void>
A promise indicating the success or failure of the operation.
import { removeChannel } from '@crabnebula/taurify-api/notification';await removeChannel();function requestPermission(): Promise<NotificationPermission>Requests the permission to send notifications.
Promise<NotificationPermission>
A promise resolving to whether the user granted the permission or not.
import { isPermissionGranted, requestPermission } from '@crabnebula/taurify-api/notification';let permissionGranted = await isPermissionGranted();if (!permissionGranted) { const permission = await requestPermission(); permissionGranted = permission === 'granted';}function sendNotification(options): voidSends a notification to the user.
| Parameter | Type |
|---|---|
options | string | Options |
void
import { isPermissionGranted, requestPermission, sendNotification } from '@crabnebula/taurify-api/notification';let permissionGranted = await isPermissionGranted();if (!permissionGranted) { const permission = await requestPermission(); permissionGranted = permission === 'granted';}if (permissionGranted) { sendNotification('Tauri is awesome!'); sendNotification({ title: 'TAURI', body: 'Tauri is awesome!' });}