Fix menubar crashes and add reliable auto-refresh

Fixes crash when switching timeframes or providers by handling
duplicate dates in history data gracefully.

Adds LaunchAgent that posts a distributed notification every 15
seconds to keep prices fresh even after long idle periods.
This commit is contained in:
AgentSeal 2026-04-23 21:09:46 +02:00
parent 17b7e6ae6c
commit 68daad5dfa
3 changed files with 67 additions and 3 deletions

View file

@ -399,7 +399,7 @@ private func buildTrendBars(from days: [DailyHistoryEntry]) -> [TrendBar] {
f.timeZone = .current
return f
}()
let entryByDate = Dictionary(uniqueKeysWithValues: days.map { ($0.date, $0) })
let entryByDate = Dictionary(days.map { ($0.date, $0) }, uniquingKeysWith: { _, new in new })
let today = calendar.startOfDay(for: Date())
let todayKey = formatter.string(from: today)
@ -837,7 +837,7 @@ private func computeAllStats(payload: MenubarPayload) -> AllStats {
peakDaySpend = ""
}
let costByDate = Dictionary(uniqueKeysWithValues: history.map { ($0.date, $0.cost) })
let costByDate = Dictionary(history.map { ($0.date, $0.cost) }, uniquingKeysWith: +)
var currentStreak = 0
for offset in 0..<400 {