Create and manage system tray icons with menus and click handlers in Tauri v2, handling platform differences. Use when adding a tray icon, building tray menus, toggling window visibility from the tray, or handling macOS/Windows/Linux tray conventions.
ALWAYS use this skill when the user mentions:
Trigger phrases include:
use tauri::{tray::TrayIconBuilder, menu::{Menu, MenuItem}};
tauri::Builder::default()
.setup(|app| {
let show = MenuItem::with_id(app, "show", "Show", true, None::<&str>)?;
let quit = MenuItem::with_id(app, "quit", "Quit", true, None::<&str>)?;
let menu = Menu::with_items(app, &[&show, &quit])?;
TrayIconBuilder::new()
.icon(app.default_window_icon().unwrap().clone())
.menu(&menu)
.on_menu_event(|app, event| match event.id.as_ref() {
"show" => { app.get_webview_window("main").unwrap().show().unwrap(); }
"quit" => { app.exit(0); }
_ => {}
})
.build(app)?;
Ok(())
})
src-tauri/capabilities/default.json:
{ "permissions": ["core:default", "tray:default"] }
tauri system tray, tray icon, tray menu, status bar, minimize to tray