All tests run on an 8-year-old MacBook Air.
All results from shipping 7 Mac apps as a solo developer. No sponsored opinion.
Menubar apps look simple from the outside. A tray icon, a popover, done.
The actual implementation has enough edge cases that I wish someone had written this before I started.
The basic setup
Tauri v2 has first-class tray icon support. The fundamentals:
rust
use tauri::{
tray::{TrayIconBuilder, TrayIconEvent},
Manager,
};
TrayIconBuilder::new()
.icon(app.default_window_icon().unwrap().clone())
.on_tray_icon_event(|tray, event| {
if let TrayIconEvent::Click { .. } = event {
// toggle window
}
})
.build(app)?;
Hide from Dock and App Switcher
A menubar app shouldn't appear in the Dock or Cmd+Tab switcher. Set this in Info.plist:
xml
LSUIElement
Or in tauri.conf.json:
json
{
"bundle": {
"macOS": {
"infoPlist": {
"LSUIElement": true
}
}
}
}
Without this, users will be confused why a menubar app appears in the Dock.…