From 0de496bf3c9a9e03f60e2d4883da7dd79a348fe0 Mon Sep 17 00:00:00 2001 From: Interitio Date: Mon, 22 Sep 2025 23:26:56 +1000 Subject: [PATCH] Adjust to new timer channel format. --- timer.js | 41 ++++++++++++++++++++++------------------- 1 file changed, 22 insertions(+), 19 deletions(-) diff --git a/timer.js b/timer.js index b3b0dbd..affd02e 100644 --- a/timer.js +++ b/timer.js @@ -31,13 +31,15 @@ class Timer { var minutes = Math.floor(dur_seconds / 60); var hours = Math.floor(minutes / 60); minutes = minutes - 60 * hours; - - timestr = String(hours).padStart(2, '0') + ':' + String(minutes).padStart(2, '0'); + // Change rendering mode based on hours or minutes left + if (hours > 0) { + timestr = String(hours).padStart(2, '0') + ':' + String(minutes).padStart(2, '0'); + } else { + timestr = String(minutes).padStart(2, '0') + ':' + String(seconds).padStart(2, '0'); + } } - if (this.running) { - this.renderer.update_time(timestr); - } + this.renderer.update_time(timestr); } tick() { @@ -47,7 +49,9 @@ class Timer { return } this.render_time(); - setTimeout(this.tick.bind(this), 1000); + if (this.running) { + setTimeout(this.tick.bind(this), 1000); + } } } @@ -74,23 +78,13 @@ class TimerRenderer { this.time_element.textContent = timestr; } - set_break_color () { - this.background.style.setProperty('--stage-color', 'var(--break-color)'); - this.time_element.style.color = "var(--break-color)"; - } - - set_focus_color () { - this.background.style.setProperty('--stage-color', 'var(--focus-color)'); - this.time_element.style.color = "var(--focus-color)"; - } - } function communicate(websocket) { console.log("Communicating"); const params = new URLSearchParams(window.location.search); - websocket.send(JSON.stringify({type: "init", channel: "SubTimer", channelid: params.get('channelid')})); + websocket.send(JSON.stringify({type: "init", channel: "SubTimer", community: params.get('community')})); var renderer = new TimerRenderer(); let timer; @@ -111,11 +105,20 @@ function communicate(websocket) { timer = new Timer( renderer, new Date(args.end_at), - true + args.running ) timer.tick(); - timer.running = args.running; break; + case "noTimer": + if (timer != null) { + timer.renderer.update_time("--:--") + timer.destroying = true; + } + case "endTimer": + if (timer != null) { + timer.renderer.update_time("00:00") + timer.destroying = true; + } default: throw new Error(`Unsupported method requested: ${event.method}.`) }