clkinfo stopw: add option for format
parent
82b78d5b69
commit
ac219f241f
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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==");
|
||||
|
|
|
|||
|
|
@ -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"}
|
||||
]
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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();
|
||||
},
|
||||
},
|
||||
});
|
||||
})
|
||||
Loading…
Reference in New Issue