BangleApps/apps/wid_edit/boot.js

21 lines
854 B
JavaScript
Raw Normal View History

Bangle.loadWidgets = (o => ()=>{
o();
const s = require("Storage").readJSON("wid_edit.json", 1) || {};
const c = s.custom || {};
2022-01-15 17:16:48 +00:00
for (const w in c){
2022-01-17 20:18:02 +00:00
if (!(w in WIDGETS)) continue; // widget no longer exists
// store defaults of customized values in _WIDGETS
if (!global._WIDGETS) global._WIDGETS = {};
if (!global._WIDGETS[w]) global._WIDGETS[w] = {};
Object.keys(c[w]).forEach(k => global._WIDGETS[w][k] = global.WIDGETS[w][k]);
//overide values in widget with configured ones
Object.assign(global.WIDGETS[w], c[w]);
2022-01-15 17:16:48 +00:00
}
const W = global.WIDGETS;
global.WIDGETS = {};
2022-01-15 17:16:48 +00:00
Object.keys(W)
2023-07-31 21:04:20 +00:00
.sort() // sort alphabetically. the next sort is stable and preserves this if sortorder matches
2022-01-15 17:16:48 +00:00
.sort((a, b) => (0|W[b].sortorder)-(0|W[a].sortorder))
.forEach(k => global.WIDGETS[k] = W[k]);
})(Bangle.loadWidgets);