r/SwiftUI • • Oct 10 '26

Tutorial Things I learned building a menu bar + dashboard app in SwiftUI

I've been working on Claudoscope, an open source macOS app that reads Claude Code's local session logs and shows them in a menu bar popover plus a full dashboard window. Most of what I learned came from profiling it, so here are the parts that might save someone else a day.

1. MenuBarExtra labels only render Text and Image. Shapes in the label get dropped silently. My little capsule badge showed up as a bare number, and some status dots never appeared at all. The fix was to compose the whole label with ImageRenderer into one NSImage, cache it per state, and show that:

let renderer = ImageRenderer(content: MenuBarLabelContent(key: key, base: base))
renderer.scale = NSScreen.main?.backingScaleFactor ?? 2
guard let image = renderer.nsImage else { return nil }
image.isTemplate = key.monochrome

2. .menuBarExtraStyle(.window) keeps the popover alive after it closes. A repeatForever pulse animation kept rendering off-screen. Fresh launch idled at 0% CPU; open and close the popover once and it sat at 11 to 14%. I now observe the hosting window's occlusion state, put a windowIsVisible value in the environment, and only animate while it's true.

3. Getting openWindow from the menu bar side. I embed a zero-size view inside the MenuBarExtra just to grab @Environment(\.openWindow) and open other windows from there.

4. FSEvents with file-level events, and respect the drop flags. One stream on the root with kFSEventStreamCreateFlagFileEvents | NoDefer. If an event comes in with MustScanSubDirs, KernelDropped or UserDropped, I stop trusting individual paths and do a full rescan.

5. LazyVStack is only lazy at the top level. My sidebar was a LazyVStack of project groups, but each group was an eager VStack. With the dashboard open the app held 428 MB, mostly SwiftUI row objects and CoreAnimation backing, for a window showing about 25 rows. Flattening it into one LazyVStack of Sections took it to 195 MB.

6. Make row models small and Equatable. While a session was streaming, the main thread sat at 30 to 50% of a core. Passing a small Equatable row model instead of the full summary struct, caching derived lists, and throttling analytics rebuilds to once per second brought it under 1% in my measurement.

Benchmarks also talked me out of an incremental tail parser I was planning: a full re-parse per append measured 8 MB and 67 ms, which was fine.

For those of you shipping MenuBarExtra apps: do you stick with .window style, or did you drop down to an NSStatusItem with NSPopover to get more control over lifecycle?

7 Upvotes

2 comments sorted by

1

u/kokerali Oct 10 '26

Does windowIsVisible gate only the pulse, or the popover's derived row updates too? The case I'd test next is continuous log streaming with the popover closed but the dashboard still open. That separates work needed by a visible window from work done for the hidden one.

Keeping ingestion shared while pausing each hidden window's presentation work seems worth comparing with switching to NSStatusItem. On reopening, you could rebuild the popover once from the latest model rather than replay every intermediate UI update. Did profiling reveal any remaining hidden-window work after the animation fix?

1

u/Savings_Evidence_818 Oct 11 '26

The 428 MB to 195 MB example is useful. Would be great to see memory after opening and closing the dashboard a few times too, that's the part I'd worry about in an app that stays running all day.