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:
parent
5651276bd6
commit
d076ef311b
@ -17,22 +17,23 @@ class TrackTimer: NSObject {
|
||||
print("Starting timer")
|
||||
guard let elapsedTimeMs = elapsedTimeMs else { return }
|
||||
print(elapsedTimeMs)
|
||||
|
||||
|
||||
timer?.invalidate()
|
||||
|
||||
startTime = CACurrentMediaTime()
|
||||
startElapsed = Double(elapsedTimeMs) / 1000
|
||||
|
||||
timer = Timer.scheduledTimer(
|
||||
withTimeInterval: 0.25,
|
||||
repeats: true
|
||||
) { _ in
|
||||
let currentTime = CACurrentMediaTime()
|
||||
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)
|
||||
let timeDiff = currentTime - self.startTime
|
||||
let newElapsedTimeMs = UInt((self.startElapsed + timeDiff) * 1000)
|
||||
|
||||
DispatchQueue.main.async {
|
||||
AppDelegate.store.dispatch(
|
||||
UpdateElapsedTimeAction(elapsedTimeMs: newElapsedTimeMs)
|
||||
)
|
||||
|
||||
Loading…
Reference in New Issue
Block a user