mirror of https://github.com/espruino/BangleApps
stopw: fix format and show milliseconds up to 1min
parent
05094f6c51
commit
f3a02082df
|
@ -3,7 +3,7 @@
|
|||
var redrawInterval;
|
||||
var startTime;
|
||||
var showMillis = true;
|
||||
var _a = (require("Storage").readJSON("clkinfostopw.setting.json", true) || {}).format, format = _a === void 0 ? 0 : _a;
|
||||
var milliTime = 60;
|
||||
var unqueueRedraw = function () {
|
||||
if (redrawInterval)
|
||||
clearInterval(redrawInterval);
|
||||
|
@ -14,7 +14,7 @@
|
|||
unqueueRedraw();
|
||||
redrawInterval = setInterval(function () {
|
||||
if (startTime) {
|
||||
if (showMillis && Date.now() - startTime > 60000) {
|
||||
if (showMillis && Date.now() - startTime > milliTime * 1000) {
|
||||
showMillis = false;
|
||||
changeInterval(redrawInterval, 1000);
|
||||
}
|
||||
|
@ -28,21 +28,15 @@
|
|||
var pad2 = function (s) { return ('0' + s.toFixed(0)).slice(-2); };
|
||||
var duration = function (start) {
|
||||
var seconds = (Date.now() - start) / 1000;
|
||||
if (seconds <= 1)
|
||||
if (seconds < milliTime)
|
||||
return seconds.toFixed(1);
|
||||
if (seconds < 60)
|
||||
return seconds.toFixed(0);
|
||||
var mins = seconds / 60;
|
||||
seconds %= 60;
|
||||
if (mins < 60)
|
||||
return format === 0
|
||||
? "".concat(mins.toFixed(0), "m").concat(pad2(seconds), "s")
|
||||
: "".concat(mins.toFixed(0), ":").concat(pad2(seconds));
|
||||
return "".concat(mins.toFixed(0), ":").concat(pad2(seconds));
|
||||
var hours = mins / 60;
|
||||
mins %= 60;
|
||||
return format === 0
|
||||
? "".concat(hours.toFixed(0), "h").concat(pad2(mins), "m").concat(pad2(seconds), "s")
|
||||
: "".concat(hours.toFixed(0), ":").concat(pad2(mins), ":").concat(pad2(seconds));
|
||||
return "".concat(hours.toFixed(0), ":").concat(pad2(mins), ":").concat(pad2(seconds));
|
||||
};
|
||||
var img = function () { return atob("GBiBAAAAAAB+AAB+AAAAAAB+AAH/sAOB8AcA4A4YcAwYMBgYGBgYGBg8GBg8GBgYGBgAGAwAMA4AcAcA4AOBwAH/gAB+AAAAAAAAAA=="); };
|
||||
return {
|
||||
|
|
|
@ -3,8 +3,7 @@
|
|||
let redrawInterval: number | undefined;
|
||||
let startTime: number | undefined;
|
||||
let showMillis = true;
|
||||
let { format = StopWatchFormat.HMS }: StopWatchSettings
|
||||
= require("Storage").readJSON("clkinfostopw.setting.json", true) || {};
|
||||
const milliTime = 60;
|
||||
|
||||
const unqueueRedraw = () => {
|
||||
if (redrawInterval) clearInterval(redrawInterval);
|
||||
|
@ -15,7 +14,7 @@
|
|||
unqueueRedraw();
|
||||
redrawInterval = setInterval(() => {
|
||||
if (startTime) {
|
||||
if (showMillis && Date.now() - startTime > 60000) {
|
||||
if (showMillis && Date.now() - startTime > milliTime * 1000) {
|
||||
showMillis = false;
|
||||
changeInterval(redrawInterval, 1000);
|
||||
}
|
||||
|
@ -31,25 +30,19 @@
|
|||
const duration = (start: number) => {
|
||||
let seconds = (Date.now() - start) / 1000;
|
||||
|
||||
if (seconds <= 1)
|
||||
if (seconds < milliTime)
|
||||
return seconds.toFixed(1);
|
||||
if (seconds < 60)
|
||||
return seconds.toFixed(0);
|
||||
|
||||
let mins = seconds / 60;
|
||||
seconds %= 60;
|
||||
|
||||
if (mins < 60)
|
||||
return format === StopWatchFormat.HMS
|
||||
? `${mins.toFixed(0)}m${pad2(seconds)}s`
|
||||
: `${mins.toFixed(0)}:${pad2(seconds)}`;
|
||||
return `${mins.toFixed(0)}:${pad2(seconds)}`;
|
||||
|
||||
let hours = mins / 60;
|
||||
mins %= 60;
|
||||
|
||||
return format === StopWatchFormat.HMS
|
||||
? `${hours.toFixed(0)}h${pad2(mins)}m${pad2(seconds)}s`
|
||||
: `${hours.toFixed(0)}:${pad2(mins)}:${pad2(seconds)}`;
|
||||
return `${hours.toFixed(0)}:${pad2(mins)}:${pad2(seconds)}`;
|
||||
};
|
||||
|
||||
const img = () => atob("GBiBAAAAAAB+AAB+AAAAAAB+AAH/sAOB8AcA4A4YcAwYMBgYGBgYGBg8GBg8GBgYGBgAGAwAMA4AcAcA4AOBwAH/gAB+AAAAAAAAAA==");
|
||||
|
|
|
@ -10,7 +10,6 @@
|
|||
"readme":"README.md",
|
||||
"allow_emulator": true,
|
||||
"storage": [
|
||||
{"name":"stopw.clkinfo.js","url":"clkinfo.js"},
|
||||
{"name":"stopw.settings.js","url":"settings.js"}
|
||||
{"name":"stopw.clkinfo.js","url":"clkinfo.js"}
|
||||
]
|
||||
}
|
||||
|
|
|
@ -1,24 +0,0 @@
|
|||
(function (back) {
|
||||
var _a;
|
||||
var SETTINGS_FILE = "clkinfostopw.setting.json";
|
||||
var storage = require("Storage");
|
||||
var settings = storage.readJSON(SETTINGS_FILE, true) || {};
|
||||
(_a = settings.format) !== null && _a !== void 0 ? _a : (settings.format = 0);
|
||||
var save = function () {
|
||||
storage.writeJSON(SETTINGS_FILE, settings);
|
||||
};
|
||||
E.showMenu({
|
||||
"": { "title": "stopwatch" },
|
||||
"< Back": back,
|
||||
"Format": {
|
||||
value: settings.format,
|
||||
min: 0,
|
||||
max: 1,
|
||||
format: function (v) { return v === 0 ? "12m34s" : "12:34"; },
|
||||
onchange: function (v) {
|
||||
settings.format = v;
|
||||
save();
|
||||
},
|
||||
},
|
||||
});
|
||||
});
|
|
@ -1,34 +0,0 @@
|
|||
const enum StopWatchFormat {
|
||||
HMS,
|
||||
Colon,
|
||||
}
|
||||
type StopWatchSettings = {
|
||||
format: StopWatchFormat,
|
||||
};
|
||||
|
||||
((back: () => void) => {
|
||||
const SETTINGS_FILE = "clkinfostopw.setting.json";
|
||||
|
||||
const storage = require("Storage");
|
||||
const settings: StopWatchSettings = storage.readJSON(SETTINGS_FILE, true) || {};
|
||||
settings.format ??= StopWatchFormat.HMS;
|
||||
|
||||
const save = () => {
|
||||
storage.writeJSON(SETTINGS_FILE, settings)
|
||||
};
|
||||
|
||||
E.showMenu({
|
||||
"": { "title": "stopwatch" },
|
||||
"< Back": back,
|
||||
"Format": {
|
||||
value: settings.format,
|
||||
min: StopWatchFormat.HMS,
|
||||
max: StopWatchFormat.Colon,
|
||||
format: v => v === StopWatchFormat.HMS ? "12m34s" : "12:34",
|
||||
onchange: v => {
|
||||
settings.format = v;
|
||||
save();
|
||||
},
|
||||
},
|
||||
});
|
||||
})
|
Loading…
Reference in New Issue