Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions SleepFocus/SleepFocusApp.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ struct SleepFocusApp: App {
@StateObject private var insightsStore = InsightsStore()
private let healthAutoSyncService = HealthAutoSyncService.shared

// Observe scene phase to detect app foregrounding.
@Environment(\.scenePhase) private var scenePhase

var body: some Scene {
WindowGroup {
Group {
Expand Down Expand Up @@ -52,6 +55,24 @@ struct SleepFocusApp: App {
guard authManager.isAuthenticated else { return }
await healthAutoSyncService.startIfNeeded(authManager: authManager)
}
// When the app returns to foreground, force-refresh smart alarm guidance
// so the backend model result is used instead of the fallback.
.onChange(of: scenePhase) { _, newPhase in
guard newPhase == .active, authManager.isAuthenticated else { return }
Task {
guard !sleepPreferences.isRefreshingSmartAlarmGuidance else { return }

await sleepPreferences.refreshSmartAlarmCycleGuidance(
using: authManager,
force: true
)
Comment thread
austinkimchi marked this conversation as resolved.

guard !sleepPreferences.isRefreshingSmartAlarmGuidance else { return }
await sleepPreferences.syncSmartAlarmRuntime(
notificationSettings: notificationSettings
)
}
}
.onOpenURL { url in
navigationManager.handleDeepLink(url)
}
Expand Down
Loading