mirror of https://github.com/espruino/BangleApps
drained: infrastructure for boot exceptions
parent
dfece3994c
commit
4d676a9e46
|
@ -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:
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue