From 4a35b30bb07d382d02b7b9a74d33c79194f91477 Mon Sep 17 00:00:00 2001 From: Rob Pilling Date: Fri, 1 Mar 2024 22:33:14 +0000 Subject: [PATCH] multitimer: restore json & sw default --- apps/multitimer/app.js | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/apps/multitimer/app.js b/apps/multitimer/app.js index 6d2c2f237..31da18796 100644 --- a/apps/multitimer/app.js +++ b/apps/multitimer/app.js @@ -328,21 +328,22 @@ function editTimer(idx, a) { setUI(); } -function readAndConvJson() { - let json = require("Storage").readJSON("multitimer.json", true); +function readJson() { + let json = require("Storage").readJSON("multitimer.json", true) || {}; if (Array.isArray(json)) { // old format, convert json = { sw: json }; require("Storage").writeJSON("multitimer.json", json); } + if (!json.sw) json.sw = []; return json; } function drawSw() { layer = 1; - const sw = readAndConvJson().sw; + const sw = readJson().sw; function updateTimers(idx) { if (!timerInt1[idx]) timerInt1[idx] = setTimeout(function() { @@ -394,8 +395,7 @@ function drawSw() { function swMenu(idx, a) { layer = -1; - const json = require("Storage").readJSON("multitimer.json", true) || {}; - json.sw = json.sw || []; + const json = readJson(); const sw = json.sw; if (sw[idx]) a = sw[idx]; else { @@ -721,7 +721,7 @@ function onDrag(e) { } } -switch (readAndConvJson().initialScreen) { +switch (readJson().initialScreen) { case 1: drawSw(); break;