Skip to content
Tauri 中文网

@tauri-apps/plugin-notification

Send toast notifications (brief auto-expiring OS window element) to your user. Can also be used with the Notification Web API.

Enumerations

Importance

Enumeration Members

Default
Default: 3;

Source: undefined

High
High: 4;

Source: undefined

Low
Low: 2;

Source: undefined

Min
Min: 1;

Source: undefined

None
None: 0;

Source: undefined


ScheduleEvery

Enumeration Members

Day
Day: "day";

Source: undefined

Hour
Hour: "hour";

Source: undefined

Minute
Minute: "minute";

Source: undefined

Month
Month: "month";

Source: undefined

Second
Second: "second";

Not supported on iOS.

Source: undefined

TwoWeeks
TwoWeeks: "twoWeeks";

Source: undefined

Week
Week: "week";

Source: undefined

Year
Year: "year";

Source: undefined


Visibility

Enumeration Members

Private
Private: 0;

Source: undefined

Public
Public: 1;

Source: undefined

Secret
Secret: -1;

Source: undefined

Classes

Schedule

Constructors

new Schedule()
new Schedule(): Schedule
Returns

Schedule

Properties

PropertyTypeDefined in
atundefined | objectSource: undefined
everyundefined | objectSource: undefined
intervalundefined | objectSource: undefined

Methods

at()
static at(
date,
repeating,
allowWhileIdle): Schedule
Parameters
ParameterTypeDefault value
dateDateundefined
repeatingbooleanfalse
allowWhileIdlebooleanfalse
Returns

Schedule

Source: undefined

every()
static every(
kind,
count,
allowWhileIdle): Schedule
Parameters
ParameterTypeDefault value
kindScheduleEveryundefined
countnumberundefined
allowWhileIdlebooleanfalse
Returns

Schedule

Source: undefined

interval()
static interval(interval, allowWhileIdle): Schedule
Parameters
ParameterTypeDefault value
intervalScheduleIntervalundefined
allowWhileIdlebooleanfalse
Returns

Schedule

Source: undefined

Interfaces

Action

Properties

PropertyTypeDefined in
destructive?booleanSource: undefined
foreground?booleanSource: undefined
idstringSource: undefined
input?booleanSource: undefined
inputButtonTitle?stringSource: undefined
inputPlaceholder?stringSource: undefined
requiresAuthentication?booleanSource: undefined
titlestringSource: undefined

ActionType

Properties

PropertyTypeDescriptionDefined in
actionsAction[]The list of associated actionsSource: undefined
allowInCarPlay?boolean-Source: undefined
customDismissAction?boolean-Source: undefined
hiddenPreviewsBodyPlaceholder?string-Source: undefined
hiddenPreviewsShowSubtitle?boolean-Source: undefined
hiddenPreviewsShowTitle?boolean-Source: undefined
idstringThe identifier of this action typeSource: undefined

ActiveNotification

Properties

PropertyTypeDefined in
actionTypeId?stringSource: undefined
attachmentsAttachment[]Source: undefined
body?stringSource: undefined
dataRecord<string, string>Source: undefined
extraRecord<string, unknown>Source: undefined
group?stringSource: undefined
groupSummarybooleanSource: undefined
idnumberSource: undefined
schedule?ScheduleSource: undefined
sound?stringSource: undefined
tag?stringSource: undefined
title?stringSource: undefined

Attachment

Attachment of a notification.

Properties

PropertyTypeDescriptionDefined in
idstringAttachment identifier.Source: undefined
urlstringAttachment URL. Accepts the asset and file protocols.Source: undefined

Channel

Properties

PropertyTypeDefined in
description?stringSource: undefined
idstringSource: undefined
importance?ImportanceSource: undefined
lightColor?stringSource: undefined
lights?booleanSource: undefined
namestringSource: undefined
sound?stringSource: undefined
vibration?booleanSource: undefined
visibility?VisibilitySource: undefined

Options

Options to send a notification.

Since

2.0.0

Properties

PropertyTypeDescriptionDefined in
actionTypeId?stringDefines an action type for this notification.Source: undefined
attachments?Attachment[]Notification attachments.Source: undefined
autoCancel?booleanAutomatically cancel the notification when the user clicks on it.Source: undefined
body?stringOptional notification body.Source: undefined
channelId?stringIdentifier 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.Source: undefined
extra?Record<string, unknown>Extra payload to store in the notification.Source: undefined
group?stringIdentifier used to group multiple notifications. https://developer.apple.com/documentation/usernotifications/unmutablenotificationcontent/1649872-threadidentifierSource: undefined
groupSummary?booleanInstructs the system that this notification is the summary of a group on Android.Source: undefined
icon?stringNotification icon. On Android the icon must be placed in the app’s res/drawable folder.Source: undefined
iconColor?stringIcon color on Android.Source: undefined
id?numberThe notification identifier to reference this object later. Must be a 32-bit integer.Source: undefined
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.Source: undefined
largeBody?stringMultiline text. Changes the notification style to big text. Cannot be used with inboxLines.Source: undefined
largeIcon?stringNotification large icon (Android). The icon must be placed in the app’s res/drawable folder.Source: undefined
number?numberSets the number of items this notification represents on Android.Source: undefined
ongoing?booleanIf 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).Source: undefined
schedule?ScheduleSchedule this notification to fire on a later time or a fixed interval.Source: undefined
silent?booleanChanges the notification presentation to be silent on iOS (no badge, no sound, not listed).Source: undefined
sound?stringThe sound resource name. Only available on mobile.Source: undefined
summary?stringDetail text for the notification with largeBody, inboxLines or groupSummary.Source: undefined
titlestringNotification title.Source: undefined
visibility?VisibilityNotification visibility.Source: undefined

PendingNotification

Properties

PropertyTypeDefined in
body?stringSource: undefined
idnumberSource: undefined
scheduleScheduleSource: undefined
title?stringSource: undefined

ScheduleInterval

Properties

PropertyTypeDescriptionDefined in
day?number-Source: undefined
hour?number-Source: undefined
minute?number-Source: undefined
month?number-Source: undefined
second?number-Source: undefined
weekday?number1 - Sunday 2 - Monday 3 - Tuesday 4 - Wednesday 5 - Thursday 6 - Friday 7 - SaturdaySource: undefined
year?number-Source: undefined

Type Aliases

PermissionState

type PermissionState: "granted" | "denied" | "prompt" | "prompt-with-rationale";

Source: undefined

Functions

active()

function active(): Promise<ActiveNotification[]>

Retrieves the list of active notifications.

Returns

Promise<ActiveNotification[]>

A promise resolving to the list of active notifications.

Example

import { active } from '@tauri-apps/plugin-notification';
const activeNotifications = await active();

Since

2.0.0

Source: undefined


cancel()

function cancel(notifications): Promise<void>

Cancels the pending notifications with the given list of identifiers.

Parameters

ParameterType
notificationsnumber[]

Returns

Promise<void>

A promise indicating the success or failure of the operation.

Example

import { cancel } from '@tauri-apps/plugin-notification';
await cancel([-34234, 23432, 4311]);

Since

2.0.0

Source: undefined


cancelAll()

function cancelAll(): Promise<void>

Cancels all pending notifications.

Returns

Promise<void>

A promise indicating the success or failure of the operation.

Example

import { cancelAll } from '@tauri-apps/plugin-notification';
await cancelAll();

Since

2.0.0

Source: undefined


channels()

function channels(): Promise<Channel[]>

Retrieves the list of notification channels.

Returns

Promise<Channel[]>

A promise resolving to the list of notification channels.

Example

import { channels } from '@tauri-apps/plugin-notification';
const notificationChannels = await channels();

Since

2.0.0

Source: undefined


createChannel()

function createChannel(channel): Promise<void>

Creates a notification channel.

Parameters

ParameterType
channelChannel

Returns

Promise<void>

A promise indicating the success or failure of the operation.

Example

import { createChannel, Importance, Visibility } from '@tauri-apps/plugin-notification';
await createChannel({
id: 'new-messages',
name: 'New Messages',
lights: true,
vibration: true,
importance: Importance.Default,
visibility: Visibility.Private
});

Since

2.0.0

Source: undefined


isPermissionGranted()

function isPermissionGranted(): Promise<boolean>

Checks if the permission to send notifications is granted.

Returns

Promise<boolean>

Example

import { isPermissionGranted } from '@tauri-apps/plugin-notification';
const permissionGranted = await isPermissionGranted();

Since

2.0.0

Source: undefined


onAction()

function onAction(cb): Promise<PluginListener>

Parameters

ParameterType
cb(notification) => void

Returns

Promise<PluginListener>

Source: undefined


onNotificationReceived()

function onNotificationReceived(cb): Promise<PluginListener>

Parameters

ParameterType
cb(notification) => void

Returns

Promise<PluginListener>

Source: undefined


pending()

function pending(): Promise<PendingNotification[]>

Retrieves the list of pending notifications.

Returns

Promise<PendingNotification[]>

A promise resolving to the list of pending notifications.

Example

import { pending } from '@tauri-apps/plugin-notification';
const pendingNotifications = await pending();

Since

2.0.0

Source: undefined


registerActionTypes()

function registerActionTypes(types): Promise<void>

Register actions that are performed when the user clicks on the notification.

Parameters

ParameterType
typesActionType[]

Returns

Promise<void>

A promise indicating the success or failure of the operation.

Example

import { registerActionTypes } from '@tauri-apps/plugin-notification';
await registerActionTypes([{
id: 'tauri',
actions: [{
id: 'my-action',
title: 'Settings'
}]
}])

Since

2.0.0

Source: undefined


removeActive()

function removeActive(notifications): Promise<void>

Removes the active notifications with the given list of identifiers.

Parameters

ParameterType
notificationsobject[]

Returns

Promise<void>

A promise indicating the success or failure of the operation.

Example

import { cancel } from '@tauri-apps/plugin-notification';
await cancel([-34234, 23432, 4311])

Since

2.0.0

Source: undefined


removeAllActive()

function removeAllActive(): Promise<void>

Removes all active notifications.

Returns

Promise<void>

A promise indicating the success or failure of the operation.

Example

import { removeAllActive } from '@tauri-apps/plugin-notification';
await removeAllActive()

Since

2.0.0

Source: undefined


removeChannel()

function removeChannel(id): Promise<void>

Removes the channel with the given identifier.

Parameters

ParameterType
idstring

Returns

Promise<void>

A promise indicating the success or failure of the operation.

Example

import { removeChannel } from '@tauri-apps/plugin-notification';
await removeChannel();

Since

2.0.0

Source: undefined


requestPermission()

function requestPermission(): Promise<NotificationPermission>

Requests the permission to send notifications.

Returns

Promise<NotificationPermission>

A promise resolving to whether the user granted the permission or not.

Example

import { isPermissionGranted, requestPermission } from '@tauri-apps/plugin-notification';
let permissionGranted = await isPermissionGranted();
if (!permissionGranted) {
const permission = await requestPermission();
permissionGranted = permission === 'granted';
}

Since

2.0.0

Source: undefined


sendNotification()

function sendNotification(options): void

Sends a notification to the user.

Parameters

ParameterType
optionsstring | Options

Returns

void

Example

import { isPermissionGranted, requestPermission, sendNotification } from '@tauri-apps/plugin-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!' });
}

Since

2.0.0

Source: undefined


Tauri 中文网 - 粤ICP备13048890号