drained: regenerate JS

master
Rob Pilling 2023-05-07 10:44:04 +01:00
parent a5253487f1
commit e489b26834
3 changed files with 80 additions and 30 deletions

View File

@ -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 () {
var checkCharge = function () {
if (E.getBattery() < restore)
return;
drainedRestore();
};
if (Bangle.isCharging())
checkCharge_1();
checkCharge();
Bangle.on("charging", function (charging) {
if (charging)
checkCharge_1();
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));
}
}
}

View File

@ -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);

View File

@ -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);
});