clkinfo stopw: add option for format

master
Rob Pilling 2023-04-16 21:04:13 +01:00
parent 82b78d5b69
commit ac219f241f
4 changed files with 43 additions and 4 deletions

View File

@ -1,2 +1,2 @@
0.01: New clkinfo!
0.02: changed format to h:mm:ss, to reduce size of text string
0.02: Added format option, reduced battery usage

View File

@ -2,6 +2,8 @@
let durationOnPause = "---";
let redrawInterval: number | undefined;
let startTime: number | undefined;
let { format = StopWatchFormat.HMS }: StopWatchSettings
= require("Storage").readJSON("clkinfostopw.setting.json", true) || {};
const unqueueRedraw = () => {
if (redrawInterval) clearInterval(redrawInterval);
@ -25,12 +27,16 @@
seconds %= 60;
if (mins < 60)
return `${pad2(mins)}m${pad2(seconds)}s`;
return format === StopWatchFormat.HMS
? `${pad2(mins)}m${pad2(seconds)}s`
: `${mins.toFixed(0)}:${pad2(seconds)}`;
let hours = mins / 60;
mins %= 60;
return `${Math.round(hours)}h${pad2(mins)}m${pad2(seconds)}s`;
return format === StopWatchFormat.HMS
? `${hours.toFixed(0)}h${pad2(mins)}m${pad2(seconds)}s`
: `${hours.toFixed(0)}:${pad2(mins)}:${pad2(seconds)}`;
};
const img = () => atob("GBiBAAAAAAB+AAB+AAAAAAB+AAH/sAOB8AcA4A4YcAwYMBgYGBgYGBg8GBg8GBgYGBgAGAwAMA4AcAcA4AOBwAH/gAB+AAAAAAAAAA==");

View File

@ -10,6 +10,7 @@
"readme":"README.md",
"allow_emulator": true,
"storage": [
{"name":"stopw.clkinfo.js","url":"clkinfo.js"}
{"name":"stopw.clkinfo.js","url":"clkinfo.js"},
{"name":"stopw.settings.js","url":"settings.js"}
]
}

View File

@ -0,0 +1,32 @@
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,
format: () => settings.format == StopWatchFormat.HMS ? "12h34m56s" : "12:34:56",
onchange: () => {
settings.format = (settings.format + 1) % 2;
save();
},
},
});
})