Implemented the sync between feature and live activity timers for the ActivityReporting service in the Sample app target.
This commit is contained in:
@@ -46,7 +46,7 @@ final class ActivityReporting: Reporting {
|
|||||||
content: .init(
|
content: .init(
|
||||||
state: .init(
|
state: .init(
|
||||||
state: .recording,
|
state: .recording,
|
||||||
anchor: anchor,
|
anchor: anchor.addingTimeInterval(Constant.Time.flooring),
|
||||||
elapsed: .zero
|
elapsed: .zero
|
||||||
),
|
),
|
||||||
staleDate: Date.now.addingTimeInterval(Constant.Time.stale)
|
staleDate: Date.now.addingTimeInterval(Constant.Time.stale)
|
||||||
@@ -65,7 +65,7 @@ final class ActivityReporting: Reporting {
|
|||||||
await update(
|
await update(
|
||||||
state: .paused,
|
state: .paused,
|
||||||
anchor: nil,
|
anchor: nil,
|
||||||
elapsed: elapsed
|
elapsed: elapsed.rounded(.down)
|
||||||
)
|
)
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
@@ -79,7 +79,7 @@ final class ActivityReporting: Reporting {
|
|||||||
#if os(iOS)
|
#if os(iOS)
|
||||||
await update(
|
await update(
|
||||||
state: .recording,
|
state: .recording,
|
||||||
anchor: anchor,
|
anchor: anchor.addingTimeInterval(Constant.Time.flooring),
|
||||||
elapsed: .zero
|
elapsed: .zero
|
||||||
)
|
)
|
||||||
#endif
|
#endif
|
||||||
@@ -95,7 +95,7 @@ final class ActivityReporting: Reporting {
|
|||||||
await update(
|
await update(
|
||||||
state: .processing,
|
state: .processing,
|
||||||
anchor: nil,
|
anchor: nil,
|
||||||
elapsed: elapsed
|
elapsed: elapsed.rounded(.down)
|
||||||
)
|
)
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
@@ -163,6 +163,12 @@ private extension ActivityReporting {
|
|||||||
private enum Constant {
|
private enum Constant {
|
||||||
/// The time constants.
|
/// The time constants.
|
||||||
enum Time {
|
enum Time {
|
||||||
|
/// The half second added to a running timer's anchor. The system counts the Live Activity's timer up from the anchor and
|
||||||
|
/// formats it with round-to-nearest, whereas the feature's own timer floors the elapsed seconds; moving the anchor half a
|
||||||
|
/// second into the future turns that rounding back into flooring, so both timers show the same whole second instead of the
|
||||||
|
/// Live Activity ticking one second ahead for the back half of each second.
|
||||||
|
static let flooring: TimeInterval = 0.5
|
||||||
|
|
||||||
/// The span past which the system marks the recording Live Activity stale once the app stops updating it — because it was
|
/// 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.
|
/// 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.
|
/// Generous enough to outlast a recording of any realistic length.
|
||||||
|
|||||||
Reference in New Issue
Block a user