1
0
Fork 0

Merge pull request #1951 from Stiralbios/master

[ActivityReminder] Bug fixes for the 2.13 cutting edge and 2.14 firmware
master
Gordon Williams 2022-06-13 08:21:59 +01:00 committed by GitHub
commit cc7b2e531e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 198 additions and 190 deletions

View File

@ -4,3 +4,4 @@
0.04: Obey system quiet mode
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.07: Fix bug on the cutting edge firmware

View File

@ -1,4 +1,11 @@
function drawAlert() {
(function () {
// load variable before defining functions cause it can trigger a ReferenceError
const activityreminder = require("activityreminder");
const storage = require("Storage");
const activityreminder_settings = activityreminder.loadSettings();
let activityreminder_data = activityreminder.loadData();
function drawAlert() {
E.showPrompt("Inactivity detected", {
title: "Activity reminder",
buttons: { "Ok": 1, "Dismiss": 2, "Pause": 3 }
@ -21,22 +28,19 @@ function drawAlert() {
Bangle.buzz(400);
}
setTimeout(load, 20000);
}
}
function run() {
function run() {
if (activityreminder.mustAlert(activityreminder_data, activityreminder_settings)) {
drawAlert();
} else {
eval(storage.read("activityreminder.settings.js"))(() => load());
}
}
}
g.clear();
Bangle.loadWidgets();
Bangle.drawWidgets();
run();
const activityreminder = require("activityreminder");
const storage = require("Storage");
g.clear();
Bangle.loadWidgets();
Bangle.drawWidgets();
const activityreminder_settings = activityreminder.loadSettings();
const activityreminder_data = activityreminder.loadData();
run();
})();

View File

@ -1,4 +1,15 @@
function run() {
(function () {
// load variable before defining functions cause it can trigger a ReferenceError
const activityreminder = require("activityreminder");
const activityreminder_settings = activityreminder.loadSettings();
let activityreminder_data = activityreminder.loadData();
if (activityreminder_data.firstLoad) {
activityreminder_data.firstLoad = false;
activityreminder.saveData(activityreminder_data);
}
function run() {
if (isNotWorn()) return;
let now = new Date();
let h = now.getHours();
@ -16,50 +27,44 @@ function run() {
*/
}
if(activityreminder.mustAlert(activityreminder_data, activityreminder_settings)){
if (activityreminder.mustAlert(activityreminder_data, activityreminder_settings)) {
load('activityreminder.app.js');
}
}
}
function isNotWorn() {
return (Bangle.isCharging() || activityreminder_settings.tempThreshold >= E.getTemperature());
}
function isDuringAlertHours(h) {
if(activityreminder_settings.startHour < activityreminder_settings.endHour){ // not passing through midnight
return (h >= activityreminder_settings.startHour && h < activityreminder_settings.endHour)
} else{ // passing through midnight
return (h >= activityreminder_settings.startHour || h < activityreminder_settings.endHour)
}
}
Bangle.on('midnight', function() {
function isNotWorn() {
return (Bangle.isCharging() || activityreminder_settings.tempThreshold >= E.getTemperature());
}
function isDuringAlertHours(h) {
if (activityreminder_settings.startHour < activityreminder_settings.endHour) { // not passing through midnight
return (h >= activityreminder_settings.startHour && h < activityreminder_settings.endHour);
} else { // passing through midnight
return (h >= activityreminder_settings.startHour || h < activityreminder_settings.endHour);
}
}
Bangle.on('midnight', function () {
/*
Usefull trick to have the app working smothly for people using it at night
*/
let now = new Date();
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
activityreminder_data.stepsOnDate = 0;
activityreminder.saveData(activityreminder_data);
}
});
});
const activityreminder = require("activityreminder");
const activityreminder_settings = activityreminder.loadSettings();
if (activityreminder_settings.enabled) {
const activityreminder_data = activityreminder.loadData();
if(activityreminder_data.firstLoad){
activityreminder_data.firstLoad = false;
activityreminder.saveData(activityreminder_data);
}
if (activityreminder_settings.enabled) {
setInterval(run, 60000);
/* todo in a futur release
increase setInterval time to something that is still sensible (5 mins ?)
when we added a settimer
*/
}
}
})();

View File

@ -1,5 +1,3 @@
const storage = require("Storage");
exports.loadSettings = function () {
return Object.assign({
enabled: true,
@ -10,20 +8,20 @@ exports.loadSettings = function () {
pauseDelayMin: 120,
minSteps: 50,
tempThreshold: 27
}, storage.readJSON("activityreminder.s.json", true) || {});
}, require("Storage").readJSON("activityreminder.s.json", true) || {});
};
exports.writeSettings = function (settings) {
storage.writeJSON("activityreminder.s.json", settings);
require("Storage").writeJSON("activityreminder.s.json", settings);
};
exports.saveData = function (data) {
storage.writeJSON("activityreminder.data.json", data);
require("Storage").writeJSON("activityreminder.data.json", data);
};
exports.loadData = function () {
let health = Bangle.getHealthStatus("day");
const data = Object.assign({
let data = Object.assign({
firstLoad: true,
stepsDate: new Date(),
stepsOnDate: health.steps,
@ -31,7 +29,7 @@ exports.loadData = function () {
dismissDate: new Date(1970),
pauseDate: new Date(1970),
},
storage.readJSON("activityreminder.data.json") || {});
require("Storage").readJSON("activityreminder.data.json") || {});
if(typeof(data.stepsDate) == "string")
data.stepsDate = new Date(data.stepsDate);

View File

@ -3,7 +3,7 @@
"name": "Activity Reminder",
"shortName":"Activity Reminder",
"description": "A reminder to take short walks for the ones with a sedentary lifestyle",
"version":"0.06",
"version":"0.07",
"icon": "app.png",
"type": "app",
"tags": "tool,activity",

View File

@ -1,7 +1,7 @@
(function (back) {
// Load settings
const activityreminder = require("activityreminder");
const settings = activityreminder.loadSettings();
let settings = activityreminder.loadSettings();
// Show the menu
E.showMenu({