clkinfostopw: js -> ts

pull/2589/head
Rob Pilling 2023-02-20 18:32:06 +00:00
parent 7aa89220be
commit 03b5210e7b
1 changed files with 13 additions and 10 deletions

View File

@ -1,22 +1,22 @@
(() => { ((): ClockInfo.Menu => {
let durationOnPause = "---"; let durationOnPause = "---";
let redrawInterval; let redrawInterval: number | undefined;
let startTime; let startTime: number | undefined;
const unqueueRedraw = () => { const unqueueRedraw = () => {
if (redrawInterval) clearInterval(redrawInterval); if (redrawInterval) clearInterval(redrawInterval);
redrawInterval = undefined; redrawInterval = undefined;
}; };
const queueRedraw = function() { const queueRedraw = function(this: ClockInfo.MenuItem) {
unqueueRedraw(); unqueueRedraw();
redrawInterval = setInterval(() => this.emit('redraw'), 100); redrawInterval = setInterval(() => this.emit('redraw'), 100);
}; };
const pad2 = s => ('0' + s.toFixed(0)).slice(-2); const pad2 = (s: number) => ('0' + s.toFixed(0)).slice(-2);
const duration = () => { const duration = (start: number) => {
let seconds = (Date.now() - startTime) / 1000; let seconds = (Date.now() - start) / 1000;
if (seconds < 60) if (seconds < 60)
return seconds.toFixed(1); return seconds.toFixed(1);
@ -33,22 +33,25 @@
return `${Math.round(hours)}h${pad2(mins)}m${pad2(seconds)}s`; return `${Math.round(hours)}h${pad2(mins)}m${pad2(seconds)}s`;
}; };
const img = () => atob("GBiBAAAAAAB+AAB+AAAAAAB+AAH/sAOB8AcA4A4YcAwYMBgYGBgYGBg8GBg8GBgYGBgAGAwAMA4AcAcA4AOBwAH/gAB+AAAAAAAAAA==");
return { return {
name: "timer", name: "timer",
img: img(),
items: [ items: [
{ {
name: "stopw", name: "stopw",
get: () => ({ get: () => ({
text: startTime text: startTime
? duration() ? duration(startTime)
: durationOnPause, : durationOnPause,
img: atob("GBiBAAAAAAB+AAB+AAAAAAB+AAH/sAOB8AcA4A4YcAwYMBgYGBgYGBg8GBg8GBgYGBgAGAwAMA4AcAcA4AOBwAH/gAB+AAAAAAAAAA==") img: img(),
}), }),
show: queueRedraw, show: queueRedraw,
hide: unqueueRedraw, hide: unqueueRedraw,
run: function() { // tapped run: function() { // tapped
if (startTime) { if (startTime) {
durationOnPause = duration(); durationOnPause = duration(startTime);
startTime = undefined; startTime = undefined;
unqueueRedraw(); unqueueRedraw();
} else { } else {