BangleApps/apps/clkinfostopw/clkinfo.js

78 lines
2.6 KiB
JavaScript
Raw Normal View History

2023-02-20 18:36:49 +00:00
(function () {
var durationOnPause = "---";
var redrawInterval;
var startTime;
var showMillis = true;
var milliTime = 60;
2023-02-20 18:36:49 +00:00
var unqueueRedraw = function () {
if (redrawInterval)
clearInterval(redrawInterval);
redrawInterval = undefined;
};
var queueRedraw = function () {
var _this = this;
unqueueRedraw();
redrawInterval = setInterval(function () {
if (startTime) {
if (showMillis && Date.now() - startTime > milliTime * 1000) {
showMillis = false;
changeInterval(redrawInterval, 1000);
}
}
else {
unqueueRedraw();
}
_this.emit('redraw');
}, 100);
2023-02-20 18:36:49 +00:00
};
var pad2 = function (s) { return ('0' + s.toFixed(0)).slice(-2); };
var duration = function (start) {
var seconds = (Date.now() - start) / 1000;
if (seconds < milliTime)
2023-02-20 18:36:49 +00:00
return seconds.toFixed(1);
var mins = seconds / 60;
seconds %= 60;
if (mins < 60)
return "".concat(mins.toFixed(0), ":").concat(pad2(seconds));
2023-02-20 18:36:49 +00:00
var hours = mins / 60;
mins %= 60;
return "".concat(hours.toFixed(0), ":").concat(pad2(mins), ":").concat(pad2(seconds));
2023-02-20 18:36:49 +00:00
};
var img = function () { return atob("GBiBAAAAAAB+AAB+AAAAAAB+AAH/sAOB8AcA4A4YcAwYMBgYGBgYGBg8GBg8GBgYGBgAGAwAMA4AcAcA4AOBwAH/gAB+AAAAAAAAAA=="); };
return {
name: "timer",
2023-02-20 18:36:49 +00:00
img: img(),
items: [
{
name: "stopw",
get: function () { return ({
text: startTime
? duration(startTime)
: durationOnPause,
img: img(),
}); },
2023-04-16 20:06:23 +00:00
show: function () {
if (startTime) {
queueRedraw.call(this);
}
else {
this.emit('redraw');
}
},
2023-02-20 18:36:49 +00:00
hide: unqueueRedraw,
run: function () {
if (startTime) {
durationOnPause = duration(startTime);
startTime = undefined;
}
else {
queueRedraw.call(this);
showMillis = true;
2023-02-20 18:36:49 +00:00
startTime = Date.now();
}
}
}
]
};
}); // FIXME: semi-colon added automatically when Typescript generates Javascript file?