2023-04-13 17:38:39 +00:00
|
|
|
{
|
2023-05-07 09:36:31 +00:00
|
|
|
const { battery: threshold = 5, interval = 10, keepStartup = true }: DrainedSettings
|
2023-04-13 16:51:23 +00:00
|
|
|
= require("Storage").readJSON(`drained.setting.json`, true) || {};
|
2023-04-08 07:25:27 +00:00
|
|
|
|
2023-04-13 16:51:23 +00:00
|
|
|
drainedInterval = setInterval(() => {
|
2023-03-10 23:20:28 +00:00
|
|
|
if(Bangle.isCharging())
|
|
|
|
return;
|
2023-04-13 17:30:49 +00:00
|
|
|
if(E.getBattery() > threshold)
|
2023-03-10 23:20:28 +00:00
|
|
|
return;
|
|
|
|
|
2023-04-19 17:14:10 +00:00
|
|
|
const app = "drained.app.js";
|
|
|
|
|
2023-05-07 09:36:31 +00:00
|
|
|
if(!keepStartup)
|
2023-04-19 17:14:10 +00:00
|
|
|
require("Storage").write(
|
|
|
|
".boot0",
|
|
|
|
`if(typeof __FILE__ === "undefined" || __FILE__ !== "${app}") setTimeout(load, 100, "${app}");`
|
|
|
|
);
|
2023-04-13 17:30:49 +00:00
|
|
|
|
2023-04-19 17:14:10 +00:00
|
|
|
load(app);
|
2023-04-08 07:25:27 +00:00
|
|
|
}, interval * 60 * 1000);
|
2023-04-13 17:38:39 +00:00
|
|
|
}
|