1
0
Fork 0

Merge pull request #2589 from bobrippling/stopw

New clock info: stopw
master
Gordon Williams 2023-02-22 08:20:04 +00:00 committed by GitHub
commit 55f47c4b86
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 152 additions and 3 deletions

View File

@ -0,0 +1 @@
0.01: New clkinfo!

View File

@ -0,0 +1,11 @@
# StopW
A simple stopwatch widget
## Usage
Tap to start, tap again to pause. Tap again to restart
## Requests
[Contact Rob](https://www.github.com/bobrippling) for features/bugs

BIN
apps/clkinfostopw/app.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.7 KiB

View File

@ -0,0 +1,58 @@
"use strict";
(function () {
var durationOnPause = "---";
var redrawInterval;
var startTime;
var unqueueRedraw = function () {
if (redrawInterval)
clearInterval(redrawInterval);
redrawInterval = undefined;
};
var queueRedraw = function () {
var _this = this;
unqueueRedraw();
redrawInterval = setInterval(function () { return _this.emit('redraw'); }, 100);
};
var pad2 = function (s) { return ('0' + s.toFixed(0)).slice(-2); };
var duration = function (start) {
var seconds = (Date.now() - start) / 1000;
if (seconds < 60)
return seconds.toFixed(1);
var mins = seconds / 60;
seconds %= 60;
if (mins < 60)
return "".concat(pad2(mins), "m").concat(pad2(seconds), "s");
var hours = mins / 60;
mins %= 60;
return "".concat(Math.round(hours), "h").concat(pad2(mins), "m").concat(pad2(seconds), "s");
};
var img = function () { return atob("GBiBAAAAAAB+AAB+AAAAAAB+AAH/sAOB8AcA4A4YcAwYMBgYGBgYGBg8GBg8GBgYGBgAGAwAMA4AcAcA4AOBwAH/gAB+AAAAAAAAAA=="); };
return {
name: "timer",
img: img(),
items: [
{
name: "stopw",
get: function () { return ({
text: startTime
? duration(startTime)
: durationOnPause,
img: img(),
}); },
show: queueRedraw,
hide: unqueueRedraw,
run: function () {
if (startTime) {
durationOnPause = duration(startTime);
startTime = undefined;
unqueueRedraw();
}
else {
queueRedraw.call(this);
startTime = Date.now();
}
}
}
]
};
});

View File

@ -0,0 +1,65 @@
((): ClockInfo.Menu => {
let durationOnPause = "---";
let redrawInterval: number | undefined;
let startTime: number | undefined;
const unqueueRedraw = () => {
if (redrawInterval) clearInterval(redrawInterval);
redrawInterval = undefined;
};
const queueRedraw = function(this: ClockInfo.MenuItem) {
unqueueRedraw();
redrawInterval = setInterval(() => this.emit('redraw'), 100);
};
const pad2 = (s: number) => ('0' + s.toFixed(0)).slice(-2);
const duration = (start: number) => {
let seconds = (Date.now() - start) / 1000;
if (seconds < 60)
return seconds.toFixed(1);
let mins = seconds / 60;
seconds %= 60;
if (mins < 60)
return `${pad2(mins)}m${pad2(seconds)}s`;
let hours = mins / 60;
mins %= 60;
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(startTime)
: durationOnPause,
img: img(),
}),
show: queueRedraw,
hide: unqueueRedraw,
run: function() { // tapped
if (startTime) {
durationOnPause = duration(startTime);
startTime = undefined;
unqueueRedraw();
} else {
queueRedraw.call(this);
startTime = Date.now();
}
}
}
]
};
})

View File

@ -0,0 +1,14 @@
{
"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"],
"allow_emulator": true,
"storage": [
{"name":"stopw.clkinfo.js","url":"clkinfo.js"}
]
}

View File

@ -20,7 +20,7 @@ declare module ClockInfo {
hasRange: true,
get(): RangeItem,
} | {
hasRange: false,
hasRange?: false,
get(): Item,
}
);

View File

@ -10096,11 +10096,11 @@ interface String {
/**
*
* @param {number} start - The start character index, if negative it is from the end of the string
* @param {any} end - The end character index, if negative it is from the end of the string, and if omitted it is the end of the string
* @param {any} [end] - [optional] The end character index, if negative it is from the end of the string, and if omitted it is the end of the string
* @returns {any} Part of this string from start for len characters
* @url http://www.espruino.com/Reference#l_String_slice
*/
slice(start: number, end: any): any;
slice(start: number, end?: any): any;
/**
* Return an array made by splitting this string up by the separator. e.g.