diff --git a/apps/presentation_timer/metadata.json b/apps/presentation_timer/metadata.json index 8790d6208..39fe6d195 100644 --- a/apps/presentation_timer/metadata.json +++ b/apps/presentation_timer/metadata.json @@ -13,5 +13,8 @@ {"name":"presentation_timer.app.js","url":"presentation_timer.app.js"}, {"name":"presentation_timer.img","url":"presentation_timer.icon.js","evaluate":true} ], - "data": [{ "name": "presentation_timer.csv" }] + "data": [ + {"name":"presentation_timer.json"} + { "name": "presentation_timer.csv" } + ] } diff --git a/apps/presentation_timer/presentation_timer.app.js b/apps/presentation_timer/presentation_timer.app.js index 1d0e5945d..fd0021d17 100644 --- a/apps/presentation_timer/presentation_timer.app.js +++ b/apps/presentation_timer/presentation_timer.app.js @@ -1,9 +1,21 @@ +const CONFIGFILE = "presentation_timer.json"; + +const now = Date.now(); +const config = Object.assign({ + state: { + total: now, + start: now, + current: now, + running: false, + } +}, require("Storage").readJSON(CONFIGFILE,1) || {}); + let w = g.getWidth(); let h = g.getHeight(); -let tTotal = Date.now(); -let tStart = tTotal; -let tCurrent = tTotal; -let running = false; +let tTotal = config.state.total; +let tStart = config.state.start; +let tCurrent = config.state.current; +let running = config.state.running; let timeY = 2*h/5; let displayInterval; let redrawButtons = true; @@ -15,6 +27,14 @@ const pause_img = atob("GBiBAf////////////////wYP/wYP/wYP/wYP/wYP/wYP/wYP/wYP/wY const play_img = atob("GBjBAP//AAAAAAAAAAAIAAAOAAAPgAAP4AAP+AAP/AAP/wAP/8AP//AP//gP//gP//AP/8AP/wAP/AAP+AAP4AAPgAAOAAAIAAAAAAAAAAA="); const reset_img = atob("GBiBAf////////////AAD+AAB+f/5+f/5+f/5+cA5+cA5+cA5+cA5+cA5+cA5+cA5+cA5+f/5+f/5+f/5+AAB/AAD////////////w=="); +function saveState() { + config.state.total = tTotal; + config.state.start = tStart; + config.state.current = tCurrent; + config.state.running = running; + require("Storage").writeJSON(CONFIGFILE, config); +} + const margin = 0.5; //half a minute tolerance //dummy default values @@ -147,6 +167,7 @@ function stopStart() { } else { draw(); } + saveState(); } function setButtonImages() { @@ -171,6 +192,7 @@ function lapReset() { g.clearRect(0,24,w,h); draw(); } + saveState(); } // simple on screen button class @@ -268,5 +290,10 @@ g.fillRect(0,0,w,h); Bangle.loadWidgets(); Bangle.drawWidgets(); readSlides(); -draw(); +setButtonImages(); +if (running) { + startTimer(); +} else { + draw(); +} setWatch(() => load(), BTN, { repeat: false, edge: "falling" });