r/SwiftUI • u/nicecahce • 1h ago
Promotion (must include link to source code) a TimelineView in a MenuBarExtra label never stops redrawing, and other things i learned building a menu bar app in swiftui (open source)
Enable HLS to view with audio, or disable this notification
source first: https://github.com/lucasnsaraujo/ebb (mit)
i built ebb, a mac menu bar app that shows how much is left of a pool of claude code and codex accounts behind cliproxyapi. the whole ui is swiftui with a bit of appkit where swiftui runs out, and a few things bit me along the way
TimelineView inside a MenuBarExtra label is a trap. the label redraws the moment you ask it to, so a periodic timeline there just keeps spinning. in the label i use a .task(id:) loop that sleeps 60s and bumps a now state instead, and it stops when the item is hidden. inside the panel TimelineView is fine, i use it for the freshness line and the "locked until" note
the menu bar item is one NSImage, not a swiftui label. that way the mark, a 3pt gap and the text land exactly where i want. plain states are template images so the menu bar tints them like its own items. the low/empty states are tinted so they can't be templates, there the drawing handler resolves colors against the appearance it's drawing in, and it redraws when increase contrast changes
MenuBarExtra has no api to open its panel. for the shortcuts/siri action that opens it i ended up finding the status item's button and pressing it, and keeping a flag so a second press doesn't close the panel
numbers use .contentTransition(.numericText(value:)) so the percentages roll, and fall back to .identity with reduce motion on
i built it with claude code, happy to answer anything about the swiftui side

