Skip to content

Commit

Permalink
drained: only check for power-restore when charging
Browse files Browse the repository at this point in the history
  • Loading branch information
bobrippling committed Oct 29, 2024
1 parent 8742e11 commit b721023
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 6 deletions.
12 changes: 9 additions & 3 deletions apps/drained/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,14 +101,20 @@ function drainedRestore() {
load();
}
var checkCharge = function () {
if (!Bangle.isCharging() || E.getBattery() < restore) {
if (E.getBattery() < restore) {
draw();
return;
}
drainedRestore();
};
checkCharge();
drainedInterval = setInterval(checkCharge, interval * 60 * 1000);
if (Bangle.isCharging())
checkCharge();
Bangle.on("charging", function (charging) {
if (drainedInterval)
drainedInterval = clearInterval(drainedInterval);
if (charging)
drainedInterval = setInterval(checkCharge, interval * 60 * 1000);
});
if (!keepStartup) {
var storage = require("Storage");
for (var _i = 0, exceptions_1 = exceptions; _i < exceptions_1.length; _i++) {
Expand Down
13 changes: 10 additions & 3 deletions apps/drained/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -131,15 +131,22 @@ function drainedRestore() { // "public", to allow users to call
}

const checkCharge = () => {
if(!Bangle.isCharging() || E.getBattery() < restore) {
if(E.getBattery() < restore) {
draw();
return;
}
drainedRestore();
};

checkCharge();
drainedInterval = setInterval(checkCharge, interval * 60 * 1000);
if (Bangle.isCharging())
checkCharge();

Bangle.on("charging", charging => {
if(drainedInterval)
drainedInterval = clearInterval(drainedInterval) as undefined;
if(charging)
drainedInterval = setInterval(checkCharge, interval * 60 * 1000);
});

if(!keepStartup){
const storage = require("Storage");
Expand Down

0 comments on commit b721023

Please sign in to comment.