Step goal reached notifications

pull/2442/head
Marco H 2023-01-03 12:41:05 +01:00
parent 1f1b8a20d5
commit 15b0876aaa
2 changed files with 33 additions and 1 deletions

View File

@ -36,6 +36,10 @@ Bangle.on("health", health => {
const DB_HEADER_LEN = 8;
const DB_FILE_LEN = DB_HEADER_LEN + DB_RECORDS_PER_MONTH*DB_RECORD_LEN;
if (health && health.steps > 0) {
handleStepGoalNotification();
}
function getRecordFN(d) {
return "health-"+d.getFullYear()+"-"+(d.getMonth()+1)+".raw";
}
@ -92,3 +96,22 @@ Bangle.on("health", health => {
health.movement /= health.movCnt;
require("Storage").write(fn, getRecordData(health), sumPos, DB_FILE_LEN);
});
function handleStepGoalNotification() {
var settings = require("Storage").readJSON("health.json",1)||{};
const steps = Bangle.getHealthStatus("day").steps;
if (settings.stepGoalNotification && settings.stepGoal > 0 && steps >= settings.stepGoal) {
const now = new Date(Date.now()).toISOString().split('T')[0]; // yyyy-mm-dd
if (!settings.stepGoalNotificationDate || settings.stepGoalNotificationDate < now) { // notification not yet shown today?
Bangle.buzz(200, 0.5);
/*LANG*/E.showPrompt("You reached your daily goal of " + settings.stepGoal + " steps!", {
/*LANG*/title: "Step goal reached!",
buttons: { "Ok": 1}
}).then(function (v) {
load();
});
settings.stepGoalNotificationDate = now;
require("Storage").writeJSON("health.json", settings);
}
}
}

View File

@ -1,7 +1,8 @@
(function (back) {
var settings = Object.assign({
hrm: 0,
stepGoal: 10000
stepGoal: 10000,
stepGoalNotification: false
}, require("Storage").readJSON("health.json", true) || {});
E.showMenu({
@ -34,6 +35,14 @@
settings.stepGoal = v;
setSettings(settings);
}
},
/*LANG*/"Step Goal Notification": {
value: "stepGoalNotification" in settings ? settings.stepGoalNotification : false,
format: () => (settings.stepGoalNotification ? 'Yes' : 'No'),
onchange: () => {
settings.stepGoalNotification = !settings.stepGoalNotification;
setSettings();
}
}
});