From 16202c1843d313496a01c6ce3e2feff02a22439b Mon Sep 17 00:00:00 2001 From: Rob Pilling Date: Sun, 7 May 2023 09:46:22 +0100 Subject: [PATCH 01/14] drained: always check charge, regardless of boot-disable --- apps/drained/app.ts | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/apps/drained/app.ts b/apps/drained/app.ts index 9fc2665ee..22e173b46 100644 --- a/apps/drained/app.ts +++ b/apps/drained/app.ts @@ -112,16 +112,14 @@ function drainedRestore() { // "public", to allow users to call load(); // necessary after updating boot.0 } -if(disableBoot){ - const checkCharge = () => { - if(E.getBattery() < restore) return; - drainedRestore(); - }; +const checkCharge = () => { + if(E.getBattery() < restore) return; + drainedRestore(); +}; - if (Bangle.isCharging()) - checkCharge(); +if (Bangle.isCharging()) + checkCharge(); - Bangle.on("charging", charging => { - if(charging) checkCharge(); - }); -} +Bangle.on("charging", charging => { + if(charging) checkCharge(); +}); From cbc69c9275a05c6d8e0bd36d21f1e0b114350044 Mon Sep 17 00:00:00 2001 From: Rob Pilling Date: Sun, 7 May 2023 09:58:47 +0100 Subject: [PATCH 02/14] drained: better clock alignment --- apps/drained/app.ts | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/apps/drained/app.ts b/apps/drained/app.ts index 22e173b46..9111a49b4 100644 --- a/apps/drained/app.ts +++ b/apps/drained/app.ts @@ -52,6 +52,8 @@ const draw = () => { const dateStr = require("locale").date(date, 0).toUpperCase() + "\n" + require("locale").dow(date, 0).toUpperCase(); + const x2 = x + 6; + const y2 = y + 66; g.reset() .clearRect(Bangle.appRect) @@ -59,8 +61,8 @@ const draw = () => { .setFontAlign(0, 0) .drawString(timeStr, x, y) .setFont("Vector", 24) - .drawString(dateStr, x, y + 56) - .drawString(`${E.getBattery()}%`, x, y + 104); + .drawString(dateStr, x2, y2) + .drawString(`${E.getBattery()}%`, x2, y2 + 48); if(nextDraw) clearTimeout(nextDraw); nextDraw = setTimeout(() => { From 00cf120a28e6f3c476631db2df09c51862b2b640 Mon Sep 17 00:00:00 2001 From: Rob Pilling Date: Sun, 7 May 2023 10:36:31 +0100 Subject: [PATCH 03/14] drained: s/disableBoot/keepStartup/ --- apps/drained/app.ts | 4 ++-- apps/drained/boot.ts | 4 ++-- apps/drained/settings.ts | 22 ++++++++++++---------- 3 files changed, 16 insertions(+), 14 deletions(-) diff --git a/apps/drained/app.ts b/apps/drained/app.ts index 9111a49b4..14a8ad4bc 100644 --- a/apps/drained/app.ts +++ b/apps/drained/app.ts @@ -99,12 +99,12 @@ reload(); Bangle.emit("drained", E.getBattery()); // restore normal boot on charge -const { disableBoot = false, restore = 20 }: DrainedSettings +const { keepStartup = true, restore = 20 }: DrainedSettings = require("Storage").readJSON(`${app}.setting.json`, true) || {}; // re-enable normal boot code when we're above a threshold: function drainedRestore() { // "public", to allow users to call - if(disableBoot){ + if(!keepStartup){ try{ eval(require('Storage').read('bootupdate.js')); }catch(e){ diff --git a/apps/drained/boot.ts b/apps/drained/boot.ts index 4dc885c20..3675e06e6 100644 --- a/apps/drained/boot.ts +++ b/apps/drained/boot.ts @@ -1,5 +1,5 @@ { -const { battery: threshold = 5, interval = 10, disableBoot = false }: DrainedSettings +const { battery: threshold = 5, interval = 10, keepStartup = true }: DrainedSettings = require("Storage").readJSON(`drained.setting.json`, true) || {}; drainedInterval = setInterval(() => { @@ -10,7 +10,7 @@ drainedInterval = setInterval(() => { const app = "drained.app.js"; - if(disableBoot) + if(!keepStartup) require("Storage").write( ".boot0", `if(typeof __FILE__ === "undefined" || __FILE__ !== "${app}") setTimeout(load, 100, "${app}");` diff --git a/apps/drained/settings.ts b/apps/drained/settings.ts index c79e6605c..01e4be653 100644 --- a/apps/drained/settings.ts +++ b/apps/drained/settings.ts @@ -2,7 +2,7 @@ type DrainedSettings = { battery?: number, restore?: number, interval?: number, - disableBoot?: ShortBoolean, + keepStartup?: ShortBoolean, }; (back => { @@ -13,23 +13,17 @@ type DrainedSettings = { settings.battery ??= 5; settings.restore ??= 20; settings.interval ??= 10; - settings.disableBoot ??= false; + settings.keepStartup ??= true; const save = () => { storage.writeJSON(SETTINGS_FILE, settings) }; + const formatBool = (b: boolean) => b ? "On" : "Off"; + E.showMenu({ "": { "title": "Drained" }, "< Back": back, - "Keep startup code": { - value: settings.disableBoot, - format: () => settings.disableBoot ? "No" : "Yes", - onchange: () => { - settings.disableBoot = !settings.disableBoot; - save(); - }, - }, "Trigger at batt%": { value: settings.battery, min: 0, @@ -63,5 +57,13 @@ type DrainedSettings = { save(); }, }, + "Keep startup code": { + value: settings.keepStartup as boolean, + format: formatBool, + onchange: (b: boolean) => { + settings.keepStartup = b; + save(); + }, + }, }); }) satisfies SettingsFunc From dfece3994c7c71d6447fc8af28526332e5a75c7d Mon Sep 17 00:00:00 2001 From: Rob Pilling Date: Sun, 7 May 2023 10:37:03 +0100 Subject: [PATCH 04/14] drained: add settings into metadata --- apps/drained/metadata.json | 3 +++ 1 file changed, 3 insertions(+) diff --git a/apps/drained/metadata.json b/apps/drained/metadata.json index 89a069b2f..a845c4ce8 100644 --- a/apps/drained/metadata.json +++ b/apps/drained/metadata.json @@ -14,5 +14,8 @@ {"name":"drained.app.js","url":"app.js"}, {"name":"drained.settings.js","url":"settings.js"}, {"name":"drained.img","url":"app-icon.js","evaluate":true} + ], + "data": [ + {"name":"drained.setting.json"} ] } From 4d676a9e46954149099221cd2b7fe5fa4de675bc Mon Sep 17 00:00:00 2001 From: Rob Pilling Date: Sun, 7 May 2023 10:39:14 +0100 Subject: [PATCH 05/14] drained: infrastructure for boot exceptions --- apps/drained/app.ts | 2 +- apps/drained/settings.ts | 42 ++++++++++++++++++++++++++++++++++++++-- 2 files changed, 41 insertions(+), 3 deletions(-) diff --git a/apps/drained/app.ts b/apps/drained/app.ts index 14a8ad4bc..a079d36df 100644 --- a/apps/drained/app.ts +++ b/apps/drained/app.ts @@ -99,7 +99,7 @@ reload(); Bangle.emit("drained", E.getBattery()); // restore normal boot on charge -const { keepStartup = true, restore = 20 }: DrainedSettings +const { keepStartup = true, restore = 20, exceptions = ["widdst.0"] }: DrainedSettings = require("Storage").readJSON(`${app}.setting.json`, true) || {}; // re-enable normal boot code when we're above a threshold: diff --git a/apps/drained/settings.ts b/apps/drained/settings.ts index 01e4be653..d3ed528f9 100644 --- a/apps/drained/settings.ts +++ b/apps/drained/settings.ts @@ -3,6 +3,7 @@ type DrainedSettings = { restore?: number, interval?: number, keepStartup?: ShortBoolean, + exceptions?: string[], }; (back => { @@ -14,6 +15,7 @@ type DrainedSettings = { settings.restore ??= 20; settings.interval ??= 10; settings.keepStartup ??= true; + settings.exceptions ??= ["widdst.0"]; // daylight savings const save = () => { storage.writeJSON(SETTINGS_FILE, settings) @@ -21,7 +23,7 @@ type DrainedSettings = { const formatBool = (b: boolean) => b ? "On" : "Off"; - E.showMenu({ + const menu: Menu = { "": { "title": "Drained" }, "< Back": back, "Trigger at batt%": { @@ -63,7 +65,43 @@ type DrainedSettings = { onchange: (b: boolean) => { settings.keepStartup = b; save(); + updateMenu(); + E.showMenu(menu); }, }, - }); + }; + + const updateMenu = () => { + if (settings.keepStartup) { + delete menu["Startup exceptions"]; + return; + } + menu["Startup exceptions"] = () => E.showMenu(bootExceptions); + + const bootExceptions: Menu = { + "": { "title" : "Startup exceptions" }, + "< Back": () => E.showMenu(menu), + }; + + storage.list(/\.boot\.js/) + .map(name => name.replace(".boot.js", "")) + .forEach((name: string) => { + bootExceptions[name] = { + value: settings.exceptions!.indexOf(name) >= 0, + format: formatBool, + onchange: (b: boolean) => { + if (b) { + settings.exceptions!.push(name); + } else { + const i = settings.exceptions!.indexOf(name); + if (i >= 0) settings.exceptions!.splice(i, 1); + } + save(); + }, + }; + }); + }; + + updateMenu(); + E.showMenu(menu); }) satisfies SettingsFunc From c9f4fd7cc725f8ce2caacb2ad08289e8a34eca06 Mon Sep 17 00:00:00 2001 From: Rob Pilling Date: Sun, 7 May 2023 10:41:51 +0100 Subject: [PATCH 06/14] drained: load boot exceptions (e.g. dst) --- apps/drained/app.ts | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/apps/drained/app.ts b/apps/drained/app.ts index a079d36df..3adfbec02 100644 --- a/apps/drained/app.ts +++ b/apps/drained/app.ts @@ -125,3 +125,15 @@ if (Bangle.isCharging()) Bangle.on("charging", charging => { if(charging) checkCharge(); }); + +if(!keepStartup){ + const storage = require("Storage"); + for(const boot of exceptions){ + try{ + const js = storage.read(`${boot}.boot.js`); + if(js) eval(js); + }catch(e){ + console.log(`error loading boot exception "${boot}": ${e}`); + } + } +} From a5253487f11a3cbf1dc35c47e2acd60dea95c1b9 Mon Sep 17 00:00:00 2001 From: Rob Pilling Date: Sun, 7 May 2023 10:43:10 +0100 Subject: [PATCH 07/14] drained: version bump for boot exceptions --- apps/drained/ChangeLog | 1 + apps/drained/metadata.json | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/apps/drained/ChangeLog b/apps/drained/ChangeLog index 1a3bc1757..ec09a29bd 100644 --- a/apps/drained/ChangeLog +++ b/apps/drained/ChangeLog @@ -1 +1,2 @@ 0.01: New app! +0.02: Allow boot exceptions, e.g. to load DST diff --git a/apps/drained/metadata.json b/apps/drained/metadata.json index a845c4ce8..ef7bbeb23 100644 --- a/apps/drained/metadata.json +++ b/apps/drained/metadata.json @@ -1,7 +1,7 @@ { "id": "drained", "name": "Drained", - "version": "0.01", + "version": "0.02", "description": "Switches to displaying a simple clock when the battery percentage is low, and disables some peripherals", "readme": "README.md", "icon": "icon.png", From e489b26834dda62f9fc9fa1c2068e55ebdce88b6 Mon Sep 17 00:00:00 2001 From: Rob Pilling Date: Sun, 7 May 2023 10:44:04 +0100 Subject: [PATCH 08/14] drained: regenerate JS --- apps/drained/app.js | 46 +++++++++++++++++++----------- apps/drained/boot.js | 4 +-- apps/drained/settings.js | 60 ++++++++++++++++++++++++++++++++-------- 3 files changed, 80 insertions(+), 30 deletions(-) diff --git a/apps/drained/app.js b/apps/drained/app.js index f9ae04605..e27fcb1d1 100644 --- a/apps/drained/app.js +++ b/apps/drained/app.js @@ -35,14 +35,16 @@ var draw = function () { var dateStr = require("locale").date(date, 0).toUpperCase() + "\n" + require("locale").dow(date, 0).toUpperCase(); + var x2 = x + 6; + var y2 = y + 66; g.reset() .clearRect(Bangle.appRect) .setFont("Vector", 55) .setFontAlign(0, 0) .drawString(timeStr, x, y) .setFont("Vector", 24) - .drawString(dateStr, x, y + 56) - .drawString("".concat(E.getBattery(), "%"), x, y + 104); + .drawString(dateStr, x2, y2) + .drawString("".concat(E.getBattery(), "%"), x2, y2 + 48); if (nextDraw) clearTimeout(nextDraw); nextDraw = setTimeout(function () { @@ -75,9 +77,9 @@ var reload = function () { }; reload(); Bangle.emit("drained", E.getBattery()); -var _a = require("Storage").readJSON("".concat(app, ".setting.json"), true) || {}, _b = _a.disableBoot, disableBoot = _b === void 0 ? false : _b, _c = _a.restore, restore = _c === void 0 ? 20 : _c; +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; function drainedRestore() { - if (disableBoot) { + if (!keepStartup) { try { eval(require('Storage').read('bootupdate.js')); } @@ -87,16 +89,28 @@ function drainedRestore() { } load(); } -if (disableBoot) { - var checkCharge_1 = function () { - if (E.getBattery() < restore) - return; - drainedRestore(); - }; - if (Bangle.isCharging()) - checkCharge_1(); - Bangle.on("charging", function (charging) { - if (charging) - checkCharge_1(); - }); +var checkCharge = function () { + if (E.getBattery() < restore) + return; + drainedRestore(); +}; +if (Bangle.isCharging()) + checkCharge(); +Bangle.on("charging", function (charging) { + if (charging) + checkCharge(); +}); +if (!keepStartup) { + var storage = require("Storage"); + for (var _i = 0, exceptions_1 = exceptions; _i < exceptions_1.length; _i++) { + var boot = exceptions_1[_i]; + try { + var js = storage.read("".concat(boot, ".boot.js")); + if (js) + eval(js); + } + catch (e) { + console.log("error loading boot exception \"".concat(boot, "\": ").concat(e)); + } + } } diff --git a/apps/drained/boot.js b/apps/drained/boot.js index 97f405123..b71db0d92 100644 --- a/apps/drained/boot.js +++ b/apps/drained/boot.js @@ -1,12 +1,12 @@ { - var _a = require("Storage").readJSON("drained.setting.json", true) || {}, _b = _a.battery, threshold_1 = _b === void 0 ? 5 : _b, _c = _a.interval, interval = _c === void 0 ? 10 : _c, _d = _a.disableBoot, disableBoot_1 = _d === void 0 ? false : _d; + var _a = require("Storage").readJSON("drained.setting.json", true) || {}, _b = _a.battery, threshold_1 = _b === void 0 ? 5 : _b, _c = _a.interval, interval = _c === void 0 ? 10 : _c, _d = _a.keepStartup, keepStartup_1 = _d === void 0 ? true : _d; drainedInterval = setInterval(function () { if (Bangle.isCharging()) return; if (E.getBattery() > threshold_1) return; var app = "drained.app.js"; - if (disableBoot_1) + if (!keepStartup_1) require("Storage").write(".boot0", "if(typeof __FILE__ === \"undefined\" || __FILE__ !== \"".concat(app, "\") setTimeout(load, 100, \"").concat(app, "\");")); load(app); }, interval * 60 * 1000); diff --git a/apps/drained/settings.js b/apps/drained/settings.js index fe4ab9c4b..47131224c 100644 --- a/apps/drained/settings.js +++ b/apps/drained/settings.js @@ -1,26 +1,20 @@ (function (back) { - var _a, _b, _c, _d; + var _a, _b, _c, _d, _e; var SETTINGS_FILE = "drained.setting.json"; var storage = require("Storage"); var settings = storage.readJSON(SETTINGS_FILE, true) || {}; (_a = settings.battery) !== null && _a !== void 0 ? _a : (settings.battery = 5); (_b = settings.restore) !== null && _b !== void 0 ? _b : (settings.restore = 20); (_c = settings.interval) !== null && _c !== void 0 ? _c : (settings.interval = 10); - (_d = settings.disableBoot) !== null && _d !== void 0 ? _d : (settings.disableBoot = false); + (_d = settings.keepStartup) !== null && _d !== void 0 ? _d : (settings.keepStartup = true); + (_e = settings.exceptions) !== null && _e !== void 0 ? _e : (settings.exceptions = ["widdst.0"]); var save = function () { storage.writeJSON(SETTINGS_FILE, settings); }; - E.showMenu({ + var formatBool = function (b) { return b ? "On" : "Off"; }; + var menu = { "": { "title": "Drained" }, "< Back": back, - "Keep startup code": { - value: settings.disableBoot, - format: function () { return settings.disableBoot ? "No" : "Yes"; }, - onchange: function () { - settings.disableBoot = !settings.disableBoot; - save(); - }, - }, "Trigger at batt%": { value: settings.battery, min: 0, @@ -54,5 +48,47 @@ save(); }, }, - }); + "Keep startup code": { + value: settings.keepStartup, + format: formatBool, + onchange: function (b) { + settings.keepStartup = b; + save(); + updateMenu(); + E.showMenu(menu); + }, + }, + }; + var updateMenu = function () { + if (settings.keepStartup) { + delete menu["Startup exceptions"]; + return; + } + menu["Startup exceptions"] = function () { return E.showMenu(bootExceptions); }; + var bootExceptions = { + "": { "title": "Startup exceptions" }, + "< Back": function () { return E.showMenu(menu); }, + }; + storage.list(/\.boot\.js/) + .map(function (name) { return name.replace(".boot.js", ""); }) + .forEach(function (name) { + bootExceptions[name] = { + value: settings.exceptions.indexOf(name) >= 0, + format: formatBool, + onchange: function (b) { + if (b) { + settings.exceptions.push(name); + } + else { + var i = settings.exceptions.indexOf(name); + if (i >= 0) + settings.exceptions.splice(i, 1); + } + save(); + }, + }; + }); + }; + updateMenu(); + E.showMenu(menu); }); From efe023c5cb348e21d98e0a254092ba8f36c346ce Mon Sep 17 00:00:00 2001 From: Rob Pilling Date: Mon, 8 May 2023 11:07:17 +0100 Subject: [PATCH 09/14] drained: use Bangle's bool formatter --- apps/drained/settings.ts | 4 ---- 1 file changed, 4 deletions(-) diff --git a/apps/drained/settings.ts b/apps/drained/settings.ts index d3ed528f9..23d7ce18d 100644 --- a/apps/drained/settings.ts +++ b/apps/drained/settings.ts @@ -21,8 +21,6 @@ type DrainedSettings = { storage.writeJSON(SETTINGS_FILE, settings) }; - const formatBool = (b: boolean) => b ? "On" : "Off"; - const menu: Menu = { "": { "title": "Drained" }, "< Back": back, @@ -61,7 +59,6 @@ type DrainedSettings = { }, "Keep startup code": { value: settings.keepStartup as boolean, - format: formatBool, onchange: (b: boolean) => { settings.keepStartup = b; save(); @@ -88,7 +85,6 @@ type DrainedSettings = { .forEach((name: string) => { bootExceptions[name] = { value: settings.exceptions!.indexOf(name) >= 0, - format: formatBool, onchange: (b: boolean) => { if (b) { settings.exceptions!.push(name); From fe1a11e0981e8ef2573c56305efd55f36df03c92 Mon Sep 17 00:00:00 2001 From: Rob Pilling Date: Wed, 10 May 2023 21:24:47 +0100 Subject: [PATCH 10/14] drained: fix menu redraw --- apps/drained/settings.ts | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/apps/drained/settings.ts b/apps/drained/settings.ts index 23d7ce18d..f972f51a7 100644 --- a/apps/drained/settings.ts +++ b/apps/drained/settings.ts @@ -62,13 +62,15 @@ type DrainedSettings = { onchange: (b: boolean) => { settings.keepStartup = b; save(); - updateMenu(); - E.showMenu(menu); + updateAndRedraw(); }, }, }; - const updateMenu = () => { + const updateAndRedraw = () => { + // will change the menu, queue redraw: + setTimeout(() => { E.showMenu(menu) }, 10); + if (settings.keepStartup) { delete menu["Startup exceptions"]; return; @@ -98,6 +100,5 @@ type DrainedSettings = { }); }; - updateMenu(); - E.showMenu(menu); + updateAndRedraw(); }) satisfies SettingsFunc From 1f6070bafd8301ec8d333390a9a58fec2c454ba8 Mon Sep 17 00:00:00 2001 From: Rob Pilling Date: Wed, 10 May 2023 21:25:19 +0100 Subject: [PATCH 11/14] drained: regenerate JS --- apps/drained/settings.js | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/apps/drained/settings.js b/apps/drained/settings.js index 47131224c..ce72f215f 100644 --- a/apps/drained/settings.js +++ b/apps/drained/settings.js @@ -11,7 +11,6 @@ var save = function () { storage.writeJSON(SETTINGS_FILE, settings); }; - var formatBool = function (b) { return b ? "On" : "Off"; }; var menu = { "": { "title": "Drained" }, "< Back": back, @@ -50,16 +49,15 @@ }, "Keep startup code": { value: settings.keepStartup, - format: formatBool, onchange: function (b) { settings.keepStartup = b; save(); - updateMenu(); - E.showMenu(menu); + updateAndRedraw(); }, }, }; - var updateMenu = function () { + var updateAndRedraw = function () { + setTimeout(function () { E.showMenu(menu); }, 10); if (settings.keepStartup) { delete menu["Startup exceptions"]; return; @@ -74,7 +72,6 @@ .forEach(function (name) { bootExceptions[name] = { value: settings.exceptions.indexOf(name) >= 0, - format: formatBool, onchange: function (b) { if (b) { settings.exceptions.push(name); @@ -89,6 +86,5 @@ }; }); }; - updateMenu(); - E.showMenu(menu); + updateAndRedraw(); }); From 1cbda278fe248eae5b741dba372dcdbcf66903b3 Mon Sep 17 00:00:00 2001 From: Rob Pilling Date: Wed, 10 May 2023 23:23:28 +0100 Subject: [PATCH 12/14] drained: avoid polluting global scope --- apps/drained/boot.js | 10 +++++----- apps/drained/boot.ts | 4 ++-- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/apps/drained/boot.js b/apps/drained/boot.js index b71db0d92..48c1572bd 100644 --- a/apps/drained/boot.js +++ b/apps/drained/boot.js @@ -1,13 +1,13 @@ -{ - var _a = require("Storage").readJSON("drained.setting.json", true) || {}, _b = _a.battery, threshold_1 = _b === void 0 ? 5 : _b, _c = _a.interval, interval = _c === void 0 ? 10 : _c, _d = _a.keepStartup, keepStartup_1 = _d === void 0 ? true : _d; +(function () { + 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.keepStartup, keepStartup = _d === void 0 ? true : _d; drainedInterval = setInterval(function () { if (Bangle.isCharging()) return; - if (E.getBattery() > threshold_1) + if (E.getBattery() > threshold) return; var app = "drained.app.js"; - if (!keepStartup_1) + if (!keepStartup) require("Storage").write(".boot0", "if(typeof __FILE__ === \"undefined\" || __FILE__ !== \"".concat(app, "\") setTimeout(load, 100, \"").concat(app, "\");")); load(app); }, interval * 60 * 1000); -} +})(); diff --git a/apps/drained/boot.ts b/apps/drained/boot.ts index 3675e06e6..1fcb0591b 100644 --- a/apps/drained/boot.ts +++ b/apps/drained/boot.ts @@ -1,4 +1,4 @@ -{ +(() => { const { battery: threshold = 5, interval = 10, keepStartup = true }: DrainedSettings = require("Storage").readJSON(`drained.setting.json`, true) || {}; @@ -18,4 +18,4 @@ drainedInterval = setInterval(() => { load(app); }, interval * 60 * 1000); -} +})() From b4d46d5779ee43f5701e62b20d13ac1f3daf58eb Mon Sep 17 00:00:00 2001 From: Rob Pilling Date: Wed, 10 May 2023 23:26:03 +0100 Subject: [PATCH 13/14] popconlaunch: avoid polluting global scope --- apps/popconlaunch/boot.js | 54 +++++++++++++++++++-------------------- apps/popconlaunch/boot.ts | 4 +-- 2 files changed, 29 insertions(+), 29 deletions(-) diff --git a/apps/popconlaunch/boot.js b/apps/popconlaunch/boot.js index eb3f18e1b..e918fffcf 100644 --- a/apps/popconlaunch/boot.js +++ b/apps/popconlaunch/boot.js @@ -1,29 +1,29 @@ -{ - var oldRead_1 = require("Storage").readJSON; - var monthAgo_1 = Date.now() - 1000 * 86400 * 28; - var cache_1; - var ensureCache_1 = function () { - if (!cache_1) { - cache_1 = oldRead_1("popcon.cache.json", true); - if (!cache_1) - cache_1 = {}; +(function () { + var oldRead = require("Storage").readJSON; + var monthAgo = Date.now() - 1000 * 86400 * 28; + var cache; + var ensureCache = function () { + if (!cache) { + cache = oldRead("popcon.cache.json", true); + if (!cache) + cache = {}; } - return cache_1; + return cache; }; - var saveCache_1 = function (orderChanged) { - require("Storage").writeJSON("popcon.cache.json", cache_1); + var saveCache = function (orderChanged) { + require("Storage").writeJSON("popcon.cache.json", cache); if (orderChanged) { - var info = oldRead_1("popcon.info", true); + var info = oldRead("popcon.info", true); info.cacheBuster = !info.cacheBuster; require("Storage").writeJSON("popcon.info", info); } }; - var sortCache_1 = function () { - var ents = Object.values(cache_1); + var sortCache = function () { + var ents = Object.values(cache); ents.sort(function (a, b) { var n; - var am = (a.last > monthAgo_1); - var bm = (b.last > monthAgo_1); + var am = (a.last > monthAgo); + var bm = (b.last > monthAgo); n = bm - am; if (n) return n; @@ -51,31 +51,31 @@ }; require("Storage").readJSON = (function (fname, skipExceptions) { var _a; - var j = oldRead_1(fname, skipExceptions); + var j = oldRead(fname, skipExceptions); if (/\.info$/.test(fname)) { - var cache_2 = ensureCache_1(); + var cache_1 = ensureCache(); var so = void 0; - if (j.src && (so = (_a = cache_2[j.src]) === null || _a === void 0 ? void 0 : _a.sortorder) != null) + if (j.src && (so = (_a = cache_1[j.src]) === null || _a === void 0 ? void 0 : _a.sortorder) != null) j.sortorder = so; else j.sortorder = 99; } return j; }); - var oldLoad_1 = load; + var oldLoad = load; global.load = function (src) { if (src) { - var cache_3 = ensureCache_1(); - var ent = cache_3[src] || (cache_3[src] = { + var cache_2 = ensureCache(); + var ent = cache_2[src] || (cache_2[src] = { pop: 0, last: 0, sortorder: -10, }); ent.pop++; ent.last = Date.now(); - var orderChanged = sortCache_1(); - saveCache_1(orderChanged); + var orderChanged = sortCache(); + saveCache(orderChanged); } - return oldLoad_1(src); + return oldLoad(src); }; -} +})(); diff --git a/apps/popconlaunch/boot.ts b/apps/popconlaunch/boot.ts index a7ac73518..2fa101927 100644 --- a/apps/popconlaunch/boot.ts +++ b/apps/popconlaunch/boot.ts @@ -1,4 +1,4 @@ -{ +(() => { type Timestamp = number; const oldRead = require("Storage").readJSON; @@ -99,4 +99,4 @@ global.load = (src: string) => { return oldLoad(src); }; -} +})() From 2d3f4375edf7f0f93799b1cfa6b3e817851ce68b Mon Sep 17 00:00:00 2001 From: Rob Pilling Date: Wed, 10 May 2023 23:37:08 +0100 Subject: [PATCH 14/14] version bumps --- apps/drained/ChangeLog | 2 ++ apps/drained/metadata.json | 2 +- apps/popconlaunch/ChangeLog | 1 + apps/popconlaunch/metadata.json | 2 +- 4 files changed, 5 insertions(+), 2 deletions(-) diff --git a/apps/drained/ChangeLog b/apps/drained/ChangeLog index ec09a29bd..c7fd27981 100644 --- a/apps/drained/ChangeLog +++ b/apps/drained/ChangeLog @@ -1,2 +1,4 @@ 0.01: New app! 0.02: Allow boot exceptions, e.g. to load DST +0.03: Permit exceptions to load in low-power mode, e.g. daylight saving time. + Also avoid polluting global scope. diff --git a/apps/drained/metadata.json b/apps/drained/metadata.json index ef7bbeb23..6dfdac78d 100644 --- a/apps/drained/metadata.json +++ b/apps/drained/metadata.json @@ -1,7 +1,7 @@ { "id": "drained", "name": "Drained", - "version": "0.02", + "version": "0.03", "description": "Switches to displaying a simple clock when the battery percentage is low, and disables some peripherals", "readme": "README.md", "icon": "icon.png", diff --git a/apps/popconlaunch/ChangeLog b/apps/popconlaunch/ChangeLog index 8a2124e33..c430b4412 100644 --- a/apps/popconlaunch/ChangeLog +++ b/apps/popconlaunch/ChangeLog @@ -1,2 +1,3 @@ 0.01: New App! 0.02: Trim old entries from the popcon app cache +0.03: Avoid polluting global scope diff --git a/apps/popconlaunch/metadata.json b/apps/popconlaunch/metadata.json index 1acab2b6c..be3bc6a92 100644 --- a/apps/popconlaunch/metadata.json +++ b/apps/popconlaunch/metadata.json @@ -2,7 +2,7 @@ "id": "popconlaunch", "name": "Popcon Launcher", "shortName": "Popcon", - "version": "0.02", + "version": "0.03", "description": "Launcher modification - your launchers will display your favourite (popular) apps first. Overrides `readJSON`, may slow down your watch", "readme": "README.md", "icon": "app.png",