Skip to main content

notification

@tauri-apps/api / notification

Module: notification

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

This package is also accessible with window.__TAURI__.notification when tauri.conf.json > build > withGlobalTauri is set to true.

The APIs must be allowlisted on tauri.conf.json:

{
"tauri": {
"allowlist": {
"notification": {
"all": true // enable all notification APIs
}
}
}
}

It is recommended to allowlist only the APIs you use for optimal bundle size and security.

Interfaces​

Type Aliases​

Permission​

Ζ¬ Permission: "granted" | "denied" | "default"

Possible permission values.

Defined in​

notification.ts:42

Functions​

isPermissionGranted​

β–Έ isPermissionGranted(): Promise<boolean>

Checks if the permission to send notifications is granted.

example

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

Returns​

Promise<boolean>

Defined in​

notification.ts:54


requestPermission​

β–Έ requestPermission(): Promise<Permission>

Requests the permission to send notifications.

example

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

Returns​

Promise<Permission>

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

Defined in​

notification.ts:80


sendNotification​

β–Έ sendNotification(options): void

Sends a notification to the user.

example

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

Parameters​

NameTypeDescription
optionsstring | OptionsNotification options.

Returns​

void

Defined in​

notification.ts:102