惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

云风的 BLOG
云风的 BLOG
M
MIT News - Artificial intelligence
博客园 - Franky
J
Java Code Geeks
V
Visual Studio Blog
G
Google Developers Blog
罗磊的独立博客
MongoDB | Blog
MongoDB | Blog
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
Recent Announcements
Recent Announcements
Last Week in AI
Last Week in AI
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
Stack Overflow Blog
Stack Overflow Blog
博客园 - 司徒正美
The GitHub Blog
The GitHub Blog
腾讯CDC
阮一峰的网络日志
阮一峰的网络日志
V
V2EX
博客园 - 【当耐特】
IT之家
IT之家
I
InfoQ
U
Unit 42
C
Check Point Blog
Martin Fowler
Martin Fowler

DEV Community

Authentication Security Deep Dive: From Brute Force to Salted Hashing (With Java Examples) Why AI Systems Don’t Fail — They Drift Spilling beans for how i learn for exam😁"Reinforcement Learning Cheat Sheet" I Replaced Chrome with Safari for AI Browser Automation. Here's What Broke (and What Finally Worked) How Python Borrows Other People's Work The $40 Architecture: Processing 1 Billion API Requests with 99.99% Uptime Vibe Coding: A Workflow Guide (From Zero to SaaS) Most webhook security guides protect the wrong side. The scary part is delivery. Headless CMS for TanStack Start: Build a Blog with Cosmic EU Age Verification App "Hacked in 2 Minutes" — What Actually Happened Comfy Cloud’s delete function does not actually remove files Running AI Models on GPU Cloud Servers: A Beginner Guide Event-driven media intelligence with AWS Step Functions and Bedrock I scored 500 AI prompts across 8 quality dimensions — here's what broke How to Call Google Gemini API from Next.js (Free Tier, No Backend Needed) The Portal Protocol: Reclaiming Human Connection in the Age of AI How to Fix Your Team's Scattered Knowledge Problem With a Self-Hosted Forum Intro to tc Cloud Functors: A Graph-First Mental Model for the Modern Cloud Designing Multi-Tenant Backends With Both Ownership and Team Access I Built a Neumorphic CSS Library with 77+ Components — Here's What I Learned PostgreSQL Performance Optimization: Why Connection Pooling Is Critical at Scale Cómo construí un SaaS multi-rubro para gestionar expensas en Argentina con FastAPI + Vue 3 🚀 I Built an Ethical Hacking Scanner Tool – Open Source Project I Replaced /usage and /context in Claude Code With a Single Statusline A Pythonic Way to Handle Emails (IMAP/SMTP) with Auto-Discovery and AI-Ready Design I Collected 8.9 Million Polymarket Price Points — Here's What I Found About How Markets Really Move EcoTrack AI — Carbon Footprint Tracker & Dashboard Everyone's Using AI. No One Agrees How. 5 self-hosted ebook managers worth trying in 2026 Building Your First AI Agent with LangChain: From Chatbot to Autonomous Assistant
Building a Menubar App with Tauri v2 — What Nobody Tells You
hiyoyo · 2026-05-14 · via DEV Community

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. This is the first thing to set.

Window positioning
The window should appear below the tray icon, not in the center of the screen. Tauri doesn't handle this automatically.

Get the tray icon position and calculate:

rust
fn position_window_near_tray(window: &WebviewWindow, tray_rect: &tauri::PhysicalRect) {
let window_size = window.outer_size().unwrap();
let x = tray_rect.position.x + (tray_rect.size.width as i32 / 2)
- (window_size.width as i32 / 2);
let y = tray_rect.position.y + tray_rect.size.height as i32;
window.set_position(tauri::PhysicalPosition::new(x, y)).ok();
}
Account for screen edges. A window that opens half off-screen on a secondary monitor is a real edge case worth handling.

Show/hide vs create/destroy
Two approaches: keep the window hidden and show/hide it, or create and destroy it on each toggle.

Show/hide is simpler and faster. The window stays in memory. State persists between opens.

Create/destroy resets state on each open. Good for apps where you want a fresh start each time. Slower on older hardware.

I use show/hide for all my menubar apps. The state persistence is a feature, not a bug.

rust
if window.is_visible().unwrap_or(false) {
window.hide().ok();
} else {
window.show().ok();
window.set_focus().ok();
}
Auto-hide when focus is lost
Click elsewhere, window disappears. Users expect this from menubar apps.

rust
window.on_window_event(|event| {
if let WindowEvent::Focused(false) = event {
window.hide().ok();
}
});
One edge case: if your window opens a dialog or file picker, the focus loss will close the main window before the dialog appears. Add a flag to suppress auto-hide when a child window is open.

The verdict
Menubar apps in Tauri v2 are well-supported. The gaps are window positioning, auto-hide behavior, and the LSUIElement setting. All solvable — just not documented in one place until now.

If this was useful, a ❤️ helps more than you'd think — thanks!

Hiyoko PDF Vault → https://hiyokoko.gumroad.com/l/HiyokoPDFVault
X → @hiyoyok