2022-01-15 17:16:48 +00:00
|
|
|
Bangle.loadWidgets = function() {
|
|
|
|
global.WIDGETS={}; global._WIDGETS={};
|
|
|
|
require("Storage").list(/\.wid\.js$/)
|
|
|
|
.forEach(widget=>{
|
|
|
|
try { eval(require("Storage").read(widget)); }
|
|
|
|
catch (e) {print(widget,e);}
|
|
|
|
});
|
2022-01-17 18:40:33 +00:00
|
|
|
const s = require("Storage").readJSON("wid_edit.json", 1) || {},
|
|
|
|
c = s.custom || {};
|
2022-01-15 17:16:48 +00:00
|
|
|
for (const w in c){
|
2022-01-17 20:02:44 +00:00
|
|
|
if (!(w in WIDGETS)) continue;
|
2022-01-17 18:36:41 +00:00
|
|
|
let _W = {};
|
|
|
|
// store default area/sortorder in _WIDGETS
|
|
|
|
if (c[w].area) _W.area = WIDGETS[w].area;
|
|
|
|
if ('sortorder' in c[w]) _W.sortorder = WIDGETS[w].sortorder;
|
|
|
|
Object.assign(WIDGETS[w], c[w]);
|
|
|
|
_WIDGETS[w] = _W;
|
2022-01-15 17:16:48 +00:00
|
|
|
}
|
2022-01-17 18:40:33 +00:00
|
|
|
if (!Object.keys(_WIDGETS).length) delete _WIDGETS; // no need for this after all
|
2022-01-15 17:16:48 +00:00
|
|
|
const W = WIDGETS;
|
|
|
|
WIDGETS = {};
|
|
|
|
Object.keys(W)
|
2022-01-17 19:35:18 +00:00
|
|
|
.sort()
|
2022-01-15 17:16:48 +00:00
|
|
|
.sort((a, b) => (0|W[b].sortorder)-(0|W[a].sortorder))
|
2022-01-17 18:36:41 +00:00
|
|
|
.forEach(k => WIDGETS[k] = W[k]);
|
2022-01-15 17:16:48 +00:00
|
|
|
}
|