diff --git a/internal/tray/tray.go b/internal/tray/tray.go index a456140..b3f674f 100644 --- a/internal/tray/tray.go +++ b/internal/tray/tray.go @@ -13,10 +13,11 @@ type Callbacks struct { OnQuit func() // called when user clicks Quit } -// Run starts the systray on the main thread. It blocks until quit. -// Must be called from the main goroutine on macOS. -func Run(cb Callbacks) { - systray.Run(func() { +// Register sets up the systray without starting its own event loop. +// This must be used when another framework (like Wails) already owns +// the main thread and NSApplication run loop on macOS. +func Register(cb Callbacks) { + systray.Register(func() { systray.SetTemplateIcon(iconData, iconData) systray.SetTitle("") systray.SetTooltip("Egressor — egress monitor") diff --git a/internal/tray/tray_stub.go b/internal/tray/tray_stub.go index 5cc111e..35d4532 100644 --- a/internal/tray/tray_stub.go +++ b/internal/tray/tray_stub.go @@ -9,8 +9,8 @@ type Callbacks struct { OnQuit func() } -// Run is a no-op on unsupported platforms. -func Run(_ Callbacks) {} +// Register is a no-op on unsupported platforms. +func Register(_ Callbacks) {} // Available returns false when the systray is not compiled in. func Available() bool { diff --git a/internal/ui/app.go b/internal/ui/app.go index 7004484..90694cf 100644 --- a/internal/ui/app.go +++ b/internal/ui/app.go @@ -53,9 +53,11 @@ func (a *App) Startup(ctx context.Context) { slog.Error("failed to start proxy", "err", err) } - // Start system tray icon (macOS menu bar) + // Set up system tray icon (macOS menu bar). + // Uses Register instead of Run to avoid starting a second NSApplication + // run loop — Wails already owns the main thread. if tray.Available() { - go tray.Run(tray.Callbacks{ + tray.Register(tray.Callbacks{ OnPauseToggle: func(paused bool) { a.engine.SetBypassed(paused) if paused { diff --git a/internal/ui/frontend/src/App.tsx b/internal/ui/frontend/src/App.tsx index 414bf17..e5ca140 100644 --- a/internal/ui/frontend/src/App.tsx +++ b/internal/ui/frontend/src/App.tsx @@ -75,7 +75,7 @@ function App() { )} ) : ( -
+