diff --git a/apps/multitimer/ChangeLog b/apps/multitimer/ChangeLog index 67b0cc014..fff0d3d23 100644 --- a/apps/multitimer/ChangeLog +++ b/apps/multitimer/ChangeLog @@ -6,3 +6,4 @@ 0.06: Support fastloading 0.07: Fix fastloading support - ensure drag handler's restored after menu display/fastload removes it +0.08: Add setting for initial page to display diff --git a/apps/multitimer/app.js b/apps/multitimer/app.js index 965a12d26..99830cea1 100644 --- a/apps/multitimer/app.js +++ b/apps/multitimer/app.js @@ -328,9 +328,21 @@ function editTimer(idx, a) { setUI(); } +function readAndConvJson() { + let json = require("Storage").readJSON("multitimer.json", true); + + if (Array.isArray(json)) { + // old format, convert + json = { sw: json }; + require("Storage").writeJSON("multitimer.json", json); + } + + return json; +} + function drawSw() { layer = 1; - const sw = require("Storage").readJSON("multitimer.json", true) || []; + const sw = readAndConvJson().sw; function updateTimers(idx) { if (!timerInt1[idx]) timerInt1[idx] = setTimeout(function() { @@ -382,12 +394,14 @@ function drawSw() { function swMenu(idx, a) { layer = -1; - const sw = require("Storage").readJSON("multitimer.json", true) || []; + const json = require("Storage").readJSON("multitimer.json", true) || {}; + json.sw = json.sw || []; + const sw = json.sw; if (sw[idx]) a = sw[idx]; else { a = {"t" : 0, "on" : false, "msg" : ""}; sw[idx] = a; - require("Storage").writeJSON("multitimer.json", sw); + require("Storage").writeJSON("multitimer.json", json); } function updateTimer() { @@ -408,7 +422,7 @@ function swMenu(idx, a) { } else delete a.msg; sw[idx] = a; - require("Storage").writeJSON("multitimer.json", sw); + require("Storage").writeJSON("multitimer.json", json); swMenu(idx, a); }); } @@ -458,7 +472,7 @@ function swMenu(idx, a) { select : (i) => { function saveAndReload() { - require("Storage").writeJSON("multitimer.json", sw); + require("Storage").writeJSON("multitimer.json", json); s.draw(); } @@ -707,5 +721,17 @@ function onDrag(e) { } } -drawTimers(); +switch (readAndConvJson().initialScreen) { + case 0: + case undefined: + default: + drawTimers(); + break; + case 1: + drawSw(); + break; + case 2: + drawAlarms(); + break; +} } diff --git a/apps/multitimer/metadata.json b/apps/multitimer/metadata.json index e753d0581..8ba946520 100644 --- a/apps/multitimer/metadata.json +++ b/apps/multitimer/metadata.json @@ -1,7 +1,7 @@ { "id": "multitimer", "name": "Multi Timer", - "version": "0.07", + "version": "0.08", "description": "Set timers and chronographs (stopwatches) and watch them count down in real time. Pause, create, edit, and delete timers and chronos, and add custom labels/messages. Also sets alarms.", "icon": "app.png", "screenshots": [ @@ -16,6 +16,7 @@ {"name":"multitimer.app.js","url":"app.js"}, {"name":"multitimer.boot.js","url":"boot.js"}, {"name":"multitimer.alarm.js","url":"alarm.js"}, + {"name":"multitimer.settings.js","url":"settings.js"}, {"name":"multitimer.img","url":"app-icon.js","evaluate":true} ], "data": [{"name":"multitimer.json"}], diff --git a/apps/multitimer/settings.js b/apps/multitimer/settings.js new file mode 100644 index 000000000..de0ed74f4 --- /dev/null +++ b/apps/multitimer/settings.js @@ -0,0 +1,31 @@ +(function(back) { + const file = "multitimer.json"; + let json = require('Storage').readJSON(file, true); + if (Array.isArray(json)) { + // old format, convert + json = { sw: json }; + } + + function writeSettings() { + require('Storage').writeJSON(file, json); + } + + const screens = ["Timers", "Chronos", "Alarms"]; + + E.showMenu({ + "": { + "title": "multitimer" + }, + "< Back": back, + "Initial screen": { + value: json.initialScreen || 0, + min: 0, + max: screens.length - 1, + format: v => screens[v], + onchange: v => { + json.initialScreen = v; + writeSettings(); + } + }, + }); +});