Fix the const reassign bug (cutting edge firmware) and better indentation and scoping
parent
0cc0a40356
commit
85a52afbf5
|
|
@ -4,3 +4,4 @@
|
||||||
0.04: Obey system quiet mode
|
0.04: Obey system quiet mode
|
||||||
0.05: Battery optimisation, add the pause option, bug fixes
|
0.05: Battery optimisation, add the pause option, bug fixes
|
||||||
0.06: Add a temperature threshold to detect (and not alert) if the BJS isn't worn. Better support for the peoples using the app at night
|
0.06: Add a temperature threshold to detect (and not alert) if the BJS isn't worn. Better support for the peoples using the app at night
|
||||||
|
0.07: Fix bug on the cutting edge firmware
|
||||||
|
|
@ -1,4 +1,5 @@
|
||||||
function drawAlert() {
|
(function () {
|
||||||
|
function drawAlert() {
|
||||||
E.showPrompt("Inactivity detected", {
|
E.showPrompt("Inactivity detected", {
|
||||||
title: "Activity reminder",
|
title: "Activity reminder",
|
||||||
buttons: { "Ok": 1, "Dismiss": 2, "Pause": 3 }
|
buttons: { "Ok": 1, "Dismiss": 2, "Pause": 3 }
|
||||||
|
|
@ -21,22 +22,22 @@ function drawAlert() {
|
||||||
Bangle.buzz(400);
|
Bangle.buzz(400);
|
||||||
}
|
}
|
||||||
setTimeout(load, 20000);
|
setTimeout(load, 20000);
|
||||||
}
|
}
|
||||||
|
|
||||||
function run() {
|
function run() {
|
||||||
if (activityreminder.mustAlert(activityreminder_data, activityreminder_settings)) {
|
if (activityreminder.mustAlert(activityreminder_data, activityreminder_settings)) {
|
||||||
drawAlert();
|
drawAlert();
|
||||||
} else {
|
} else {
|
||||||
eval(storage.read("activityreminder.settings.js"))(() => load());
|
eval(storage.read("activityreminder.settings.js"))(() => load());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const activityreminder = require("activityreminder");
|
||||||
const activityreminder = require("activityreminder");
|
const storage = require("Storage");
|
||||||
const storage = require("Storage");
|
g.clear();
|
||||||
g.clear();
|
Bangle.loadWidgets();
|
||||||
Bangle.loadWidgets();
|
Bangle.drawWidgets();
|
||||||
Bangle.drawWidgets();
|
const activityreminder_settings = activityreminder.loadSettings();
|
||||||
const activityreminder_settings = activityreminder.loadSettings();
|
const activityreminder_data = activityreminder.loadData();
|
||||||
const activityreminder_data = activityreminder.loadData();
|
run();
|
||||||
run();
|
})();
|
||||||
|
|
@ -1,4 +1,5 @@
|
||||||
function run() {
|
(function () {
|
||||||
|
function run() {
|
||||||
if (isNotWorn()) return;
|
if (isNotWorn()) return;
|
||||||
let now = new Date();
|
let now = new Date();
|
||||||
let h = now.getHours();
|
let h = now.getHours();
|
||||||
|
|
@ -16,43 +17,44 @@ function run() {
|
||||||
*/
|
*/
|
||||||
}
|
}
|
||||||
|
|
||||||
if(activityreminder.mustAlert(activityreminder_data, activityreminder_settings)){
|
if (activityreminder.mustAlert(activityreminder_data, activityreminder_settings)) {
|
||||||
load('activityreminder.app.js');
|
load('activityreminder.app.js');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function isNotWorn() {
|
function isNotWorn() {
|
||||||
return (Bangle.isCharging() || activityreminder_settings.tempThreshold >= E.getTemperature());
|
return (Bangle.isCharging() || activityreminder_settings.tempThreshold >= E.getTemperature());
|
||||||
}
|
}
|
||||||
|
|
||||||
function isDuringAlertHours(h) {
|
function isDuringAlertHours(h) {
|
||||||
if(activityreminder_settings.startHour < activityreminder_settings.endHour){ // not passing through midnight
|
if (activityreminder_settings.startHour < activityreminder_settings.endHour) { // not passing through midnight
|
||||||
return (h >= activityreminder_settings.startHour && h < activityreminder_settings.endHour)
|
return (h >= activityreminder_settings.startHour && h < activityreminder_settings.endHour)
|
||||||
} else{ // passing through midnight
|
} else { // passing through midnight
|
||||||
return (h >= activityreminder_settings.startHour || h < activityreminder_settings.endHour)
|
return (h >= activityreminder_settings.startHour || h < activityreminder_settings.endHour)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Bangle.on('midnight', function() {
|
Bangle.on('midnight', function () {
|
||||||
/*
|
/*
|
||||||
Usefull trick to have the app working smothly for people using it at night
|
Usefull trick to have the app working smothly for people using it at night
|
||||||
*/
|
*/
|
||||||
let now = new Date();
|
let now = new Date();
|
||||||
let h = now.getHours();
|
let h = now.getHours();
|
||||||
if (activityreminder_settings.enabled && isDuringAlertHours(h)){
|
if (activityreminder_settings.enabled && isDuringAlertHours(h)) {
|
||||||
// updating only the steps and keeping the original stepsDate on purpose
|
// updating only the steps and keeping the original stepsDate on purpose
|
||||||
activityreminder_data.stepsOnDate = 0;
|
activityreminder_data.stepsOnDate = 0;
|
||||||
activityreminder.saveData(activityreminder_data);
|
activityreminder.saveData(activityreminder_data);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
const activityreminder = require("activityreminder");
|
|
||||||
const activityreminder_settings = activityreminder.loadSettings();
|
const activityreminder = require("activityreminder");
|
||||||
if (activityreminder_settings.enabled) {
|
const activityreminder_settings = activityreminder.loadSettings();
|
||||||
|
if (activityreminder_settings.enabled) {
|
||||||
const activityreminder_data = activityreminder.loadData();
|
const activityreminder_data = activityreminder.loadData();
|
||||||
if(activityreminder_data.firstLoad){
|
if (activityreminder_data.firstLoad) {
|
||||||
activityreminder_data.firstLoad = false;
|
activityreminder_data.firstLoad = false;
|
||||||
activityreminder.saveData(activityreminder_data);
|
activityreminder.saveData(activityreminder_data);
|
||||||
}
|
}
|
||||||
|
|
@ -61,5 +63,5 @@ if (activityreminder_settings.enabled) {
|
||||||
increase setInterval time to something that is still sensible (5 mins ?)
|
increase setInterval time to something that is still sensible (5 mins ?)
|
||||||
when we added a settimer
|
when we added a settimer
|
||||||
*/
|
*/
|
||||||
}
|
}
|
||||||
|
})();
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,3 @@
|
||||||
const storage = require("Storage");
|
|
||||||
|
|
||||||
exports.loadSettings = function () {
|
exports.loadSettings = function () {
|
||||||
return Object.assign({
|
return Object.assign({
|
||||||
enabled: true,
|
enabled: true,
|
||||||
|
|
@ -10,15 +8,15 @@ exports.loadSettings = function () {
|
||||||
pauseDelayMin: 120,
|
pauseDelayMin: 120,
|
||||||
minSteps: 50,
|
minSteps: 50,
|
||||||
tempThreshold: 27
|
tempThreshold: 27
|
||||||
}, storage.readJSON("activityreminder.s.json", true) || {});
|
}, require("Storage").readJSON("activityreminder.s.json", true) || {});
|
||||||
};
|
};
|
||||||
|
|
||||||
exports.writeSettings = function (settings) {
|
exports.writeSettings = function (settings) {
|
||||||
storage.writeJSON("activityreminder.s.json", settings);
|
require("Storage").writeJSON("activityreminder.s.json", settings);
|
||||||
};
|
};
|
||||||
|
|
||||||
exports.saveData = function (data) {
|
exports.saveData = function (data) {
|
||||||
storage.writeJSON("activityreminder.data.json", data);
|
require("Storage").writeJSON("activityreminder.data.json", data);
|
||||||
};
|
};
|
||||||
|
|
||||||
exports.loadData = function () {
|
exports.loadData = function () {
|
||||||
|
|
@ -31,7 +29,7 @@ exports.loadData = function () {
|
||||||
dismissDate: new Date(1970),
|
dismissDate: new Date(1970),
|
||||||
pauseDate: new Date(1970),
|
pauseDate: new Date(1970),
|
||||||
},
|
},
|
||||||
storage.readJSON("activityreminder.data.json") || {});
|
require("Storage").readJSON("activityreminder.data.json") || {});
|
||||||
|
|
||||||
if(typeof(data.stepsDate) == "string")
|
if(typeof(data.stepsDate) == "string")
|
||||||
data.stepsDate = new Date(data.stepsDate);
|
data.stepsDate = new Date(data.stepsDate);
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,7 @@
|
||||||
"name": "Activity Reminder",
|
"name": "Activity Reminder",
|
||||||
"shortName":"Activity Reminder",
|
"shortName":"Activity Reminder",
|
||||||
"description": "A reminder to take short walks for the ones with a sedentary lifestyle",
|
"description": "A reminder to take short walks for the ones with a sedentary lifestyle",
|
||||||
"version":"0.06",
|
"version":"0.07",
|
||||||
"icon": "app.png",
|
"icon": "app.png",
|
||||||
"type": "app",
|
"type": "app",
|
||||||
"tags": "tool,activity",
|
"tags": "tool,activity",
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue