mirror of
https://github.com/AvengeMedia/DankMaterialShell.git
synced 2026-10-27 21:47:50 -04:00
30 lines
873 B
JavaScript
30 lines
873 B
JavaScript
.pragma library
|
|
.import "SettingsSpec.js" as SpecModule
|
|
|
|
function parse(text, warn) {
|
|
const settings = {};
|
|
if (!text)
|
|
return settings;
|
|
let policy;
|
|
try {
|
|
policy = JSON.parse(text);
|
|
} catch (e) {
|
|
warn("Ignoring unreadable managed settings:", e.message);
|
|
return settings;
|
|
}
|
|
for (const key in policy) {
|
|
const spec = SpecModule.SPEC[key];
|
|
if (!spec || spec.persist === false) {
|
|
warn("Ignoring managed setting that does not exist:", key);
|
|
continue;
|
|
}
|
|
const value = policy[key];
|
|
if (typeof value !== typeof spec.def || Array.isArray(value) !== Array.isArray(spec.def)) {
|
|
warn("Ignoring managed setting of the wrong type:", key, JSON.stringify(value));
|
|
continue;
|
|
}
|
|
settings[key] = value;
|
|
}
|
|
return settings;
|
|
}
|