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());
|
Bangle.emit("drained", E.getBattery());
|
||||||
|
|
||||||
// restore normal boot on charge
|
// 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) || {};
|
= require("Storage").readJSON(`${app}.setting.json`, true) || {};
|
||||||
|
|
||||||
// re-enable normal boot code when we're above a threshold:
|
// re-enable normal boot code when we're above a threshold:
|
||||||
|
|
|
@ -3,6 +3,7 @@ type DrainedSettings = {
|
||||||
restore?: number,
|
restore?: number,
|
||||||
interval?: number,
|
interval?: number,
|
||||||
keepStartup?: ShortBoolean,
|
keepStartup?: ShortBoolean,
|
||||||
|
exceptions?: string[],
|
||||||
};
|
};
|
||||||
|
|
||||||
(back => {
|
(back => {
|
||||||
|
@ -14,6 +15,7 @@ type DrainedSettings = {
|
||||||
settings.restore ??= 20;
|
settings.restore ??= 20;
|
||||||
settings.interval ??= 10;
|
settings.interval ??= 10;
|
||||||
settings.keepStartup ??= true;
|
settings.keepStartup ??= true;
|
||||||
|
settings.exceptions ??= ["widdst.0"]; // daylight savings
|
||||||
|
|
||||||
const save = () => {
|
const save = () => {
|
||||||
storage.writeJSON(SETTINGS_FILE, settings)
|
storage.writeJSON(SETTINGS_FILE, settings)
|
||||||
|
@ -21,7 +23,7 @@ type DrainedSettings = {
|
||||||
|
|
||||||
const formatBool = (b: boolean) => b ? "On" : "Off";
|
const formatBool = (b: boolean) => b ? "On" : "Off";
|
||||||
|
|
||||||
E.showMenu({
|
const menu: Menu = {
|
||||||
"": { "title": "Drained" },
|
"": { "title": "Drained" },
|
||||||
"< Back": back,
|
"< Back": back,
|
||||||
"Trigger at batt%": {
|
"Trigger at batt%": {
|
||||||
|
@ -63,7 +65,43 @@ type DrainedSettings = {
|
||||||
onchange: (b: boolean) => {
|
onchange: (b: boolean) => {
|
||||||
settings.keepStartup = b;
|
settings.keepStartup = b;
|
||||||
save();
|
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
|
}) satisfies SettingsFunc
|
||||||
|
|
Loading…
Reference in New Issue