From ea5acf0b12c978b0fadc4691a1347a02af5bd569 Mon Sep 17 00:00:00 2001 From: Rob Pilling Date: Thu, 13 Apr 2023 18:38:39 +0100 Subject: [PATCH] drained: rearrange disabling/enabling bootcode --- apps/drained/app.js | 7 +++++++ apps/drained/app.ts | 11 +++++++++++ apps/drained/boot.js | 27 ++++++++++++--------------- apps/drained/boot.ts | 10 +++------- 4 files changed, 33 insertions(+), 22 deletions(-) diff --git a/apps/drained/app.js b/apps/drained/app.js index 529d51639..133d5e192 100644 --- a/apps/drained/app.js +++ b/apps/drained/app.js @@ -58,3 +58,10 @@ Bangle.CLOCK = 1; g.clear(); draw(); Bangle.emit("drained", E.getBattery()); +var _a = (require("Storage").readJSON("".concat(app, ".setting.json"), true) || {}).disableBoot, disableBoot = _a === void 0 ? false : _a; +if (disableBoot) { + Bangle.on("charging", function (charging) { + if (charging) + eval(require('Storage').read('bootupdate.js')); + }); +} diff --git a/apps/drained/app.ts b/apps/drained/app.ts index a7b53d2b8..14fa3e378 100644 --- a/apps/drained/app.ts +++ b/apps/drained/app.ts @@ -79,3 +79,14 @@ draw(); // permit other apps to put themselves into low-power mode Bangle.emit("drained", E.getBattery()); + +// restore normal boot on charge +const { disableBoot = false }: DrainedSettings + = require("Storage").readJSON(`${app}.setting.json`, true) || {}; + +if(disableBoot){ + Bangle.on("charging", charging => { + if (charging) + eval(require('Storage').read('bootupdate.js')); + }); +} diff --git a/apps/drained/boot.js b/apps/drained/boot.js index 9ed524b7f..d1c64780b 100644 --- a/apps/drained/boot.js +++ b/apps/drained/boot.js @@ -1,16 +1,13 @@ "use strict"; -var _a = require("Storage").readJSON("drained.setting.json", true) || {}, _b = _a.battery, threshold = _b === void 0 ? 5 : _b, _c = _a.interval, interval = _c === void 0 ? 10 : _c, _d = _a.disableBoot, disableBoot = _d === void 0 ? false : _d; -drainedInterval = setInterval(function () { - if (Bangle.isCharging()) - return; - if (E.getBattery() > threshold) - return; - if (disableBoot) { - require("Storage").erase(".boot0"); - Bangle.on("charging", function (charging) { - if (charging) - eval(require('Storage').read('bootupdate.js')); - }); - } - load("drained.app.js"); -}, interval * 60 * 1000); +{ + var _a = require("Storage").readJSON("drained.setting.json", true) || {}, _b = _a.battery, threshold_1 = _b === void 0 ? 5 : _b, _c = _a.interval, interval = _c === void 0 ? 10 : _c, _d = _a.disableBoot, disableBoot_1 = _d === void 0 ? false : _d; + drainedInterval = setInterval(function () { + if (Bangle.isCharging()) + return; + if (E.getBattery() > threshold_1) + return; + if (disableBoot_1) + require("Storage").erase(".boot0"); + load("drained.app.js"); + }, interval * 60 * 1000); +} diff --git a/apps/drained/boot.ts b/apps/drained/boot.ts index 46c6811fd..c269bf08a 100644 --- a/apps/drained/boot.ts +++ b/apps/drained/boot.ts @@ -1,3 +1,4 @@ +{ const { battery: threshold = 5, interval = 10, disableBoot = false }: DrainedSettings = require("Storage").readJSON(`drained.setting.json`, true) || {}; @@ -7,14 +8,9 @@ drainedInterval = setInterval(() => { if(E.getBattery() > threshold) return; - if(disableBoot){ + if(disableBoot) require("Storage").erase(".boot0"); - Bangle.on("charging", charging => { - if (charging) - eval(require('Storage').read('bootupdate.js')); - }); - } - load("drained.app.js"); }, interval * 60 * 1000); +}