wid_edit: clean up removed widgets in settings app instead
to keep boot code as small as possiblemaster
parent
9a8ccf0f4f
commit
d5a14cacbd
|
|
@ -7,14 +7,8 @@ Bangle.loadWidgets = function() {
|
||||||
});
|
});
|
||||||
const s = require("Storage").readJSON("wid_edit.json", 1) || {},
|
const s = require("Storage").readJSON("wid_edit.json", 1) || {},
|
||||||
c = s.custom || {};
|
c = s.custom || {};
|
||||||
let u = false; // do we need to write updated settings?
|
|
||||||
for (const w in c){
|
for (const w in c){
|
||||||
if (!(w in WIDGETS)) {
|
if (!(w in WIDGETS)) continue;
|
||||||
// widget no longer exists: remove it from settings file
|
|
||||||
delete c[w];
|
|
||||||
u = true;
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
let _W = {};
|
let _W = {};
|
||||||
// store default area/sortorder in _WIDGETS
|
// store default area/sortorder in _WIDGETS
|
||||||
if (c[w].area) _W.area = WIDGETS[w].area;
|
if (c[w].area) _W.area = WIDGETS[w].area;
|
||||||
|
|
@ -23,10 +17,6 @@ Bangle.loadWidgets = function() {
|
||||||
_WIDGETS[w] = _W;
|
_WIDGETS[w] = _W;
|
||||||
}
|
}
|
||||||
if (!Object.keys(_WIDGETS).length) delete _WIDGETS; // no need for this after all
|
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;
|
const W = WIDGETS;
|
||||||
WIDGETS = {};
|
WIDGETS = {};
|
||||||
Object.keys(W)
|
Object.keys(W)
|
||||||
|
|
|
||||||
|
|
@ -7,6 +7,19 @@
|
||||||
if (!('custom' in settings)) settings.custom = {};
|
if (!('custom' in settings)) settings.custom = {};
|
||||||
global._WIDGETS = global._WIDGETS || {};
|
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
|
* Sort & redraw all widgets
|
||||||
*/
|
*/
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue