|
|
|
|
@ -48,8 +48,8 @@ class CountdownScheduler { |
|
|
|
|
handler(.failure(error)) |
|
|
|
|
print("Scheduling error = \(error)") |
|
|
|
|
} else { |
|
|
|
|
if let date = trigger.nextTriggerDate() { |
|
|
|
|
AppEnvironment.sun.startCountdown(date, countdown: countdown) |
|
|
|
|
if let triggerDate = trigger.nextTriggerDate() { |
|
|
|
|
AppEnvironment.sun.startCountdown(triggerDate, countdown: countdown) |
|
|
|
|
handler(.success(trigger.nextTriggerDate())) |
|
|
|
|
} else { |
|
|
|
|
let backupDate = Date().addingTimeInterval(duration) |
|
|
|
|
@ -89,7 +89,7 @@ class AppEnvironment : ObservableObject { |
|
|
|
|
DispatchQueue.main.async { |
|
|
|
|
let dateInterval = DateInterval(start: Date(), end: date) |
|
|
|
|
self.notificationDates[countdown.stringId] = dateInterval |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
self._launchLiveActivity(countdown: countdown, endDate: date) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
@ -179,16 +179,22 @@ class AppEnvironment : ObservableObject { |
|
|
|
|
return ActivityKit.Activity<LaunchWidgetAttributes>.activities.first(where: { $0.attributes.id == countdownId } ) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// fileprivate func _updateLiveActivity(countdownId: String, endDate: Date) { |
|
|
|
|
// if let activity = self._liveActivity(countdownId: countdownId) { |
|
|
|
|
// Task { |
|
|
|
|
// let state = LaunchWidgetAttributes.ContentState(ended: true) |
|
|
|
|
// let content = ActivityContent(state: state, staleDate: endDate) |
|
|
|
|
// await activity.update(content) |
|
|
|
|
// print("Ending the Live Activity: \(activity.id)") |
|
|
|
|
// } |
|
|
|
|
// } |
|
|
|
|
// } |
|
|
|
|
func updateLiveActivities() { |
|
|
|
|
|
|
|
|
|
for (countdownId, interval) in self.notificationDates { |
|
|
|
|
if let activity = self._liveActivity(countdownId: countdownId) { |
|
|
|
|
|
|
|
|
|
Task { |
|
|
|
|
let ended = interval.end < Date() |
|
|
|
|
let state = LaunchWidgetAttributes.ContentState(ended: ended) |
|
|
|
|
let content = ActivityContent(state: state, staleDate: interval.end) |
|
|
|
|
await activity.update(content) |
|
|
|
|
print("Ending the Live Activity: \(activity.id)") |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
fileprivate func _endLiveActivity(countdownId: String) { |
|
|
|
|
|
|
|
|
|
|