Added the "reset()" method to the Reporting protocol in the Recording feature target to discard leftover Live Activities at launch and set a stale date on recording activities.
This commit is contained in:
@@ -49,7 +49,7 @@ final class ActivityReporting: Reporting {
|
||||
anchor: anchor,
|
||||
elapsed: .zero
|
||||
),
|
||||
staleDate: nil
|
||||
staleDate: Date.now.addingTimeInterval(Constant.Time.stale)
|
||||
)
|
||||
)
|
||||
#endif
|
||||
@@ -112,6 +112,19 @@ final class ActivityReporting: Reporting {
|
||||
#endif
|
||||
}
|
||||
|
||||
/// Ends every recording Live Activity still around — including one left over from an earlier run of the app the system killed before
|
||||
/// it could end its own — dismissing them right away, so an abandoned activity never outlives the process that started it. Meant to
|
||||
/// run once at launch, before any recording starts, since a fresh launch has no recording an activity could still belong to.
|
||||
func reset() async {
|
||||
#if os(iOS)
|
||||
for activity in Activity<RecordingActivityAttributes>.activities {
|
||||
await activity.end(nil, dismissalPolicy: .immediate)
|
||||
}
|
||||
|
||||
activity = nil
|
||||
#endif
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#if os(iOS)
|
||||
@@ -137,10 +150,23 @@ private extension ActivityReporting {
|
||||
anchor: anchor,
|
||||
elapsed: elapsed
|
||||
),
|
||||
staleDate: nil
|
||||
staleDate: Date.now.addingTimeInterval(Constant.Time.stale)
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// MARK: - Constants
|
||||
|
||||
/// The constant values used across the reporting service.
|
||||
private enum Constant {
|
||||
/// The time constants.
|
||||
enum Time {
|
||||
/// The span past which the system marks the recording Live Activity stale once the app stops updating it — because it was
|
||||
/// killed, for example — so an abandoned activity stops looking live instead of lingering for the activity's full lifetime.
|
||||
/// Generous enough to outlast a recording of any realistic length.
|
||||
static let stale: TimeInterval = 60 * 60
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user