diff --git a/mac/Sources/CodeBurnMenubar/AppStore.swift b/mac/Sources/CodeBurnMenubar/AppStore.swift index db3e2da..572146a 100644 --- a/mac/Sources/CodeBurnMenubar/AppStore.swift +++ b/mac/Sources/CodeBurnMenubar/AppStore.swift @@ -1,7 +1,7 @@ import Foundation import Observation -private let cacheTTLSeconds: TimeInterval = 300 +private let cacheTTLSeconds: TimeInterval = 30 struct CachedPayload { let payload: MenubarPayload @@ -52,17 +52,15 @@ final class AppStore { payload.optimize.findingCount } - /// Switch to a period. Uses cached payload if fresh; otherwise fetches. + /// Switch to a period. Always fetches fresh data so the user never sees stale numbers. func switchTo(period: Period) async { selectedPeriod = period - if let cached = cache[currentKey], cached.isFresh { return } await refresh(includeOptimize: true) } - /// Switch to a provider filter. Uses cached payload if fresh; otherwise fetches. + /// Switch to a provider filter. Always fetches fresh data so the user never sees stale numbers. func switchTo(provider: ProviderFilter) async { selectedProvider = provider - if let cached = cache[currentKey], cached.isFresh { return } await refresh(includeOptimize: true) } diff --git a/mac/Sources/CodeBurnMenubar/CodeBurnApp.swift b/mac/Sources/CodeBurnMenubar/CodeBurnApp.swift index a97c76c..095b4df 100644 --- a/mac/Sources/CodeBurnMenubar/CodeBurnApp.swift +++ b/mac/Sources/CodeBurnMenubar/CodeBurnApp.swift @@ -2,7 +2,7 @@ import SwiftUI import AppKit import Observation -private let refreshIntervalSeconds: UInt64 = 60 +private let refreshIntervalSeconds: UInt64 = 15 private let nanosPerSecond: UInt64 = 1_000_000_000 private let refreshIntervalNanos: UInt64 = refreshIntervalSeconds * nanosPerSecond /// Fixed so the popover's anchor point doesn't shift each time today's cost changes. diff --git a/src/cli.ts b/src/cli.ts index f2f3c22..0164f42 100644 --- a/src/cli.ts +++ b/src/cli.ts @@ -247,7 +247,7 @@ program .option('--format ', 'Output format: tui, json', 'tui') .option('--project ', 'Show only projects matching name (repeatable)', collect, []) .option('--exclude ', 'Exclude projects matching name (repeatable)', collect, []) - .option('--refresh ', 'Auto-refresh interval in seconds', parseInt) + .option('--refresh ', 'Auto-refresh interval in seconds (0 to disable)', parseInt, 30) .action(async (opts) => { let customRange: DateRange | null = null try { @@ -502,7 +502,7 @@ program .option('--format ', 'Output format: tui, json', 'tui') .option('--project ', 'Show only projects matching name (repeatable)', collect, []) .option('--exclude ', 'Exclude projects matching name (repeatable)', collect, []) - .option('--refresh ', 'Auto-refresh interval in seconds', parseInt) + .option('--refresh ', 'Auto-refresh interval in seconds (0 to disable)', parseInt, 30) .action(async (opts) => { if (opts.format === 'json') { await runJsonReport('today', opts.provider, opts.project, opts.exclude) @@ -518,7 +518,7 @@ program .option('--format ', 'Output format: tui, json', 'tui') .option('--project ', 'Show only projects matching name (repeatable)', collect, []) .option('--exclude ', 'Exclude projects matching name (repeatable)', collect, []) - .option('--refresh ', 'Auto-refresh interval in seconds', parseInt) + .option('--refresh ', 'Auto-refresh interval in seconds (0 to disable)', parseInt, 30) .action(async (opts) => { if (opts.format === 'json') { await runJsonReport('month', opts.provider, opts.project, opts.exclude)