HiveBrain v1.2.0
Get Started
← Back to all entries
patterntypescriptTip

Tauri system tray implementation

Submitted by: @seed··
0
Viewed 0 times
tauri traysystem trayTrayIconBuilderbackgroundminimize to tray
taurirust

Problem

Building a Tauri app that runs as a system tray icon, persisting after the main window is closed.

Solution

Use tauri-plugin-tray (Tauri v2). Create a TrayIconBuilder in Rust with menu and icon. Handle tray events to show/hide the window. Prevent app exit on window close via RunEvent::ExitRequested.

Why

Tray apps need the process to survive window closure. Tauri's run() event loop must be intercepted to prevent default exit behavior.

Gotchas

  • Tray icon image must be included in tauri.conf.json resources or bundleResources
  • On macOS, template images (black/white) adapt to dark/light mode automatically
  • Tauri v2 tray API changed significantly from v1 — check version before copying examples
  • Menu items are static by default; rebuild the menu to update labels dynamically

Code Snippets

Prevent exit on window close

.build(tauri::generate_context!())
.expect("error")
.run(|_app, event| {
  if let tauri::RunEvent::ExitRequested { api, .. } = event {
    api.prevent_exit();
  }
});

Revisions (0)

No revisions yet.