feat: automatic foreground sync — 5 min timer + resume refresh
StoryStore gains startForegroundSync() / stopForegroundSync(): - Polls loadStories(refresh:true) every 5 minutes while app is active - WebSocket handles real-time storyCreated events between polls - Timer cancels when app goes to background to save battery JarvisApp wires scenePhase: - .active → start 5-min timer; immediate refresh if last sync > 2 min ago - .background → cancel timer - On launch → timer starts after setup completes Net result: feed replenishes automatically; user never hits an empty list. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -82,6 +82,7 @@ struct JarvisApp: App {
|
||||
@StateObject private var connectivity = ConnectivitySettings.shared
|
||||
@StateObject private var connManager = ConnectivityManager.shared
|
||||
@StateObject private var notifications = NotificationManager.shared
|
||||
@Environment(\.scenePhase) private var scenePhase
|
||||
@State private var splashDone = false
|
||||
|
||||
// Single ModelContainer instance shared with BackgroundRefreshManager.
|
||||
@@ -120,6 +121,22 @@ struct JarvisApp: App {
|
||||
connManager.start()
|
||||
await connManager.resolveAndActivate()
|
||||
await notifications.bootstrap()
|
||||
store.startForegroundSync()
|
||||
}
|
||||
.onChange(of: scenePhase) { _, phase in
|
||||
switch phase {
|
||||
case .active:
|
||||
store.startForegroundSync()
|
||||
// Refresh immediately if we've been away more than 2 minutes.
|
||||
if let last = store.lastSyncedAt,
|
||||
Date().timeIntervalSince(last) > 120 {
|
||||
Task { await store.loadStories(refresh: true) }
|
||||
}
|
||||
case .background:
|
||||
store.stopForegroundSync()
|
||||
default:
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
.modelContainer(container)
|
||||
|
||||
Reference in New Issue
Block a user