1
1
mirror of https://github.com/danbee/persephone synced 2025-03-04 08:39:11 +00:00

We need to run the timer on the main thread

This adds it to the main RunLoop.
This commit is contained in:
Daniel Barber 2019-04-19 20:17:45 -05:00
parent 22ba1b21ed
commit 5bb3fd099d
Signed by: danbarber
GPG Key ID: 931D8112E0103DD8

View File

@ -23,16 +23,17 @@ class TrackTimer: NSObject {
startTime = CACurrentMediaTime()
startElapsed = Double(elapsedTimeMs) / 1000
timer = Timer.scheduledTimer(
DispatchQueue.main.sync {
self.timer = Timer.scheduledTimer(
withTimeInterval: 0.25,
repeats: true
) { _ in
print("Timer fired")
let currentTime = CACurrentMediaTime()
let timeDiff = currentTime - self.startTime
let newElapsedTimeMs = UInt((self.startElapsed + timeDiff) * 1000)
DispatchQueue.main.async {
AppDelegate.store.dispatch(
UpdateElapsedTimeAction(elapsedTimeMs: newElapsedTimeMs)
)