|
|
|
|
@ -122,27 +122,27 @@ 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 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) |
|
|
|
|
@ -167,14 +167,17 @@ class Conductor: ObservableObject { |
|
|
|
|
do { |
|
|
|
|
let date = Date(timeIntervalSinceNow: countdown.duration) |
|
|
|
|
|
|
|
|
|
self.startCountdown(date, countdown: countdown) |
|
|
|
|
|
|
|
|
|
self.removeLiveTimer(id: countdown.stringId) |
|
|
|
|
|
|
|
|
|
let soundFile = try SoundFile(fullName: countdown.soundName) |
|
|
|
|
let soundPlayer = try DelaySoundPlayer(timerID: countdown.stringId, soundFile: soundFile) |
|
|
|
|
self._delayedSoundPlayers[countdown.stringId] = soundPlayer |
|
|
|
|
try soundPlayer.start(in: countdown.duration, |
|
|
|
|
repeatCount: Int(countdown.repeatCount)) |
|
|
|
|
|
|
|
|
|
let dateInterval = DateInterval(start: Date(), end: date) |
|
|
|
|
self.currentCountdowns[countdown.stringId] = dateInterval |
|
|
|
|
|
|
|
|
|
if Preferences.playConfirmationSound { |
|
|
|
|
self._playSound(Const.confirmationSound.rawValue) |
|
|
|
|
} |
|
|
|
|
@ -315,11 +318,11 @@ class Conductor: ObservableObject { |
|
|
|
|
|
|
|
|
|
func deactivateAudioSessionIfPossible() { |
|
|
|
|
if self._delayedSoundPlayers.isEmpty { |
|
|
|
|
do { |
|
|
|
|
try AVAudioSession.sharedInstance().setActive(false) |
|
|
|
|
} catch { |
|
|
|
|
Logger.error(error) |
|
|
|
|
} |
|
|
|
|
// do { |
|
|
|
|
// try AVAudioSession.sharedInstance().setActive(false) |
|
|
|
|
// } catch { |
|
|
|
|
// Logger.error(error) |
|
|
|
|
// } |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|