[ActivityReminder] Use 2 space indent like on others apps in the repository

pull/2095/head
Stiralbios 2022-08-20 14:17:36 +02:00
parent fb7b69379a
commit 8cc79a77d0
3 changed files with 183 additions and 183 deletions

View File

@ -1,46 +1,46 @@
(function () { (function () {
// load variable before defining functions cause it can trigger a ReferenceError // load variable before defining functions cause it can trigger a ReferenceError
const activityreminder = require("activityreminder"); const activityreminder = require("activityreminder");
const storage = require("Storage"); const storage = require("Storage");
const activityreminder_settings = activityreminder.loadSettings(); const activityreminder_settings = activityreminder.loadSettings();
let activityreminder_data = activityreminder.loadData(); let activityreminder_data = activityreminder.loadData();
function drawAlert() { 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 }
}).then(function (v) { }).then(function (v) {
if (v == 1) { if (v == 1) {
activityreminder_data.okDate = new Date(); activityreminder_data.okDate = new Date();
} }
if (v == 2) { if (v == 2) {
activityreminder_data.dismissDate = new Date(); activityreminder_data.dismissDate = new Date();
} }
if (v == 3) { if (v == 3) {
activityreminder_data.pauseDate = new Date(); activityreminder_data.pauseDate = new Date();
} }
activityreminder.saveData(activityreminder_data); activityreminder.saveData(activityreminder_data);
load(); load();
}); });
// Obey system quiet mode: // Obey system quiet mode:
if (!(storage.readJSON('setting.json', 1) || {}).quiet) { if (!(storage.readJSON('setting.json', 1) || {}).quiet) {
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());
} }
} }
g.clear();
Bangle.loadWidgets();
Bangle.drawWidgets();
run();
g.clear();
Bangle.loadWidgets();
Bangle.drawWidgets();
run();
})(); })();

View File

@ -1,70 +1,70 @@
(function () { (function () {
// load variable before defining functions cause it can trigger a ReferenceError // load variable before defining functions cause it can trigger a ReferenceError
const activityreminder = require("activityreminder"); const activityreminder = require("activityreminder");
const activityreminder_settings = activityreminder.loadSettings(); const activityreminder_settings = activityreminder.loadSettings();
let activityreminder_data = activityreminder.loadData(); let activityreminder_data = activityreminder.loadData();
if (activityreminder_data.firstLoad) { if (activityreminder_data.firstLoad) {
activityreminder_data.firstLoad = false; activityreminder_data.firstLoad = false;
activityreminder.saveData(activityreminder_data);
}
function run() {
if (isNotWorn()) return;
let now = new Date();
let h = now.getHours();
if (isDuringAlertHours(h)) {
let health = Bangle.getHealthStatus("day");
if (health.steps - activityreminder_data.stepsOnDate >= activityreminder_settings.minSteps // more steps made than needed
|| health.steps < activityreminder_data.stepsOnDate) { // new day or reboot of the watch
activityreminder_data.stepsOnDate = health.steps;
activityreminder_data.stepsDate = now;
activityreminder.saveData(activityreminder_data); activityreminder.saveData(activityreminder_data);
}
function run() {
if (isNotWorn()) return;
let now = new Date();
let h = now.getHours();
if (isDuringAlertHours(h)) {
let health = Bangle.getHealthStatus("day");
if (health.steps - activityreminder_data.stepsOnDate >= activityreminder_settings.minSteps // more steps made than needed
|| health.steps < activityreminder_data.stepsOnDate) { // new day or reboot of the watch
activityreminder_data.stepsOnDate = health.steps;
activityreminder_data.stepsDate = now;
activityreminder.saveData(activityreminder_data);
/* todo in a futur release
Add settimer to trigger like 30 secs after going in this part cause the person have been walking
(pass some argument to run() to handle long walks and not triggering so often)
*/
}
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 () {
/*
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)) {
// updating only the steps and keeping the original stepsDate on purpose
activityreminder_data.stepsOnDate = 0;
activityreminder.saveData(activityreminder_data);
}
});
if (activityreminder_settings.enabled) {
setInterval(run, 60000);
/* todo in a futur release /* todo in a futur release
increase setInterval time to something that is still sensible (5 mins ?) Add settimer to trigger like 30 secs after going in this part cause the person have been walking
when we added a settimer (pass some argument to run() to handle long walks and not triggering so often)
*/ */
}
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 () {
/*
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)) {
// updating only the steps and keeping the original stepsDate on purpose
activityreminder_data.stepsOnDate = 0;
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,80 +1,80 @@
(function (back) { (function (back) {
// Load settings // Load settings
const activityreminder = require("activityreminder"); const activityreminder = require("activityreminder");
let settings = activityreminder.loadSettings(); let settings = activityreminder.loadSettings();
// Show the menu // Show the menu
E.showMenu({ E.showMenu({
"": { "title": "Activity Reminder" }, "": { "title": "Activity Reminder" },
"< Back": () => back(), "< Back": () => back(),
'Enable': { 'Enable': {
value: settings.enabled, value: settings.enabled,
onchange: v => { onchange: v => {
settings.enabled = v; settings.enabled = v;
activityreminder.writeSettings(settings); activityreminder.writeSettings(settings);
} }
}, },
'Start hour': { 'Start hour': {
value: settings.startHour, value: settings.startHour,
min: 0, max: 24, min: 0, max: 24,
onchange: v => { onchange: v => {
settings.startHour = v; settings.startHour = v;
activityreminder.writeSettings(settings); activityreminder.writeSettings(settings);
} }
}, },
'End hour': { 'End hour': {
value: settings.endHour, value: settings.endHour,
min: 0, max: 24, min: 0, max: 24,
onchange: v => { onchange: v => {
settings.endHour = v; settings.endHour = v;
activityreminder.writeSettings(settings); activityreminder.writeSettings(settings);
} }
}, },
'Max inactivity': { 'Max inactivity': {
value: settings.maxInnactivityMin, value: settings.maxInnactivityMin,
min: 15, max: 120, min: 15, max: 120,
onchange: v => { onchange: v => {
settings.maxInnactivityMin = v; settings.maxInnactivityMin = v;
activityreminder.writeSettings(settings); activityreminder.writeSettings(settings);
}, },
format: x => x + "m" format: x => x + "m"
}, },
'Dismiss delay': { 'Dismiss delay': {
value: settings.dismissDelayMin, value: settings.dismissDelayMin,
min: 5, max: 60, min: 5, max: 60,
onchange: v => { onchange: v => {
settings.dismissDelayMin = v; settings.dismissDelayMin = v;
activityreminder.writeSettings(settings); activityreminder.writeSettings(settings);
}, },
format: x => x + "m" format: x => x + "m"
}, },
'Pause delay': { 'Pause delay': {
value: settings.pauseDelayMin, value: settings.pauseDelayMin,
min: 30, max: 240, step: 5, min: 30, max: 240, step: 5,
onchange: v => { onchange: v => {
settings.pauseDelayMin = v; settings.pauseDelayMin = v;
activityreminder.writeSettings(settings); activityreminder.writeSettings(settings);
}, },
format: x => { format: x => {
return x + "m"; return x + "m";
} }
}, },
'Min steps': { 'Min steps': {
value: settings.minSteps, value: settings.minSteps,
min: 10, max: 500, step: 10, min: 10, max: 500, step: 10,
onchange: v => { onchange: v => {
settings.minSteps = v; settings.minSteps = v;
activityreminder.writeSettings(settings); activityreminder.writeSettings(settings);
} }
}, },
'Temp Threshold': { 'Temp Threshold': {
value: settings.tempThreshold, value: settings.tempThreshold,
min: 20, max: 40, step: 0.5, min: 20, max: 40, step: 0.5,
format: v => v + "°C", format: v => v + "°C",
onchange: v => { onchange: v => {
settings.tempThreshold = v; settings.tempThreshold = v;
activityreminder.writeSettings(settings); activityreminder.writeSettings(settings);
} }
} }
}); });
}) })