|
|
|
|
@ -61,9 +61,8 @@ class Conductor: ObservableObject { |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func removeLiveTimer(id: String) { |
|
|
|
|
|
|
|
|
|
Logger.log("removeLiveTimer") |
|
|
|
|
func removeLiveTimer(id: TimerID) { |
|
|
|
|
// Logger.log("removeLiveTimer") |
|
|
|
|
self.liveTimers.removeAll(where: { $0.id == id }) |
|
|
|
|
self.cancelledCountdowns.removeAll(where: { $0 == id }) |
|
|
|
|
if let soundPlayer = self._delayedSoundPlayers[id] { |
|
|
|
|
@ -77,7 +76,7 @@ class Conductor: ObservableObject { |
|
|
|
|
|
|
|
|
|
fileprivate func _buildLiveTimers() { |
|
|
|
|
|
|
|
|
|
Logger.log("_buildLiveTimers") |
|
|
|
|
// Logger.log("_buildLiveTimers") |
|
|
|
|
|
|
|
|
|
let liveCountdowns = self.currentCountdowns.map { |
|
|
|
|
return LiveTimer(id: $0, date: $1.end) |
|
|
|
|
@ -127,28 +126,6 @@ class Conductor: ObservableObject { |
|
|
|
|
|
|
|
|
|
// MARK: - Countdown |
|
|
|
|
|
|
|
|
|
// func startCountdown(_ date: Date, countdown: Countdown) { |
|
|
|
|
//// DispatchQueue.main.async { |
|
|
|
|
// |
|
|
|
|
// Logger.log("Starts countdown: \(countdown.displayName)") |
|
|
|
|
// |
|
|
|
|
// // cleanup existing countdowns |
|
|
|
|
// self.removeLiveTimer(id: countdown.stringId) |
|
|
|
|
// |
|
|
|
|
//// self._cleanupTimers.removeValue(forKey: countdown.stringId) |
|
|
|
|
// |
|
|
|
|
// let dateInterval = DateInterval(start: Date(), end: date) |
|
|
|
|
// self.currentCountdowns[countdown.stringId] = dateInterval |
|
|
|
|
// |
|
|
|
|
//// self._launchLiveActivity(countdown: countdown, endDate: date) |
|
|
|
|
// |
|
|
|
|
//// self._createTimerIntent(countdown) |
|
|
|
|
// |
|
|
|
|
//// Logger.log("countdowns count = \(self.currentCountdowns.count)") |
|
|
|
|
// |
|
|
|
|
//// } |
|
|
|
|
// } |
|
|
|
|
|
|
|
|
|
func cancelCountdown(id: TimerID) { |
|
|
|
|
CountdownScheduler.master.cancelCurrentNotifications(countdownId: id) |
|
|
|
|
self.cancelSoundPlayer(id: id) |
|
|
|
|
@ -169,7 +146,7 @@ class Conductor: ObservableObject { |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func prepareAlarm(countdown: Countdown, handler: @escaping (Result<Date?, Error>) -> Void) { |
|
|
|
|
func startCountdown(countdown: Countdown, handler: @escaping (Result<Date?, Error>) -> Void) { |
|
|
|
|
|
|
|
|
|
DispatchQueue.main.async { |
|
|
|
|
|
|
|
|
|
@ -179,8 +156,7 @@ class Conductor: ObservableObject { |
|
|
|
|
self.removeLiveTimer(id: countdown.stringId) |
|
|
|
|
|
|
|
|
|
let sound = countdown.someSound |
|
|
|
|
let soundFile = try SoundFile(fullName: sound.fileName) |
|
|
|
|
let soundPlayer = try DelaySoundPlayer(timerID: countdown.stringId, soundFile: soundFile) |
|
|
|
|
let soundPlayer = try DelaySoundPlayer(timerID: countdown.stringId, sound: sound) |
|
|
|
|
self._delayedSoundPlayers[countdown.stringId] = soundPlayer |
|
|
|
|
try soundPlayer.start(in: countdown.duration, |
|
|
|
|
repeatCount: Int(countdown.repeatCount)) |
|
|
|
|
@ -240,8 +216,7 @@ class Conductor: ObservableObject { |
|
|
|
|
|
|
|
|
|
do { |
|
|
|
|
let sound: Sound = countdown.someSound |
|
|
|
|
let soundFile: SoundFile = try SoundFile(fullName: sound.fileName) |
|
|
|
|
let soundPlayer = try DelaySoundPlayer(timerID: countdownId, soundFile: soundFile) |
|
|
|
|
let soundPlayer = try DelaySoundPlayer(timerID: countdownId, sound: sound) |
|
|
|
|
self._delayedSoundPlayers[countdown.stringId] = soundPlayer |
|
|
|
|
try soundPlayer.restore(for: interval.end, repeatCount: Int(countdown.repeatCount)) |
|
|
|
|
} catch { |
|
|
|
|
|