Skip to content

Commit

Permalink
Merge pull request #3626 from bobrippling/fix/drained-restore
Browse files Browse the repository at this point in the history
drained: fix not restoring when charge threshold met
  • Loading branch information
thyttan authored Oct 29, 2024
2 parents 93de0b5 + b721023 commit ed3bf8c
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 5 deletions.
1 change: 1 addition & 0 deletions apps/drained/ChangeLog
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@
0.04: Enhance menu: enable bluetooth, visit settings & visit recovery
0.05: Enhance menu: permit toggling bluetooth
0.06: Display clock in green when charging, with "charging" text
0.07: Correctly restore full power when the charged threshold is reached
6 changes: 4 additions & 2 deletions apps/drained/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ var reload = function () {
};
reload();
Bangle.emit("drained", E.getBattery());
var _a = require("Storage").readJSON("".concat(app, ".setting.json"), true) || {}, _b = _a.keepStartup, keepStartup = _b === void 0 ? true : _b, _c = _a.restore, restore = _c === void 0 ? 20 : _c, _d = _a.exceptions, exceptions = _d === void 0 ? ["widdst.0"] : _d;
var _a = require("Storage").readJSON("".concat(app, ".setting.json"), true) || {}, _b = _a.keepStartup, keepStartup = _b === void 0 ? true : _b, _c = _a.restore, restore = _c === void 0 ? 20 : _c, _d = _a.exceptions, exceptions = _d === void 0 ? ["widdst.0"] : _d, _e = _a.interval, interval = _e === void 0 ? 10 : _e;
function drainedRestore() {
if (!keepStartup) {
try {
Expand All @@ -110,8 +110,10 @@ var checkCharge = function () {
if (Bangle.isCharging())
checkCharge();
Bangle.on("charging", function (charging) {
if (drainedInterval)
drainedInterval = clearInterval(drainedInterval);
if (charging)
checkCharge();
drainedInterval = setInterval(checkCharge, interval * 60 * 1000);
});
if (!keepStartup) {
var storage = require("Storage");
Expand Down
7 changes: 5 additions & 2 deletions apps/drained/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ reload();
Bangle.emit("drained", E.getBattery());

// restore normal boot on charge
const { keepStartup = true, restore = 20, exceptions = ["widdst.0"] }: DrainedSettings
const { keepStartup = true, restore = 20, exceptions = ["widdst.0"], interval = 10 }: DrainedSettings
= require("Storage").readJSON(`${app}.setting.json`, true) || {};

// re-enable normal boot code when we're above a threshold:
Expand All @@ -142,7 +142,10 @@ if (Bangle.isCharging())
checkCharge();

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

if(!keepStartup){
Expand Down
2 changes: 1 addition & 1 deletion apps/drained/metadata.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"id": "drained",
"name": "Drained",
"version": "0.06",
"version": "0.07",
"description": "Switches to displaying a simple clock when the battery percentage is low, and disables some peripherals",
"readme": "README.md",
"icon": "icon.png",
Expand Down

0 comments on commit ed3bf8c

Please sign in to comment.