Skip to content
Tutorials Center
My learning

Topics

Lesson 24 of 39 ยท Plugins and Native Features

Notifications, Clipboard, Shortcuts and OS Info

Use Tauri plugins for system notifications, clipboard, global keyboard shortcuts, opening links, OS information and single-instance apps, with runnable stand-ins of shortcut parsing.

What makes a desktop app feel native is the small things: a notification when a download ends, a shortcut that works even when your window is hidden, a clipboard button that copies the result, a link that opens in the user's own browser. Tauri has an official plugin for each. This lesson goes through the most useful ones.

If you have not yet seen how plugins are registered and permitted, read The Tauri Plugin System first. For each plugin, the pattern is always the same: add it, register it in Rust, grant a permission, call the JavaScript API.

Real versus stand-in. The ts, rust and json blocks are real Tauri code. The runnable node blocks model the logic around the features, such as parsing shortcut strings and message formatting, because the real features need a desktop.

Notifications

Terminal
npm run tauri add notification
JSON
{ "permissions": ["core:default", "notification:default"] }
TypeScript
import {
  isPermissionGranted,
  requestPermission,
  sendNotification,
} from '@tauri-apps/plugin-notification';

let allowed = await isPermissionGranted();
if (!allowed) {
  allowed = (await requestPermission()) === 'granted';
}

if (allowed) {
  sendNotification({
    title: 'Export finished',
    body: 'Your report is ready in Downloads.',
  });
}

Always check permission first: on macOS and mobile the user must agree, and on some systems they can switch notifications off at any time. Notify only for events that matter to the user, otherwise people will mute your app. On desktop, notifications also work from Rust through the same plugin (app.notification().builder().title("...").show()). Mobile versions add channels, actions and scheduled notifications.

Clipboard

Terminal
npm run tauri add clipboard-manager
JSON
{ "permissions": ["core:default", "clipboard-manager:allow-read-text", "clipboard-manager:allow-write-text"] }
TypeScript
import { writeText, readText } from '@tauri-apps/plugin-clipboard-manager';

await writeText('https://example.com/share/abc123');
const pasted = await readText();

The browser clipboard API works in a webview only under restrictions (focus, secure contexts), so the plugin is more dependable. It also supports images. Because reading the clipboard can expose passwords the user just copied, grant allow-read-text only if you truly need it. A clipboard-history app does; a "copy link" button does not.

Global shortcuts

Normal keyboard shortcuts only fire when your window has focus. A global shortcut fires from anywhere, even when your app is minimized, like a "quick capture" hotkey.

Terminal
npm run tauri add global-shortcut
Rust
#[cfg(desktop)]
app.handle().plugin(tauri_plugin_global_shortcut::Builder::new().build())?;
TypeScript
import { register, unregister, isRegistered } from '@tauri-apps/plugin-global-shortcut';

await register('CommandOrControl+Shift+K', (event) => {
  if (event.state === 'Pressed') {
    console.log('Quick capture!');
  }
});

// later
await unregister('CommandOrControl+Shift+K');

CommandOrControl means Cmd on macOS and Ctrl elsewhere. Another application may already own a combination, so registration can fail; tell the user and let them pick another. Never grab common shortcuts such as Ctrl+C. Shortcuts are desktop only.

The stand-in below parses shortcut strings the way a library must, including normalizing the modifier names and rejecting invalid input.

Node.js Stand-in: parse and normalize shortcut strings

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with node:readline or process.stdin), it gets the next line from this box.

Do not use window.open for external URLs. Use the opener plugin, which opens the default browser or the registered app for a file.

TypeScript
import { openUrl, openPath, revealItemInDir } from '@tauri-apps/plugin-opener';

await openUrl('https://tauri.app');
await openPath('/home/ada/Documents/report.pdf');
await revealItemInDir('/home/ada/Documents/report.pdf'); // show in the file manager

Opener permissions take scopes: opener:allow-open-url with { "url": "https://*.example.com" } keeps your app from opening arbitrary URLs. (Older Tauri 2 projects may use shell:allow-open from the shell plugin for the same job.)

OS info and process control

TypeScript
import { platform, arch, version, locale } from '@tauri-apps/plugin-os';
import { exit, relaunch } from '@tauri-apps/plugin-process';

console.log(platform(), arch(), version(), await locale());
// for example: "windows" "x86_64" "10.0.26300" "en-US"

await relaunch(); // restart the app, used after an update
await exit(0);

platform() is handy for showing the right shortcut hint (Cmd versus Ctrl) or hiding a feature that is not available on mobile. The os plugin also provides type(), family(), eol() and hostname().

Single instance, autostart, window state

Three small plugins solve problems almost every app has:

  • single-instance: if the user starts the app a second time, focus the first window instead of opening a second copy. Register it first among your plugins and use its callback to receive the second launch's arguments.
  • window-state: remembers each window's size, position and maximized state between launches.
  • autostart: adds your app to the system's login items when the user chooses so. Offer it as a setting, never as a default.
Rust
tauri::Builder::default()
    .plugin(tauri_plugin_single_instance::init(|app, args, _cwd| {
        println!("second launch with {args:?}");
        // bring the existing window to the front here
    }))
    .plugin(tauri_plugin_window_state::Builder::default().build())

Formatting a good notification

The text you send matters as much as the API. The small helper below enforces a few rules: short titles, a body trimmed to a sensible length, and no empty notifications.

Node.js Stand-in: build a tidy notification

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with node:readline or process.stdin), it gets the next line from this box.

Check your understanding

Quick check ยท 5 questions

of 5 answered You scored / 5 ยท perfect!

  1. 1. What must you do before sending a notification?

    Operating systems can require user consent, so check isPermissionGranted() and ask with requestPermission() if needed.
  2. 2. What does CommandOrControl mean in a shortcut string?

    It maps to the platform's main modifier, so one string works on every desktop.
  3. 3. Why is a global shortcut different from a normal key handler?

    Global shortcuts are registered with the operating system, so they trigger from anywhere.
  4. 4. Which plugin should open an external web link in the user's browser?

    The opener plugin hands URLs and paths to the default application and supports URL scopes.
  5. 5. What does the single-instance plugin prevent?

    A second launch is redirected to the first instance, so users do not end up with duplicate windows.

Summary

  • Notifications, clipboard, global shortcuts and opener each follow the same four steps: add, register, permit, call.
  • Check notification permission first, and send only meaningful notifications.
  • Grant clipboard read access sparingly; use URL scopes with the opener plugin.
  • Global shortcuts are desktop-only and can fail if another app owns the combination.
  • os, process, single-instance, window-state and autostart cover everyday app behavior.

Next: Writing a Custom Plugin