diff --git a/apps/run/ChangeLog b/apps/run/ChangeLog index 95945be78..3638407ef 100644 --- a/apps/run/ChangeLog +++ b/apps/run/ChangeLog @@ -13,3 +13,4 @@ 0.12: Fix for recorder not stopping at end of run. Bug introduced in 0.11 0.13: Revert #1578 (stop duplicate entries) as with 2v12 menus it causes other boxes to be wiped (fix #1643) 0.14: Fix Bangle.js 1 issue where after the 'overwrite track' menu, the start/stop button stopped working +0.15: Keep run state between runs (allowing you to exit and restart the app) diff --git a/apps/run/app.js b/apps/run/app.js index 4038b8c1a..a56fce31c 100644 --- a/apps/run/app.js +++ b/apps/run/app.js @@ -41,6 +41,13 @@ var statIDs = [settings.B1,settings.B2,settings.B3,settings.B4,settings.B5,setti var exs = ExStats.getStats(statIDs, settings); // --------------------------- +function setStatus(running) { + layout.button.label = running ? "STOP" : "START"; + layout.status.label = running ? "RUN" : "STOP"; + layout.status.bgCol = running ? "#0f0" : "#f00"; + layout.render(); +} + // Called to start/stop running function onStartStop() { var running = !exs.state.active; @@ -77,12 +84,9 @@ function onStartStop() { } else { exs.stop(); } - layout.button.label = running ? "STOP" : "START"; - layout.status.label = running ? "RUN" : "STOP"; - layout.status.bgCol = running ? "#0f0" : "#f00"; // if stopping running, don't clear state // so we can at least refer to what we've done - layout.render(); + setStatus(running); }); } @@ -105,13 +109,14 @@ for (var i=0;i{if (karvonnenActive) {stopKarvonnenUI();run();} onStartStop();}, id:"button"}]}); +},{lazy:true, btns:[{ label:"---", cb: ()=>{if (karvonnenActive) {stopKarvonnenUI();run();} onStartStop();}, id:"button"}]}); delete lc; +setStatus(exs.state.active); layout.render(); function configureNotification(stat) { diff --git a/modules/exstats.js b/modules/exstats.js index 461ae727f..1d3e27d0a 100644 --- a/modules/exstats.js +++ b/modules/exstats.js @@ -93,6 +93,16 @@ var state = { // list of active stats (indexed by ID) var stats = {}; +const DATA_FILE = "exstats.json"; +// Load the state from a saved file if there was one +state = Object.assign(state, require("Storage").readJSON(DATA_FILE,1)||{}); +// force step history to a uint8array +state.stepHistory = new Uint8Array(state.stepHistory); +// when we exit, write the current state +E.on('kill', function() { + require("Storage").writeJSON(DATA_FILE, state); +}); + // distance between 2 lat and lons, in meters, Mean Earth Radius = 6371km // https://www.movable-type.co.uk/scripts/latlong.html // (Equirectangular approximation) @@ -359,9 +369,10 @@ exports.getStats = function(statIDs, options) { state.notify.time.next = state.startTime + options.notify.time.increment; } } - reset(); + if (!state.active) reset(); // we might already be active return { - stats : stats, state : state, + stats : stats, + state : state, start : function() { state.active = true; reset();