Skip to content

Notifications

Send native notifications to your user using the notification plugin.

Install the notifications plugin to get started.

  1. Use your project’s package manager to add the dependency:
npm run tauri add notification
  1. Modify lib.rs to initialize the plugin:
#[cfg_attr(mobile, tauri::mobile_entry_point)]
pub fn run() {
tauri::Builder::default()
// Initialize the plugin
.plugin(tauri_plugin_notification::init())
.run(tauri::generate_context!())
.expect("error while running tauri application");
}

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

The notification plugin is available in both JavaScript and Rust.

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';
// 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!' });
}

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


© 2023 Tauri Contributors. CC-BY / MIT