watch: polish refresh status and compact live activity

This commit is contained in:
FuelBoard Contributor
2026-08-31 10:40:16 +01:00
parent 767080a983
commit 8bbcb0b4dc
2 changed files with 27 additions and 9 deletions
+16 -3
View File
@@ -112,6 +112,7 @@ private enum WatchRefreshState {
case stale(lastUpdated: String)
case checking
case requested(lastUpdated: String)
case checkedNoNewData(lastUpdated: String)
case needsPhone
case noData
@@ -120,7 +121,8 @@ private enum WatchRefreshState {
case .idle(let lastUpdated): return "Updated \(lastUpdated)"
case .stale(let lastUpdated): return "Cache from \(lastUpdated)"
case .checking: return "Checking…"
case .requested(let lastUpdated): return "Requested · \(lastUpdated)"
case .requested(let lastUpdated): return "Updated · \(lastUpdated)"
case .checkedNoNewData(let lastUpdated): return "No newer data · \(lastUpdated)"
case .needsPhone: return "Refresh on iPhone"
case .noData: return "No cached prices yet"
}
@@ -132,6 +134,7 @@ private enum WatchRefreshState {
case .stale: return .yellow
case .checking: return .yellow
case .requested: return .green
case .checkedNoNewData: return .secondary
case .needsPhone: return .orange
case .noData: return .secondary
}
@@ -143,6 +146,7 @@ private enum WatchRefreshState {
case .stale: return "exclamationmark.circle"
case .checking: return "arrow.triangle.2.circlepath"
case .requested: return "checkmark.circle"
case .checkedNoNewData: return "clock.badge.exclamationmark"
case .needsPhone: return "iphone"
case .noData: return "tray"
}
@@ -551,6 +555,7 @@ struct ContentView: View {
private func runCheckNow() {
refreshState = .checking
let previousLastRefresh = WatchFuelCache.loadLastRefresh()
let requestDate = Date()
WatchFuelCache.requestRefresh(requestDate)
WatchSyncManager.shared.requestRefresh(at: requestDate)
@@ -560,8 +565,16 @@ struct ContentView: View {
if WatchFuelCache.wasRefreshHandled(since: requestDate) {
await MainActor.run {
reloadFromCache()
let label = WatchFuelCache.loadLastRefresh().map(relativeRefreshText(for:)) ?? "just now"
refreshState = .requested(lastUpdated: label)
let currentLastRefresh = WatchFuelCache.loadLastRefresh()
if let currentLastRefresh,
currentLastRefresh >= requestDate,
currentLastRefresh > (previousLastRefresh ?? .distantPast) {
refreshState = .requested(lastUpdated: relativeRefreshText(for: currentLastRefresh))
} else if let currentLastRefresh {
refreshState = .checkedNoNewData(lastUpdated: relativeRefreshText(for: currentLastRefresh))
} else {
refreshState = .noData
}
}
return
}