diff --git a/mac/Sources/CodeBurnMenubar/AppStore.swift b/mac/Sources/CodeBurnMenubar/AppStore.swift index f5ba73ef..fd9bd63d 100644 --- a/mac/Sources/CodeBurnMenubar/AppStore.swift +++ b/mac/Sources/CodeBurnMenubar/AppStore.swift @@ -49,6 +49,10 @@ final class AppStore { var selectedScope: MenubarScope = MenubarScope.savedMenubarScope() var selectedClaudeConfigSourceId: String? var selectedDays: Set = [] + /// 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 { diff --git a/mac/Sources/CodeBurnMenubar/CodeBurnApp.swift b/mac/Sources/CodeBurnMenubar/CodeBurnApp.swift index f178f7b7..581f106e 100644 --- a/mac/Sources/CodeBurnMenubar/CodeBurnApp.swift +++ b/mac/Sources/CodeBurnMenubar/CodeBurnApp.swift @@ -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() diff --git a/mac/Sources/CodeBurnMenubar/Views/FlameWordmark.swift b/mac/Sources/CodeBurnMenubar/Views/FlameWordmark.swift index 531697e0..a6eb5981 100644 --- a/mac/Sources/CodeBurnMenubar/Views/FlameWordmark.swift +++ b/mac/Sources/CodeBurnMenubar/Views/FlameWordmark.swift @@ -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") } diff --git a/mac/Sources/CodeBurnMenubar/Views/MenuBarContent.swift b/mac/Sources/CodeBurnMenubar/Views/MenuBarContent.swift index 218384d5..a9461be1 100644 --- a/mac/Sources/CodeBurnMenubar/Views/MenuBarContent.swift +++ b/mac/Sources/CodeBurnMenubar/Views/MenuBarContent.swift @@ -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 } } }