Skip to content

Commit 995aefb

Browse files
author
thyttan
committed
ateatimer: fix initial draw when timer was already running
1 parent 76f4b0a commit 995aefb

File tree

2 files changed

+11
-5
lines changed

2 files changed

+11
-5
lines changed

apps/ateatimer/ChangeLog

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
0.01: First release
22
0.02: Fix icon, utilize sched, show running timer on app relaunch
33
0.03: Flash time in green when starting the timer
4-
0.04: Buzz when starting and resetting timer
4+
0.04: Buzz when starting and resetting timer. Fix initial draw when timer is
5+
running.

apps/ateatimer/app.js

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -147,11 +147,15 @@ function handleTouch(x, y) {
147147
}
148148
}
149149

150+
let updateTimeRemaining = ()=>{
151+
let alarm = require("sched").getAlarm("ateatimer");
152+
timeRemaining = Math.floor(require("sched").getTimeToAlarm(alarm) / 1000);
153+
}
154+
150155
// Function to update the display every second
151156
function updateDisplay() {
152157
if (timerRunning) {
153-
let alarm = require("sched").getAlarm("ateatimer");
154-
timeRemaining = Math.floor(require("sched").getTimeToAlarm(alarm) / 1000);
158+
updateTimeRemaining();
155159
drawTime();
156160
if (timeRemaining <= 0) {
157161
timeRemaining = 0;
@@ -176,10 +180,11 @@ Bangle.on("touch", (zone, xy) => {
176180
});
177181

178182
let isRunning = require("sched").getAlarm("ateatimer");
179-
// Draw the initial timer display
180-
drawInit();
181183
if (isRunning) {
182184
timerRunning = true;
183185
// Start the timer to update the display
184186
updateIntervalID = setInterval(updateDisplay, 1000);
187+
updateTimeRemaining();
185188
}
189+
// Draw the initial timer display
190+
drawInit();

0 commit comments

Comments
 (0)