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