Skip to content
Tauri

Notifications

Send native notifications to your user using the notification plugin.

Setup

Install the notifications plugin to get started.

Use your project’s package manager to add the dependency:

npm run tauri add notification

Usage

Here are a few examples of how to use the notification plugin:

The notification plugin is available in both JavaScript and Rust.

Send Notification

Follow these steps to send a notification:

  1. Check if permission is granted

  2. Request permission if not granted

  3. Send the notification

import {
isPermissionGranted,
requestPermission,
sendNotification,
} from '@tauri-apps/plugin-notification';
// when using `"withGlobalTauri": true`, you may use
// const { isPermissionGranted, requestPermission, sendNotification, } = window.__TAURI_PLUGIN_NOTIFICATION__;
// Do you have permission to send a notification?
let permissionGranted = await isPermissionGranted();
// If not we need to request it
if (!permissionGranted) {
const permission = await requestPermission();
permissionGranted = permission === 'granted';
}
// Once permission has been granted we can send the notification
if (permissionGranted) {
sendNotification({ title: 'Tauri', body: 'Tauri is awesome!' });
}

Actions

Attachments

Channels

Security Considerations

Aside from normal sanitization procedures of user input there are currently no known security considerations.

Default Permission

This permission set configures which notification features are by default exposed.

Granted Permissions

It allows all notification related features.

  • allow-is-permission-granted
  • allow-request-permission
  • allow-notify
  • allow-register-action-types
  • allow-register-listener
  • allow-cancel
  • allow-get-pending
  • allow-remove-active
  • allow-get-active
  • allow-check-permissions
  • allow-show
  • allow-batch
  • allow-list-channels
  • allow-delete-channel
  • allow-create-channel
  • allow-permission-state

Permission Table

Identifier Description

notification:allow-batch

Enables the batch command without any pre-configured scope.

notification:deny-batch

Denies the batch command without any pre-configured scope.

notification:allow-cancel

Enables the cancel command without any pre-configured scope.

notification:deny-cancel

Denies the cancel command without any pre-configured scope.

notification:allow-check-permissions

Enables the check_permissions command without any pre-configured scope.

notification:deny-check-permissions

Denies the check_permissions command without any pre-configured scope.

notification:allow-create-channel

Enables the create_channel command without any pre-configured scope.

notification:deny-create-channel

Denies the create_channel command without any pre-configured scope.

notification:allow-delete-channel

Enables the delete_channel command without any pre-configured scope.

notification:deny-delete-channel

Denies the delete_channel command without any pre-configured scope.

notification:allow-get-active

Enables the get_active command without any pre-configured scope.

notification:deny-get-active

Denies the get_active command without any pre-configured scope.

notification:allow-get-pending

Enables the get_pending command without any pre-configured scope.

notification:deny-get-pending

Denies the get_pending command without any pre-configured scope.

notification:allow-is-permission-granted

Enables the is_permission_granted command without any pre-configured scope.

notification:deny-is-permission-granted

Denies the is_permission_granted command without any pre-configured scope.

notification:allow-list-channels

Enables the list_channels command without any pre-configured scope.

notification:deny-list-channels

Denies the list_channels command without any pre-configured scope.

notification:allow-notify

Enables the notify command without any pre-configured scope.

notification:deny-notify

Denies the notify command without any pre-configured scope.

notification:allow-permission-state

Enables the permission_state command without any pre-configured scope.

notification:deny-permission-state

Denies the permission_state command without any pre-configured scope.

notification:allow-register-action-types

Enables the register_action_types command without any pre-configured scope.

notification:deny-register-action-types

Denies the register_action_types command without any pre-configured scope.

notification:allow-register-listener

Enables the register_listener command without any pre-configured scope.

notification:deny-register-listener

Denies the register_listener command without any pre-configured scope.

notification:allow-remove-active

Enables the remove_active command without any pre-configured scope.

notification:deny-remove-active

Denies the remove_active command without any pre-configured scope.

notification:allow-request-permission

Enables the request_permission command without any pre-configured scope.

notification:deny-request-permission

Denies the request_permission command without any pre-configured scope.

notification:allow-show

Enables the show command without any pre-configured scope.

notification:deny-show

Denies the show command without any pre-configured scope.


© 2024 Tauri Contributors. CC-BY / MIT