BangleApps/apps/activityreminder/boot.js

63 lines
1.8 KiB
JavaScript
Raw Normal View History

2022-04-05 14:27:16 +00:00
global.activityreminder = Object.assign({
enabled: true,
startHour: 9,
endHour: 20,
maxInnactivityMin: 30,
dismissDelayMin: 15,
minSteps: 50,
}, require("Storage").readJSON("activityreminder.json", true) || {});
if (global.activityreminder) {
activityreminder =
Object.assign(activityreminder,
{
stepsArray: [],
run: function(){
var now = new Date();
var h = now.getHours();
if(h >= activityreminder.startHour && h < activityreminder.endHour)
{
var health = Bangle.getHealthStatus("day");
activityreminder.stepsArray.unshift(health.steps);
activityreminder.stepsArray = activityreminder.stepsArray.slice(0, activityreminder.maxInnactivityMin);
}
else{
activityreminder.stepsArray = [];
}
if(activityreminder.stepsArray.length == activityreminder.maxInnactivityMin){
if (activityreminder.stepsArray[0] - activityreminder.stepsArray[activityreminder.stepsArray.length-1] < activityreminder.minSteps)
{
activityreminder.showAlert();
}
}
},
showAlert: function(){
E.showPrompt("Innactivity detected",{
title:"Activity reminder",
buttons : {"Ok": true,"Dismiss": false}
}).then(function(v) {
if(v == true){
activityreminder.stepsArray = activityreminder.stepsArray.slice(0, activityreminder.maxInnactivityMin - 3);
}
if(v == false){
activityreminder.stepsArray = activityreminder.stepsArray.slice(0, activityreminder.maxInnactivityMin - activityreminder.dismissDelayMin);
}
load();
});
Bangle.buzz();
},
}
);
setInterval(global.activityreminder.run, 60000);
}