Commit f4aa77a2 authored by Kai Uwe Broulik's avatar Kai Uwe Broulik 🍇

Manually merge stored and default settings

One can pass a default Object to storage.get() which will be used for keys that don't exist.
However, it doesn't do that recursively, so when we add a new settings key for a specific module, like the
addToRecentDocuments it will not be present for anyone who already touched the extension settings.

Differential Revision: https://phabricator.kde.org/D28791
parent 3fd5dc36
......@@ -22,12 +22,29 @@ class SettingsUtils {
static get() {
return new Promise((resolve, reject) => {
SettingsUtils.storage().get(DEFAULT_EXTENSION_SETTINGS, (items) => {
SettingsUtils.storage().get(null /* get all */, (items) => {
const error = chrome.runtime.lastError;
if (error) {
return reject(error);
}
// Passing a default Object get() only returns defaults for the top level of the object,
// so we need to merge the level underneath manually.
const addObjectInto = (obj, add) => {
if (typeof add !== "object" || Array.isArray(add)) {
return;
}
Object.keys(add).forEach((key) => {
if (obj.hasOwnProperty(key)) {
addObjectInto(obj[key], add[key]);
} else {
obj[key] = add[key];
}
});
};
addObjectInto(items, DEFAULT_EXTENSION_SETTINGS);
resolve(items);
});
});
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment