wid_edit - Wrap loadWidgets instead of replacing it

master
Martin Boonk 2022-10-27 21:27:02 +02:00
parent 5c110a89fb
commit 3462b36f9c
1 changed files with 8 additions and 12 deletions

View File

@ -1,18 +1,14 @@
Bangle.loadWidgets = function() { Bangle.loadWidgets = (o => ()=>{
global.WIDGETS={}; o();
require("Storage").list(/\.wid\.js$/) const s = require("Storage").readJSON("wid_edit.json", 1) || {};
.forEach(w=>{ const c = s.custom || {};
try { eval(require("Storage").read(w)); }
catch (e) { print(w, e); }
});
const s = require("Storage").readJSON("wid_edit.json", 1) || {},
c = s.custom || {};
for (const w in c){ for (const w in c){
if (!(w in WIDGETS)) continue; // widget no longer exists if (!(w in WIDGETS)) continue; // widget no longer exists
// store defaults of customized values in _WIDGETS // store defaults of customized values in _WIDGETS
global._WIDGETS=global._WIDGETS||{}; if (!global._WIDGETS) global._WIDGETS = {};
_WIDGETS[w] = {}; if (!global._WIDGETS[w]) global._WIDGETS[w] = {};
Object.keys(c[w]).forEach(k => _WIDGETS[w][k] = WIDGETS[w][k]); Object.keys(c[w]).forEach(k => _WIDGETS[w][k] = WIDGETS[w][k]);
//overide values in widget with configured ones
Object.assign(WIDGETS[w], c[w]); Object.assign(WIDGETS[w], c[w]);
} }
const W = WIDGETS; const W = WIDGETS;
@ -21,4 +17,4 @@ Bangle.loadWidgets = function() {
.sort() .sort()
.sort((a, b) => (0|W[b].sortorder)-(0|W[a].sortorder)) .sort((a, b) => (0|W[b].sortorder)-(0|W[a].sortorder))
.forEach(k => WIDGETS[k] = W[k]); .forEach(k => WIDGETS[k] = W[k]);
} })(Bangle.loadWidgets);