From 9a0c31c56d41912074ba41ca034baeb7cdf17b12 Mon Sep 17 00:00:00 2001 From: Salim Blume Date: Thu, 24 Mar 2022 22:19:11 -0500 Subject: [PATCH] Fix run notifications bugs and improve accuracy --- apps/recorder/ChangeLog | 1 + apps/recorder/metadata.json | 2 +- apps/recorder/widget.js | 3 +-- apps/run/ChangeLog | 1 + apps/run/app.js | 4 ++-- apps/run/metadata.json | 2 +- apps/run/settings.js | 12 ++++++------ modules/exstats.js | 12 +++++++----- 8 files changed, 20 insertions(+), 17 deletions(-) diff --git a/apps/recorder/ChangeLog b/apps/recorder/ChangeLog index 90937e160..e9877808c 100644 --- a/apps/recorder/ChangeLog +++ b/apps/recorder/ChangeLog @@ -17,3 +17,4 @@ 0.11: Fix KML and GPX export when there is no GPS data 0.12: Fix 'Back' label positioning on track/graph display, make translateable 0.13: Fix for when widget is used before app +0.14: Remove unneeded variable assignment \ No newline at end of file diff --git a/apps/recorder/metadata.json b/apps/recorder/metadata.json index e2400603d..d715af38d 100644 --- a/apps/recorder/metadata.json +++ b/apps/recorder/metadata.json @@ -2,7 +2,7 @@ "id": "recorder", "name": "Recorder", "shortName": "Recorder", - "version": "0.13", + "version": "0.14", "description": "Record GPS position, heart rate and more in the background, then download to your PC.", "icon": "app.png", "tags": "tool,outdoors,gps,widget", diff --git a/apps/recorder/widget.js b/apps/recorder/widget.js index 221bc6c1a..4a105754b 100644 --- a/apps/recorder/widget.js +++ b/apps/recorder/widget.js @@ -248,7 +248,7 @@ } var buttons={Yes:"yes",No:"no"}; if (newFileName) buttons["New"] = "new"; - var prompt = E.showPrompt("Overwrite\nLog " + settings.file.match(/\d+/)[0] + "?",{title:"Recorder",buttons:buttons}).then(selection=>{ + return E.showPrompt("Overwrite\nLog " + settings.file.match(/\d+/)[0] + "?",{title:"Recorder",buttons:buttons}).then(selection=>{ if (selection==="no") return false; // just cancel if (selection==="yes") { require("Storage").open(settings.file,"r").erase(); @@ -259,7 +259,6 @@ } return WIDGETS["recorder"].setRecording(1); }); - return prompt; } settings.recording = isOn; updateSettings(settings); diff --git a/apps/run/ChangeLog b/apps/run/ChangeLog index 401a68de9..46fdb7e7e 100644 --- a/apps/run/ChangeLog +++ b/apps/run/ChangeLog @@ -9,3 +9,4 @@ 0.08: Added support for notifications from exstats. Support all stats from exstats 0.09: Fix broken start/stop if recording not enabled (fix #1561) 0.10: Don't allow the same setting to be chosen for 2 boxes (fix #1578) +0.11: Notifications fixes \ No newline at end of file diff --git a/apps/run/app.js b/apps/run/app.js index d066c8b1f..fb8158e58 100644 --- a/apps/run/app.js +++ b/apps/run/app.js @@ -59,7 +59,7 @@ function onStartStop() { layout.render(); }) ); - } else { + } else if (!settings.record && WIDGETS["recorder"]) { prepPromises.push( WIDGETS["recorder"].setRecording(false) ); @@ -124,7 +124,7 @@ function configureNotification(stat) { } Object.keys(settings.notify).forEach((statType) => { - if (settings.notify[statType].increment > 0) { + if (settings.notify[statType].increment > 0 && exs.stats[statType]) { configureNotification(exs.stats[statType]); } }); diff --git a/apps/run/metadata.json b/apps/run/metadata.json index 51239d297..09e5a3bed 100644 --- a/apps/run/metadata.json +++ b/apps/run/metadata.json @@ -1,6 +1,6 @@ { "id": "run", "name": "Run", - "version":"0.10", + "version":"0.11", "description": "Displays distance, time, steps, cadence, pace and more for runners.", "icon": "app.png", "tags": "run,running,fitness,outdoors,gps", diff --git a/apps/run/settings.js b/apps/run/settings.js index 949f7a235..6a7d169c4 100644 --- a/apps/run/settings.js +++ b/apps/run/settings.js @@ -90,8 +90,8 @@ [[300, 1],[300, 0],[300, 1],[300, 0],[300, 1]], ]; notificationsMenu[/*LANG*/"Dist Pattern"] = { - value: Math.max(0,vibPatterns.findIndex((p) => JSON.stringify(p) === JSON.stringify(settings.notify.dist.notifications))), - min: 0, max: vibPatterns.length, + value: Math.max(0,vibTimes.findIndex((p) => JSON.stringify(p) === JSON.stringify(settings.notify.dist.notifications))), + min: 0, max: vibTimes.length, format: v => vibPatterns[v]||/*LANG*/"Off", onchange: v => { settings.notify.dist.notifications = vibTimes[v]; @@ -100,8 +100,8 @@ } } notificationsMenu[/*LANG*/"Step Pattern"] = { - value: Math.max(0,vibPatterns.findIndex((p) => JSON.stringify(p) === JSON.stringify(settings.notify.step.notifications))), - min: 0, max: vibPatterns.length, + value: Math.max(0,vibTimes.findIndex((p) => JSON.stringify(p) === JSON.stringify(settings.notify.step.notifications))), + min: 0, max: vibTimes.length, format: v => vibPatterns[v]||/*LANG*/"Off", onchange: v => { settings.notify.step.notifications = vibTimes[v]; @@ -110,8 +110,8 @@ } } notificationsMenu[/*LANG*/"Time Pattern"] = { - value: Math.max(0,vibPatterns.findIndex((p) => JSON.stringify(p) === JSON.stringify(settings.notify.time.notifications))), - min: 0, max: vibPatterns.length, + value: Math.max(0,vibTimes.findIndex((p) => JSON.stringify(p) === JSON.stringify(settings.notify.time.notifications))), + min: 0, max: vibTimes.length, format: v => vibPatterns[v]||/*LANG*/"Off", onchange: v => { settings.notify.time.notifications = vibTimes[v]; diff --git a/modules/exstats.js b/modules/exstats.js index b106622d0..ec0a838a7 100644 --- a/modules/exstats.js +++ b/modules/exstats.js @@ -139,9 +139,9 @@ Bangle.on("GPS", function(fix) { if (stats["pacea"]) stats["pacea"].emit("changed",stats["pacea"]); if (stats["pacec"]) stats["pacec"].emit("changed",stats["pacec"]); if (stats["speed"]) stats["speed"].emit("changed",stats["speed"]); - if (state.notify.dist.increment > 0 && state.notify.dist.next <= stats["dist"]) { + if (state.notify.dist.increment > 0 && state.notify.dist.next <= state.distance) { stats["dist"].emit("notify",stats["dist"]); - state.notify.dist.next = stats["dist"] + state.notify.dist.increment; + state.notify.dist.next = state.notify.dist.next + state.notify.dist.increment; } }); @@ -152,7 +152,7 @@ Bangle.on("step", function(steps) { state.lastStepCount = steps; if (state.notify.step.increment > 0 && state.notify.step.next <= steps) { stats["step"].emit("notify",stats["step"]); - state.notify.step.next = steps + state.notify.step.increment; + state.notify.step.next = state.notify.step.next + state.notify.step.increment; } }); Bangle.on("HRM", function(h) { @@ -285,7 +285,7 @@ exports.getStats = function(statIDs, options) { } if (state.notify.time.increment > 0 && state.notify.time.next <= now) { stats["time"].emit("notify",stats["time"]); - state.notify.time.next = now + state.notify.time.increment; + state.notify.time.next = state.notify.time.next + state.notify.time.increment; } }, 1000); function reset() { @@ -299,6 +299,8 @@ exports.getStats = function(statIDs, options) { state.curSpeed = 0; state.BPM = 0; state.BPMage = 0; + state.thisGPS = {}; + state.lastGPS = {}; state.notify = options.notify; if (options.notify.dist.increment > 0) { state.notify.dist.next = state.distance + options.notify.dist.increment; @@ -338,7 +340,7 @@ exports.appendMenuItems = function(menu, settings, saveSettings) { } exports.appendNotifyMenuItems = function(menu, settings, saveSettings) { var distNames = ['Off', "1000m","1 mile","1/2 Mthn", "Marathon",]; - var distAmts = [0, 1000,1609,21098,42195]; + var distAmts = [0, 1000, 1609, 21098, 42195]; menu['Ntfy Dist'] = { min: 0, max: distNames.length-1, value: Math.max(distAmts.indexOf(settings.notify.dist.increment),0),