New clkinfo: stopw

pull/2589/head
Rob Pilling 2022-12-29 19:24:04 +00:00
parent 55d7a893b1
commit ae74346bb1
3 changed files with 57 additions and 0 deletions

BIN
apps/clkinfostopw/app.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.7 KiB

View File

@ -0,0 +1,44 @@
(() => {
let durationOnPause = "---";
let redrawInterval;
let startTime;
const unqueueRedraw = () => {
if (redrawInterval) clearInterval(redrawInterval);
redrawInterval = undefined;
};
const queueRedraw = function() {
unqueueRedraw();
redrawInterval = setInterval(() => this.emit('redraw'), 100);
};
const duration = () => ((Date.now() - startTime) / 1000).toFixed(1);
return {
name: "timer",
items: [
{
name: "stopw",
get: () => ({
text: startTime
? duration()
: durationOnPause,
img: atob("GBiBAAAAAAB+AAB+AAAAAAB+AAH/sAOB8AcA4A4YcAwYMBgYGBgYGBg8GBg8GBgYGBgAGAwAMA4AcAcA4AOBwAH/gAB+AAAAAAAAAA==")
}),
show: queueRedraw,
hide: unqueueRedraw,
run: function() { // tapped
if (startTime) {
durationOnPause = duration();
startTime = undefined;
unqueueRedraw();
} else {
queueRedraw.call(this);
startTime = Date.now();
}
}
}
]
};
})

View File

@ -0,0 +1,13 @@
{
"id": "clkinfostopw",
"name": "Stop Watch Clockinfo",
"version":"0.01",
"description": "A simple stopwatch, shown via clockinfo",
"icon": "app.png",
"type": "clkinfo",
"tags": "clkinfo,timer",
"supports" : ["BANGLEJS2"],
"storage": [
{"name":"stopw.clkinfo.js","url":"clkinfo.js"}
]
}