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 build.withGlobalTauri in tauri.conf.json is set to true.
The APIs must be added to tauri.allowlist.notification in 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
Options
Options to send a notification.
Since: 1.0.0
Properties
body
Optionalbody:string
Optional notification body.
Defined in: notification.ts:38
icon
Optionalicon:string
Optional notification icon.
Defined in: notification.ts:40
title
title:
string
Notification title.
Defined in: notification.ts:36
Type Aliases
Permission
Permission:
"granted"|"denied"|"default"
Possible permission values.
Defined in: notification.ts:44
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();
Since: 1.0.0
Returns: Promise<boolean>
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';
}
Since: 1.0.0
Returns: Promise<Permission>
A promise resolving to whether the user granted the permission or not.
sendNotification
sendNotification(
options:string|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!' });
}
Since: 1.0.0
Parameters
| Name | Type | 
|---|---|
| options | string|Options | 
Returns: void