iOS Live Activity Updates
Nucleic-Session: 665980BA-E8A5-4E84-9DF4-1757CF792353 Co-authored-by: Nucleic <[email protected]>
This commit is contained in:
@@ -143,15 +143,33 @@ final class LiveActivityManager {
|
|||||||
tokenObservation = nil
|
tokenObservation = nil
|
||||||
pendingState = nil
|
pendingState = nil
|
||||||
lastState = nil
|
lastState = nil
|
||||||
guard let activity else { return }
|
let tracked = activity
|
||||||
self.activity = nil
|
self.activity = nil
|
||||||
onActivityEnded?(activity.id) // let the Macs stop pushing to this token
|
if let tracked { onActivityEnded?(tracked.id) } // let the Macs stop pushing to this token
|
||||||
|
// Dismiss the tracked Activity *and any strays*: ending only the one we track would leave an
|
||||||
|
// orphan (from a prior launch killed before `end()`) rendering a stale "needs attention"
|
||||||
|
// glance in the Dynamic Island after the work it described has finished. Clear them all so
|
||||||
|
// "everything idle" can't get stuck on screen.
|
||||||
Task {
|
Task {
|
||||||
|
for activity in Activity<NucleicSessionAttributes>.activities {
|
||||||
await activity.end(
|
await activity.end(
|
||||||
ActivityContent(state: activity.content.state, staleDate: nil),
|
ActivityContent(state: activity.content.state, staleDate: nil),
|
||||||
dismissalPolicy: .immediate)
|
dismissalPolicy: .immediate)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Dismiss every live Activity except `keep` — collapses accidental duplicates down to one so
|
||||||
|
/// iOS can't render a stale orphan alongside the tracked glance.
|
||||||
|
private func endStrays(keeping keep: String) {
|
||||||
|
for stray in Activity<NucleicSessionAttributes>.activities where stray.id != keep {
|
||||||
|
Task {
|
||||||
|
await stray.end(
|
||||||
|
ActivityContent(state: stray.content.state, staleDate: nil),
|
||||||
|
dismissalPolicy: .immediate)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// MARK: - Projection
|
// MARK: - Projection
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user