Skip to content
Merged
Show file tree
Hide file tree
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
5 changes: 5 additions & 0 deletions app/Sources/CovenPocketApp.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ struct CovenPocketAppDependencies {

@main
struct CovenPocketApp: App {
@Environment(\.scenePhase) private var scenePhase
@StateObject private var router = AppRouter.shared
@StateObject private var rootWindowState: RootWindowState
let rootWindowFactory: RootWindowFactory
Expand Down Expand Up @@ -44,6 +45,10 @@ struct CovenPocketApp: App {
else { return }
router.openSession(id: sessionID)
}
.onChange(of: scenePhase) { _, phase in
guard phase == .background else { return }
Task { await rootWindowState.chatState.model.pauseGoalForBackground() }
}
}
.commands {
CommandGroup(replacing: .newItem) {
Expand Down
8 changes: 8 additions & 0 deletions app/Sources/Support/ChatModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -344,6 +344,14 @@ final class ChatModel: ObservableObject {
} catch { appendError(error.localizedDescription) }
}

/// Goals are intentionally finite foreground work. Persisting the pause
/// before iOS suspends the process makes a later resume explicit and
/// prevents an interrupted loop from being treated as still active.
func pauseGoalForBackground() async {
guard goal?.status == .active else { return }
await pauseGoal()
}

func clearGoal() async {
guard let session else { return }
do {
Expand Down
Loading