diff --git a/apps/drained/README.md b/apps/drained/README.md index da3f16ef8..3ddee5907 100644 --- a/apps/drained/README.md +++ b/apps/drained/README.md @@ -20,6 +20,7 @@ With this app installed, your Bangle will automatically switch into low power mo ## Features - [x] Wake on twist -> off (#2502) +- [x] Emit `"drained"` event # Creator diff --git a/apps/drained/app.js b/apps/drained/app.js index ef1a00db0..529d51639 100644 --- a/apps/drained/app.js +++ b/apps/drained/app.js @@ -57,3 +57,4 @@ Bangle.setUI({ Bangle.CLOCK = 1; g.clear(); draw(); +Bangle.emit("drained", E.getBattery()); diff --git a/apps/drained/app.ts b/apps/drained/app.ts index 65966ed6e..a7b53d2b8 100644 --- a/apps/drained/app.ts +++ b/apps/drained/app.ts @@ -76,3 +76,6 @@ Bangle.CLOCK=1; g.clear(); draw(); + +// permit other apps to put themselves into low-power mode +Bangle.emit("drained", E.getBattery()); diff --git a/apps/drained/boot.js b/apps/drained/boot.js index a02b20e4f..9ed524b7f 100644 --- a/apps/drained/boot.js +++ b/apps/drained/boot.js @@ -1,16 +1,16 @@ "use strict"; -var _a = require("Storage").readJSON("drained.setting.json", true) || {}, _b = _a.battery, battery = _b === void 0 ? 5 : _b, _c = _a.interval, interval = _c === void 0 ? 10 : _c, _d = _a.disableBoot, disableBoot = _d === void 0 ? false : _d; -if (disableBoot) { - require("Storage").erase(".boot0"); - Bangle.on("charging", function (charging) { - if (charging) - eval(require('Storage').read('bootupdate.js')); - }); -} +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() > battery) + 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); diff --git a/apps/drained/boot.ts b/apps/drained/boot.ts index faedd3153..46c6811fd 100644 --- a/apps/drained/boot.ts +++ b/apps/drained/boot.ts @@ -1,20 +1,20 @@ -const { battery = 5, interval = 10, disableBoot = false }: DrainedSettings +const { battery: threshold = 5, interval = 10, disableBoot = false }: DrainedSettings = require("Storage").readJSON(`drained.setting.json`, true) || {}; -if(disableBoot){ - require("Storage").erase(".boot0"); - - Bangle.on("charging", charging => { - if (charging) - eval(require('Storage').read('bootupdate.js')); - }); -} - drainedInterval = setInterval(() => { if(Bangle.isCharging()) return; - if(E.getBattery() > battery) + if(E.getBattery() > threshold) return; + 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);