From 00cf120a28e6f3c476631db2df09c51862b2b640 Mon Sep 17 00:00:00 2001 From: Rob Pilling Date: Sun, 7 May 2023 10:36:31 +0100 Subject: [PATCH] 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