From dc3d591a01dca9b89e67a032fd85df9247a83aaa Mon Sep 17 00:00:00 2001 From: Mikael <112403418+mikael-ros@users.noreply.github.com> Date: Sat, 14 Sep 2024 23:33:00 +0200 Subject: [PATCH] Made it theoretically impossible for the timer to glitch out --- src/components/ui/Timer.tsx | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/src/components/ui/Timer.tsx b/src/components/ui/Timer.tsx index e807595..459a6e2 100644 --- a/src/components/ui/Timer.tsx +++ b/src/components/ui/Timer.tsx @@ -22,6 +22,10 @@ class Time { this.sound = new Audio(timerSound); this.sound.volume = getSetOrElse("volume", 1.0); this.timeDisplay(this.toString()); + this.interval = null; + } + + start(){ this.interval = window.setInterval(() => { if (!this.lapsed()){ this.tick() @@ -51,12 +55,7 @@ class Time { this.time = this.initTime; this.kill(false); this.timeDisplay(this.toString()); - this.interval = window.setInterval(() => { - if (!this.lapsed()){ - this.tick() - } else { - this.kill(true); - }}, 1000); + this.start(); } reset(){