drained: emit "drained" event

pull/2684/head
Rob Pilling 2023-04-13 18:30:49 +01:00
parent ab75d5b353
commit 80a77772e8
5 changed files with 25 additions and 20 deletions

View File

@ -20,6 +20,7 @@ With this app installed, your Bangle will automatically switch into low power mo
## Features ## Features
- [x] Wake on twist -> off (#2502) - [x] Wake on twist -> off (#2502)
- [x] Emit `"drained"` event
# Creator # Creator

View File

@ -57,3 +57,4 @@ Bangle.setUI({
Bangle.CLOCK = 1; Bangle.CLOCK = 1;
g.clear(); g.clear();
draw(); draw();
Bangle.emit("drained", E.getBattery());

View File

@ -76,3 +76,6 @@ Bangle.CLOCK=1;
g.clear(); g.clear();
draw(); draw();
// permit other apps to put themselves into low-power mode
Bangle.emit("drained", E.getBattery());

View File

@ -1,5 +1,10 @@
"use strict"; "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; 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) { if (disableBoot) {
require("Storage").erase(".boot0"); require("Storage").erase(".boot0");
Bangle.on("charging", function (charging) { Bangle.on("charging", function (charging) {
@ -7,10 +12,5 @@ if (disableBoot) {
eval(require('Storage').read('bootupdate.js')); eval(require('Storage').read('bootupdate.js'));
}); });
} }
drainedInterval = setInterval(function () {
if (Bangle.isCharging())
return;
if (E.getBattery() > battery)
return;
load("drained.app.js"); load("drained.app.js");
}, interval * 60 * 1000); }, interval * 60 * 1000);

View File

@ -1,6 +1,12 @@
const { battery = 5, interval = 10, disableBoot = false }: DrainedSettings const { battery: threshold = 5, interval = 10, disableBoot = false }: DrainedSettings
= require("Storage").readJSON(`drained.setting.json`, true) || {}; = require("Storage").readJSON(`drained.setting.json`, true) || {};
drainedInterval = setInterval(() => {
if(Bangle.isCharging())
return;
if(E.getBattery() > threshold)
return;
if(disableBoot){ if(disableBoot){
require("Storage").erase(".boot0"); require("Storage").erase(".boot0");
@ -10,11 +16,5 @@ if(disableBoot){
}); });
} }
drainedInterval = setInterval(() => {
if(Bangle.isCharging())
return;
if(E.getBattery() > battery)
return;
load("drained.app.js"); load("drained.app.js");
}, interval * 60 * 1000); }, interval * 60 * 1000);