Skip to content
Tauri
Releases

@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: index.ts:283


High
High: 4;

Source: index.ts:284


Low
Low: 2;

Source: index.ts:282


Min
Min: 1;

Source: index.ts:281


None
None: 0;

Source: index.ts:280


ScheduleEvery

Enumeration Members

Day
Day: 'day';

Source: index.ts:157


Hour
Hour: 'hour';

Source: index.ts:158


Minute
Minute: 'minute';

Source: index.ts:159


Month
Month: 'month';

Source: index.ts:154


Second
Second: 'second';

Not supported on iOS.

Source: index.ts:163


TwoWeeks
TwoWeeks: 'twoWeeks';

Source: index.ts:155


Week
Week: 'week';

Source: index.ts:156


Year
Year: 'year';

Source: index.ts:153


Visibility

Enumeration Members

Private
Private: 0;

Source: index.ts:289


Public
Public: 1;

Source: index.ts:290


Secret
Secret: -1;

Source: index.ts:288

Classes

Schedule

Constructors

constructor()
new Schedule(): Schedule
Returns

Schedule

Properties

PropertyType
atundefined | {allowWhileIdle: boolean; date: Date; repeating: boolean;}
everyundefined | {allowWhileIdle: boolean; count: number; interval: ScheduleEvery;}
intervalundefined | {allowWhileIdle: boolean; interval: ScheduleInterval;}

Methods

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

Schedule

Source: index.ts:188


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

Schedule

Source: index.ts:207


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

Schedule

Source: index.ts:196

Interfaces

Action

Properties

PropertyType
destructive?boolean
foreground?boolean
idstring
input?boolean
inputButtonTitle?string
inputPlaceholder?string
requiresAuthentication?boolean
titlestring

ActionType

Properties

PropertyTypeDescription
actionsAction[]The list of associated actions
allowInCarPlay?boolean-
customDismissAction?boolean-
hiddenPreviewsBodyPlaceholder?string-
hiddenPreviewsShowSubtitle?boolean-
hiddenPreviewsShowTitle?boolean-
idstringThe identifier of this action type

ActiveNotification

Properties

PropertyType
actionTypeId?string
attachmentsAttachment[]
body?string
dataRecord< string, string >
extraRecord< string, unknown >
group?string
groupSummaryboolean
idnumber
schedule?Schedule
sound?string
tag?string
title?string

Attachment

Attachment of a notification.

Properties

PropertyTypeDescription
idstringAttachment identifier.
urlstringAttachment URL. Accepts the asset and file protocols.

Channel

Properties

PropertyType
description?string
idstring
importance?Importance
lightColor?string
lights?boolean
namestring
sound?string
vibration?boolean
visibility?Visibility

Options

Options to send a notification.

Since

2.0.0

Properties

PropertyTypeDescription
actionTypeId?stringDefines an action type for this notification.
attachments?Attachment[]Notification attachments.
autoCancel?booleanAutomatically cancel the notification when the user clicks on it.
body?stringOptional notification body.
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.
extra?objectExtra payload to store in the notification.
group?stringIdentifier used to group multiple notifications.

https://developer.apple.com/documentation/usernotifications/unmutablenotificationcontent/1649872-threadidentifier
groupSummary?booleanInstructs the system that this notification is the summary of a group on Android.
icon?stringNotification icon.

On Android the icon must be placed in the app’s res/drawable folder.
iconColor?stringIcon color on Android.
id?numberThe 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?stringMultiline text.
Changes the notification style to big text.
Cannot be used with inboxLines.
largeIcon?stringNotification large icon (Android).

The icon must be placed in the app’s res/drawable folder.
number?numberSets the number of items this notification represents on Android.
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).
schedule?ScheduleSchedule this notification to fire on a later time or a fixed interval.
silent?booleanChanges the notification presentation to be silent on iOS (no badge, no sound, not listed).
sound?stringThe sound resource name. Only available on mobile.
summary?stringDetail text for the notification with largeBody, inboxLines or groupSummary.
titlestringNotification title.
visibility?VisibilityNotification visibility.

PendingNotification

Properties

PropertyType
body?string
idnumber
scheduleSchedule
title?string

Type Aliases

Permission

Permission: 'granted' | 'denied' | 'default';

Possible permission values.

Source: index.ts:306


ScheduleInterval

ScheduleInterval: object;

Type declaration

MemberTypeDescription
day?number-
hour?number-
minute?number-
month?number-
second?number-
weekday?number1 - Sunday
2 - Monday
3 - Tuesday
4 - Wednesday
5 - Thursday
6 - Friday
7 - Saturday
year?number-

Source: index.ts:133

Functions

active()

active(): Promise< ActiveNotification[] >

Retrieves the list of active notifications.

Example

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

Since

2.0.0

Returns

Promise< ActiveNotification[] >

A promise resolving to the list of active notifications.

Source: index.ts:460


cancel()

cancel(notifications): Promise< void >

Cancels the pending notifications with the given list of identifiers.

Example

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

Since

2.0.0

Parameters

ParameterType
notificationsnumber[]

Returns

Promise< void >

A promise indicating the success or failure of the operation.

Source: index.ts:426


cancelAll()

cancelAll(): Promise< void >

Cancels all pending notifications.

Example

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

Since

2.0.0

Returns

Promise< void >

A promise indicating the success or failure of the operation.

Source: index.ts:443


channels()

channels(): Promise< Channel[] >

Retrieves the list of notification channels.

Example

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

Since

2.0.0

Returns

Promise< Channel[] >

A promise resolving to the list of notification channels.

Source: index.ts:554


createChannel()

createChannel(channel): Promise< void >

Creates a notification channel.

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

Parameters

ParameterType
channelChannel

Returns

Promise< void >

A promise indicating the success or failure of the operation.

Source: index.ts:520


isPermissionGranted()

isPermissionGranted(): Promise< boolean >

Checks if the permission to send notifications is granted.

Example

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

Since

2.0.0

Returns

Promise< boolean >

Source: index.ts:318


onAction()

onAction(cb): Promise< PluginListener >

Parameters

ParameterType
cb(notification) => void

Returns

Promise< PluginListener >

Source: index.ts:564


onNotificationReceived()

onNotificationReceived(cb): Promise< PluginListener >

Parameters

ParameterType
cb(notification) => void

Returns

Promise< PluginListener >

Source: index.ts:558


pending()

pending(): Promise< PendingNotification[] >

Retrieves the list of pending notifications.

Example

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

Since

2.0.0

Returns

Promise< PendingNotification[] >

A promise resolving to the list of pending notifications.

Source: index.ts:409


registerActionTypes()

registerActionTypes(types): Promise< void >

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

Example

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

Since

2.0.0

Parameters

ParameterType
typesActionType[]

Returns

Promise< void >

A promise indicating the success or failure of the operation.

Source: index.ts:392


removeActive()

removeActive(notifications): Promise< void >

Removes the active notifications with the given list of identifiers.

Example

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

Since

2.0.0

Parameters

ParameterType
notifications{id: number; tag: string;}[]

Returns

Promise< void >

A promise indicating the success or failure of the operation.

Source: index.ts:477


removeAllActive()

removeAllActive(): Promise< void >

Removes all active notifications.

Example

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

Since

2.0.0

Returns

Promise< void >

A promise indicating the success or failure of the operation.

Source: index.ts:496


removeChannel()

removeChannel(id): Promise< void >

Removes the channel with the given identifier.

Example

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

Since

2.0.0

Parameters

ParameterType
idstring

Returns

Promise< void >

A promise indicating the success or failure of the operation.

Source: index.ts:537


requestPermission()

requestPermission(): Promise< Permission >

Requests the permission to send notifications.

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

Returns

Promise< Permission >

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

Source: index.ts:341


sendNotification()

sendNotification(options): void

Sends a notification to the user.

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

Parameters

ParameterType
optionsstring | Options

Returns

void

Source: index.ts:363


© 2024 Tauri Contributors. CC-BY / MIT