From efb136e194b6cd22d4fe205e52ff2783a64da3c0 Mon Sep 17 00:00:00 2001 From: Salim Blume Date: Sat, 5 Mar 2022 02:59:13 -0600 Subject: [PATCH] Potential fix for time notification --- apps/run/app.js | 40 ++++++++++++++++++++++++---------------- 1 file changed, 24 insertions(+), 16 deletions(-) diff --git a/apps/run/app.js b/apps/run/app.js index 0f8969e70..bf45a196b 100644 --- a/apps/run/app.js +++ b/apps/run/app.js @@ -84,22 +84,6 @@ for (var i=0;ilayout[e.id].label = e.getString()); if (sb) sb.on('changed', e=>layout[e.id].label = e.getString()); - if (sa) sa.on('notify', (e)=>{ - settings.notify[e.id].notifications.reduce(function (promise, buzzTime) { - return promise.then(function () { - return Bangle.buzz(buzzTime); - }); - }, Promise.resolve()); - console.log(`notify from ${JSON.stringify(e)}`); - }); - if (sb) sa.on('notify', (e)=>{ - settings.notify[e.id].notifications.reduce(function (promise, buzzTime) { - return promise.then(function () { - return Bangle.buzz(buzzTime); - }); - }, Promise.resolve()); - console.log(`notify from ${JSON.stringify(e)}`); - }); } // At the bottom put time/GPS state/etc lc.push({ type:"h", filly:1, c:[ @@ -114,6 +98,30 @@ var layout = new Layout( { delete lc; layout.render(); +function configureNotification(stat) { + stat.on('notify', (e)=>{ + settings.notify[stat.id].notifications.reduce(function (promise, buzzTime) { + return promise.then(function () { + return Bangle.buzz(buzzTime); + }); + }, Promise.resolve()); + console.log(`notify from ${JSON.stringify(e)}`); + }); +} + +// TODO: Should really loop over Object.keys(settings.notify) +if (settings.notify.dist.increment > 0) { + configureNotification(exs.stats.dist); +} + +if (settings.notify.step.increment > 0) { + configureNotification(exs.stats.step); +} + +if (settings.notify.time.increment > 0) { + configureNotification(exs.stats.time); +} + // Handle GPS state change for icon Bangle.on("GPS", function(fix) { layout.gps.bgCol = fix.fix ? "#0f0" : "#f00";