From 5e58abdba883af77f803de55f7b2d6e77baeac4d Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Tom=C3=A1=C5=A1=20Valenta?= <git@imaniti.org>
Date: Tue, 24 Oct 2023 23:00:01 +0200
Subject: [PATCH] let the timer count down on its own if within 5 seconds

---
 static_src/timer.js | 15 +++++++++++++--
 1 file changed, 13 insertions(+), 2 deletions(-)

diff --git a/static_src/timer.js b/static_src/timer.js
index 6d73c6d..ce4212e 100644
--- a/static_src/timer.js
+++ b/static_src/timer.js
@@ -151,13 +151,15 @@ $(window).ready(
                 }
 
                 if ("is_running" in data) {
+                    const remainingTime = window.timer.getTimeValues()
+
                     if (data["is_running"]) {
                         // Don't do anything if we have reached an inconsistent state,
                         // where the timer is at 0 but server still reports it playing.
                         // This will be resolved within a few milliseconds.
-                        const remainingTime = window.timer.getTimeValues()
 
-                        if (remainingTime.seconds === 0 && remainingTime.minutes === 0) {
+                        if (remainingTime.minutes === 0 && remainingTime.seconds === 0) {
+                            return
                         }
 
                         window.timer.start()
@@ -166,6 +168,15 @@ $(window).ready(
                         $("#pause_play > .btn__body").html("⏸︎")
                         window.timerIsRunning = true
                     } else {
+                        if (
+                            window.timerIsRunning
+                            && "sync_time" in data
+                            && data["sync_time"]["minutes"] === 0
+                            && data["sync_time"]["seconds"] === 0
+                        ) {
+                            return
+                        }
+
                         window.timer.pause()
 
                         $("#is_counting").prop("checked", false)
-- 
GitLab