1
0
Fork 0

barclock: use timeout to tick exactly on the second, instead of interval

master
Richard de Boer 2021-06-10 20:17:03 +02:00
parent 3df0e9d64c
commit 002f861038
3 changed files with 12 additions and 11 deletions

View File

@ -1312,7 +1312,7 @@
{ "id": "barclock",
"name": "Bar Clock",
"icon": "clock-bar.png",
"version":"0.05",
"version":"0.06",
"description": "A simple digital clock showing seconds as a bar",
"tags": "clock",
"type":"clock",

View File

@ -3,3 +3,4 @@
0.03: Fix dates drawing over each other at midnight
0.04: Small bugfix
0.05: Clock does not start if app Languages is not installed
0.06: Improve accuracy

View File

@ -124,7 +124,7 @@
g.fillRect(0, timeTop, screen.width, screen.height)
}
let lastSeconds
let lastSeconds, tTick
const tick = function () {
g.reset()
const date = new Date()
@ -136,20 +136,20 @@
}
// the bar only gets larger, so drawing on top of the previous one is fine
drawBar(date)
lastSeconds = seconds
// schedule next update
const millis = date.getMilliseconds()
tTick = setTimeout(tick, 1000-millis)
}
let iTick
const start = function () {
lastSeconds = 99 // force redraw
tick()
iTick = setInterval(tick, 1000)
}
const stop = function () {
if (iTick) {
clearInterval(iTick)
iTick = undefined
if (tTick) {
clearTimeout(tTick)
tTick = undefined
}
}