From 8742e11581e77ffcce15842921a5a3c7297e9406 Mon Sep 17 00:00:00 2001 From: Rob Pilling Date: Mon, 28 Oct 2024 18:03:45 +0000 Subject: [PATCH 1/2] drained: fix not restoring when charge threshold met previously the assumption was that the `"changing"` event would be fired periodically when charging. fixes #3625 --- apps/drained/ChangeLog | 1 + apps/drained/app.js | 12 ++++-------- apps/drained/app.ts | 12 ++++-------- apps/drained/metadata.json | 2 +- 4 files changed, 10 insertions(+), 17 deletions(-) diff --git a/apps/drained/ChangeLog b/apps/drained/ChangeLog index 3767ad71ef..0667d8ff61 100644 --- a/apps/drained/ChangeLog +++ b/apps/drained/ChangeLog @@ -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 diff --git a/apps/drained/app.js b/apps/drained/app.js index deafe7d681..57acadf25d 100644 --- a/apps/drained/app.js +++ b/apps/drained/app.js @@ -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 { @@ -101,18 +101,14 @@ function drainedRestore() { load(); } var checkCharge = function () { - if (E.getBattery() < restore) { + if (!Bangle.isCharging() || E.getBattery() < restore) { draw(); return; } drainedRestore(); }; -if (Bangle.isCharging()) - checkCharge(); -Bangle.on("charging", function (charging) { - if (charging) - checkCharge(); -}); +checkCharge(); +drainedInterval = setInterval(checkCharge, interval * 60 * 1000); if (!keepStartup) { var storage = require("Storage"); for (var _i = 0, exceptions_1 = exceptions; _i < exceptions_1.length; _i++) { diff --git a/apps/drained/app.ts b/apps/drained/app.ts index a779a8660c..343fa10692 100644 --- a/apps/drained/app.ts +++ b/apps/drained/app.ts @@ -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: @@ -131,19 +131,15 @@ function drainedRestore() { // "public", to allow users to call } const checkCharge = () => { - if(E.getBattery() < restore) { + if(!Bangle.isCharging() || E.getBattery() < restore) { draw(); return; } drainedRestore(); }; -if (Bangle.isCharging()) - checkCharge(); - -Bangle.on("charging", charging => { - if(charging) checkCharge(); -}); +checkCharge(); +drainedInterval = setInterval(checkCharge, interval * 60 * 1000); if(!keepStartup){ const storage = require("Storage"); diff --git a/apps/drained/metadata.json b/apps/drained/metadata.json index a5389a91b9..eff9a331b1 100644 --- a/apps/drained/metadata.json +++ b/apps/drained/metadata.json @@ -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", From b721023daa3eea4647fe76efe81026307e6d2253 Mon Sep 17 00:00:00 2001 From: Rob Pilling Date: Tue, 29 Oct 2024 21:21:17 +0000 Subject: [PATCH 2/2] drained: only check for power-restore when charging --- apps/drained/app.js | 12 +++++++++--- apps/drained/app.ts | 13 ++++++++++--- 2 files changed, 19 insertions(+), 6 deletions(-) diff --git a/apps/drained/app.js b/apps/drained/app.js index 57acadf25d..d4cb97db84 100644 --- a/apps/drained/app.js +++ b/apps/drained/app.js @@ -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++) { diff --git a/apps/drained/app.ts b/apps/drained/app.ts index 343fa10692..fd39b11bdf 100644 --- a/apps/drained/app.ts +++ b/apps/drained/app.ts @@ -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");