Skip to content
Tutorials Center
My learning

Topics

Lesson 38 of 39 ยท Projects and Practice

Project: A Clipboard History Manager with Tauri

Build a clipboard history manager with Tauri 2: clipboard plugin, global shortcut, tray icon, a popup window, duplicate and sensitive-data handling, and a runnable history model with search and pinning.

A clipboard manager is the perfect "small tool that lives in the background" project. It starts with the system, sits in the tray, remembers what you copied, and pops up with one keyboard shortcut so you can paste something from ten minutes ago. It uses nearly everything from Notifications, Clipboard, Shortcuts and OS Info, plus careful thinking about privacy, which is the real challenge here.

Real versus stand-in. The bash, rust, json and ts blocks are real Tauri 2 code. The runnable blocks implement the history logic (dedupe, limits, pinning, search, privacy filter) in JavaScript, because the clipboard needs a real desktop.

Requirements and privacy first

  1. Remember the last 100 text items copied, newest first.
  2. A global shortcut (CommandOrControl+Shift+V) shows a small popup window; pressing Escape or clicking away hides it.
  3. Selecting an item copies it back and closes the popup.
  4. Pin items so they never expire; search the list.
  5. Live in the tray with a menu: Show, Pause recording, Clear history, Quit.

Privacy matters more than features. The clipboard often holds passwords and tokens. Decisions to make on day one:

  • A pause switch, and automatic skipping of content that looks sensitive (long random strings, credit-card-like numbers, items from known password managers when the OS reports the source).
  • History stays local; never send it anywhere.
  • Store it with a size and age limit, and offer "Clear history". Consider not saving to disk at all by default.
  • Do not log clipboard contents.

Setup

Terminal
npm create tauri-app@latest clip-history
cd clip-history
npm run tauri add clipboard-manager
npm run tauri add global-shortcut
npm run tauri add store

Enable the tray in Cargo.toml: tauri = { version = "2", features = ["tray-icon"] }. Hide the main window at startup in tauri.conf.json ("visible": false) and let it be a popup:

JSON
{
  "app": {
    "windows": [
      {
        "label": "main",
        "title": "Clipboard",
        "width": 420,
        "height": 520,
        "visible": false,
        "decorations": false,
        "alwaysOnTop": true,
        "skipTaskbar": true,
        "resizable": false
      }
    ]
  }
}

Capability for main:

JSON
{
  "identifier": "popup",
  "windows": ["main"],
  "permissions": [
    "core:default",
    "core:window:allow-hide",
    "core:window:allow-show",
    "core:window:allow-set-focus",
    "clipboard-manager:allow-read-text",
    "clipboard-manager:allow-write-text",
    "store:default"
  ]
}

Rust: tray, shortcut and the popup

Rust
use tauri::{
    menu::{Menu, MenuItem},
    tray::TrayIconBuilder,
    AppHandle, Manager,
};
use tauri_plugin_global_shortcut::{Code, Modifiers, Shortcut, ShortcutState};

fn toggle_popup(app: &AppHandle) {
    if let Some(window) = app.get_webview_window("main") {
        if window.is_visible().unwrap_or(false) {
            let _ = window.hide();
        } else {
            let _ = window.center();
            let _ = window.show();
            let _ = window.set_focus();
        }
    }
}

pub fn run() {
    let shortcut = Shortcut::new(Some(Modifiers::SUPER | Modifiers::SHIFT), Code::KeyV);

    tauri::Builder::default()
        .plugin(tauri_plugin_clipboard_manager::init())
        .plugin(tauri_plugin_store::Builder::new().build())
        .plugin(
            tauri_plugin_global_shortcut::Builder::new()
                .with_handler(move |app, sc, event| {
                    if sc == &shortcut && event.state() == ShortcutState::Pressed {
                        toggle_popup(app);
                    }
                })
                .build(),
        )
        .setup(move |app| {
            use tauri_plugin_global_shortcut::GlobalShortcutExt;
            app.global_shortcut().register(shortcut)?;

            let show = MenuItem::with_id(app, "show", "Show history", true, None::<&str>)?;
            let clear = MenuItem::with_id(app, "clear", "Clear history", true, None::<&str>)?;
            let quit = MenuItem::with_id(app, "quit", "Quit", true, None::<&str>)?;
            let menu = Menu::with_items(app, &[&show, &clear, &quit])?;

            TrayIconBuilder::new()
                .icon(app.default_window_icon().unwrap().clone())
                .menu(&menu)
                .on_menu_event(|app, event| match event.id.as_ref() {
                    "show" => toggle_popup(app),
                    "clear" => { use tauri::Emitter; let _ = app.emit("history://clear", ()); }
                    "quit" => app.exit(0),
                    _ => {}
                })
                .build(app)?;
            Ok(())
        })
        .on_window_event(|window, event| {
            // hide instead of closing, and hide when focus is lost
            match event {
                tauri::WindowEvent::CloseRequested { api, .. } => { api.prevent_close(); let _ = window.hide(); }
                tauri::WindowEvent::Focused(false) => { let _ = window.hide(); }
                _ => {}
            }
        })
        .run(tauri::generate_context!())
        .expect("error while running");
}

(Modifiers::SUPER is the Cmd key on macOS and the Windows key elsewhere; use Modifiers::CONTROL for Ctrl.)

Polling the clipboard

The plugin has no "clipboard changed" event on every platform, so the frontend (or a Rust thread) polls: read the text every half second and add it when it differs from the last value.

TypeScript
import { readText } from '@tauri-apps/plugin-clipboard-manager';

let last = '';
setInterval(async () => {
  try {
    const text = (await readText()) ?? '';
    if (text && text !== last) {
      last = text;
      history.add(text);
    }
  } catch {
    // clipboard holds an image or is locked: ignore
  }
}, 500);

Polling is cheap for tiny text. A Rust thread with a native listener crate (for example clipboard-rs) can use real change notifications for lower power use.

The history logic you can run

The model below holds the rules: ignore empty and sensitive text, deduplicate by moving a repeated item to the top, cap the size while protecting pinned items, search, and pause.

Node.js Core model: history with dedupe, pinning, search, privacy

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.

The sensitive-content test is only a heuristic. Be honest about its limits in your app's description: it reduces risk, it does not eliminate it.

Persisting safely

By default, keep history in memory so nothing sensitive reaches the disk. If you offer "remember across restarts", save only pinned items, using the store plugin (Store, SQL and Settings), cap the age, and say so in the settings. Never save to cloud services without an explicit, opt-in sync feature and encryption.

Node.js Core model: expire old items

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.

Polish and extensions

  • Arrow keys and Enter to choose, number keys 1 to 9 for quick paste.
  • Image and file clipboard formats (the plugin supports images).
  • Autostart at login as an opt-in setting.
  • Per-app exclusion list: do not record while certain apps are focused.
  • A window-state-free design: always center the popup on the active display.
  • Package with signing (bundling) and keep it updated (updater).

Check your understanding

Quick check ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

  1. 1. Why is privacy the main design concern of a clipboard manager?

    Anything you record can leak secrets, so the app should filter, limit, expire and never upload history.
  2. 2. When the user copies text that already exists in history, what does the model do?

    Deduplication keeps one entry per text and refreshes its position.
  3. 3. How do you keep the popup window from appearing in the taskbar and from quitting the app when closed?

    A tray app keeps running; the window hides rather than closes.
  4. 4. Why register the global shortcut in Rust's setup()?

    The shortcut must exist while the window is hidden, so it is registered at startup.

Summary

  • A tray app keeps running with a hidden, always-on-top popup toggled by a global shortcut.
  • Poll the clipboard plugin for text, ignore empty and sensitive content, dedupe, cap and expire items, protect pinned ones.
  • Prefer in-memory history; persist only what the user chooses, and offer pause and clear.
  • Hide windows on close and on blur; quit only from the tray menu.

Next: Practice and Best Practices