|
|
|
|
@ -26,6 +26,8 @@ class Conductor: ObservableObject { |
|
|
|
|
self.currentStopwatches = Conductor.savedStopwatches |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Published var cancelledCountdowns: [String] = [] |
|
|
|
|
|
|
|
|
|
@Published var currentCountdowns: [String : DateInterval] = [:] { |
|
|
|
|
didSet { |
|
|
|
|
Conductor.savedCountdowns = currentCountdowns |
|
|
|
|
@ -48,6 +50,7 @@ class Conductor: ObservableObject { |
|
|
|
|
|
|
|
|
|
func removeLiveTimer(id: String) { |
|
|
|
|
self.liveTimers.removeAll(where: { $0.id == id }) |
|
|
|
|
self.cancelledCountdowns.removeAll(where: { $0 == id }) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
fileprivate func _buildLiveTimers() { |
|
|
|
|
@ -58,38 +61,24 @@ class Conductor: ObservableObject { |
|
|
|
|
|
|
|
|
|
// add countdown if not present |
|
|
|
|
for liveCountdown in liveCountdowns { |
|
|
|
|
if let livetimer = self.liveTimers.first(where: { $0.id == liveCountdown.id }) { |
|
|
|
|
self.liveTimers.replace([livetimer], with: [liveCountdown]) |
|
|
|
|
if let index = self.liveTimers.firstIndex(where: { $0.id == liveCountdown.id }) { |
|
|
|
|
self.liveTimers.remove(at: index) |
|
|
|
|
self.liveTimers.insert(liveCountdown, at: index) |
|
|
|
|
} else { |
|
|
|
|
self.liveTimers.append(liveCountdown) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// remove after |
|
|
|
|
// for liveTimer in self.liveTimers { |
|
|
|
|
// let id: String = liveTimer.id |
|
|
|
|
// if liveCountdowns.first(where: { $0.id == id }) == nil { |
|
|
|
|
// let timer = Timer.scheduledTimer(withTimeInterval: 8.0, repeats: false) { _ in |
|
|
|
|
// self.removeLiveTimer(id: id) |
|
|
|
|
// } |
|
|
|
|
// self._cleanupTimers[id] = timer |
|
|
|
|
// } |
|
|
|
|
// } |
|
|
|
|
|
|
|
|
|
let liveStopwatches = self.currentStopwatches.map { |
|
|
|
|
return LiveTimer(id: $0, date: $1) |
|
|
|
|
} |
|
|
|
|
for liveStopwatch in liveStopwatches { |
|
|
|
|
if let livetimer = self.liveTimers.first(where: { $0.id == liveStopwatch.id }) { |
|
|
|
|
self.liveTimers.replace([livetimer], with: [liveStopwatch]) |
|
|
|
|
if let index = self.liveTimers.firstIndex(where: { $0.id == liveStopwatch.id }) { |
|
|
|
|
self.liveTimers.remove(at: index) |
|
|
|
|
self.liveTimers.insert(liveStopwatch, at: index) |
|
|
|
|
} else { |
|
|
|
|
self.liveTimers.append(liveStopwatch) |
|
|
|
|
} |
|
|
|
|
// |
|
|
|
|
// |
|
|
|
|
// if self.liveTimers.first(where: { $0.id == liveStopwatch.id }) == nil { |
|
|
|
|
// self.liveTimers.append(liveStopwatch) |
|
|
|
|
// } |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
@ -127,6 +116,7 @@ class Conductor: ObservableObject { |
|
|
|
|
func cancelCountdown(id: String) { |
|
|
|
|
CountdownScheduler.master.cancelCurrentNotifications(countdownId: id) |
|
|
|
|
self.stopSoundIfPossible() |
|
|
|
|
self.cancelledCountdowns.append(id) |
|
|
|
|
self._endCountdown(countdownId: id, cancel: true) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|