wid_edit: clean up removed widgets in settings app instead

to keep boot code as small as possible
pull/1303/head
Richard de Boer 2022-01-17 21:02:44 +01:00
parent 9a8ccf0f4f
commit d5a14cacbd
No known key found for this signature in database
GPG Key ID: 8721727971871937
2 changed files with 14 additions and 11 deletions

View File

@ -7,14 +7,8 @@ Bangle.loadWidgets = function() {
});
const s = require("Storage").readJSON("wid_edit.json", 1) || {},
c = s.custom || {};
let u = false; // do we need to write updated settings?
for (const w in c){
if (!(w in WIDGETS)) {
// widget no longer exists: remove it from settings file
delete c[w];
u = true;
continue;
}
if (!(w in WIDGETS)) continue;
let _W = {};
// store default area/sortorder in _WIDGETS
if (c[w].area) _W.area = WIDGETS[w].area;
@ -23,10 +17,6 @@ Bangle.loadWidgets = function() {
_WIDGETS[w] = _W;
}
if (!Object.keys(_WIDGETS).length) delete _WIDGETS; // no need for this after all
if (u) {
s.custom = c;
require("Storage").writeJSON("wid_edit.json", s);
}
const W = WIDGETS;
WIDGETS = {};
Object.keys(W)

View File

@ -7,6 +7,19 @@
if (!('custom' in settings)) settings.custom = {};
global._WIDGETS = global._WIDGETS || {};
let cleanup = false;
for (const id in settings.custom) {
if (!(id in WIDGETS)) {
// widget which no longer exists
cleanup = true;
delete settings.custom[id];
}
}
if (cleanup) {
if (!Object.keys(settings.custom).length) delete settings.custom;
require("Storage").writeJSON("wid_edit.json", settings);
}
/**
* Sort & redraw all widgets
*/