fix(menubar): stop rendering the closed popover around the clock

The status-item popover's hosting view is created once and lives for the
app's lifetime, and the flame wordmark inside it ran a repeat-forever
shimmer, so SwiftUI re-rendered the closed popover at display cadence
continuously: 5 to 7 percent idle CPU and roughly 650 wakeups a second
(Activity Monitor showed a 12-hour energy figure near two thirds of
Chrome's). The wordmark sweep and the loading flame pulse now start and
stop with popover visibility via a store flag set by the popover
delegate.
This commit is contained in:
iamtoruk 2026-08-31 10:46:37 -07:00
parent f54329e686
commit c19d5621e3
4 changed files with 38 additions and 8 deletions

View file

@ -49,6 +49,10 @@ final class AppStore {
var selectedScope: MenubarScope = MenubarScope.savedMenubarScope()
var selectedClaudeConfigSourceId: String?
var selectedDays: Set<String> = []
/// True while the status-item popover is on screen. The popover's hosting
/// view is created once and lives forever, so repeat-forever animations
/// must gate on this or they render at display cadence around the clock.
var menuPopoverVisible = false
var activeScope: MenubarScope { effectiveSelectedScope }
private var effectiveSelectedScope: MenubarScope {

View file

@ -1427,6 +1427,7 @@ final class AppDelegate: NSObject, NSApplicationDelegate, NSPopoverDelegate, NSM
// closes. The popover's window takes keyboard focus on its own
// via makeKeyAndOrderFront, which is enough for keystrokes to
// reach the SwiftUI content.
store.menuPopoverVisible = true
popover.show(relativeTo: button.bounds, of: button, preferredEdge: .minY)
if let window = popover.contentViewController?.view.window {
// Pin the popover's window above the status-bar layer but tag
@ -1640,6 +1641,7 @@ final class AppDelegate: NSObject, NSApplicationDelegate, NSPopoverDelegate, NSM
}
func popoverDidClose(_ notification: Notification) {
store.menuPopoverVisible = false
// Catch up on any menubar title updates that were skipped while the
// popover was anchored.
refreshStatusButton()

View file

@ -3,6 +3,7 @@ import SwiftUI
/// The "CodeBurn" wordmark filled with the website's animated flame gradient.
struct FlameWordmark: View {
@Environment(\.accessibilityReduceMotion) private var reduceMotion
@Environment(AppStore.self) private var store
@State private var sweeping = false
// CSS parity: the site's `.flame-text` uses background-size: 300% with
@ -38,13 +39,21 @@ struct FlameWordmark: View {
.frame(width: geo.size.width * 3, height: geo.size.height)
.offset(x: sweeping ? -geo.size.width * 2 : 0)
.animation(
reduceMotion ? nil : .easeInOut(duration: 1.5).repeatForever(autoreverses: true),
reduceMotion || !store.menuPopoverVisible
? nil
: .easeInOut(duration: 1.5).repeatForever(autoreverses: true),
value: sweeping
)
}
.mask(wordmark)
}
.onAppear { sweeping = true }
.onAppear { sweeping = store.menuPopoverVisible }
// The hosting view outlives every popover appearance, so the sweep
// starts and stops with visibility instead of running forever in a
// closed popover (5 to 7 percent idle CPU before this gate).
.onChange(of: store.menuPopoverVisible) { _, visible in
sweeping = visible
}
.accessibilityElement(children: .ignore)
.accessibilityLabel("CodeBurn")
}

View file

@ -302,6 +302,7 @@ private struct FetchErrorOverlay: View {
/// yellow→orange→red, looping.
private struct BurnLoadingOverlay: View {
let periodLabel: String
@Environment(AppStore.self) private var store
@State private var fillProgress: CGFloat = 0
@State private var glowing: Bool = false
@ -320,13 +321,27 @@ private struct BurnLoadingOverlay: View {
.foregroundStyle(.secondary)
}
}
.onAppear {
withAnimation(.easeInOut(duration: 1.4).repeatForever(autoreverses: true)) {
fillProgress = 1.0
}
withAnimation(.easeInOut(duration: 0.9).repeatForever(autoreverses: true)) {
glowing = true
.onAppear { setPulsing(store.menuPopoverVisible) }
.onChange(of: store.menuPopoverVisible) { _, visible in
setPulsing(visible)
}
}
private func setPulsing(_ on: Bool) {
guard on else {
var stop = Transaction()
stop.disablesAnimations = true
withTransaction(stop) {
fillProgress = 0
glowing = false
}
return
}
withAnimation(.easeInOut(duration: 1.4).repeatForever(autoreverses: true)) {
fillProgress = 1.0
}
withAnimation(.easeInOut(duration: 0.9).repeatForever(autoreverses: true)) {
glowing = true
}
}
}