Merge pull request #9936 from Snuffleupagus/BasePreferences-validate
Validate the Preferences when fetching them from storage
This commit is contained in:
commit
d19e13ee2e
@ -635,8 +635,6 @@ let PDFViewerApplication = {
|
|||||||
if (this.pdfLoadingTask) {
|
if (this.pdfLoadingTask) {
|
||||||
// We need to destroy already opened document.
|
// We need to destroy already opened document.
|
||||||
return this.close().then(() => {
|
return this.close().then(() => {
|
||||||
// Reload the preferences if a document was previously opened.
|
|
||||||
this.preferences.reload();
|
|
||||||
// ... and repeat the open() call.
|
// ... and repeat the open() call.
|
||||||
return this.open(file, args);
|
return this.open(file, args);
|
||||||
});
|
});
|
||||||
|
@ -60,9 +60,19 @@ class BasePreferences {
|
|||||||
|
|
||||||
this.prefs = Object.assign(Object.create(null), defaults);
|
this.prefs = Object.assign(Object.create(null), defaults);
|
||||||
return this._readFromStorage(defaults);
|
return this._readFromStorage(defaults);
|
||||||
}).then((prefObj) => {
|
}).then((prefs) => {
|
||||||
if (prefObj) {
|
if (!prefs) {
|
||||||
this.prefs = prefObj;
|
return;
|
||||||
|
}
|
||||||
|
for (let name in prefs) {
|
||||||
|
const defaultValue = this.defaults[name], prefValue = prefs[name];
|
||||||
|
// Ignore preferences not present in, or whose types don't match,
|
||||||
|
// the default values.
|
||||||
|
if (defaultValue === undefined ||
|
||||||
|
typeof prefValue !== typeof defaultValue) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
this.prefs[name] = prefValue;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -99,21 +109,6 @@ class BasePreferences {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Replace the current preference values with the ones from storage.
|
|
||||||
* @return {Promise} A promise that is resolved when the preference values
|
|
||||||
* have been updated.
|
|
||||||
*/
|
|
||||||
reload() {
|
|
||||||
return this._initializedPromise.then(() => {
|
|
||||||
return this._readFromStorage(this.defaults);
|
|
||||||
}).then((prefObj) => {
|
|
||||||
if (prefObj) {
|
|
||||||
this.prefs = prefObj;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set the value of a preference.
|
* Set the value of a preference.
|
||||||
* @param {string} name The name of the preference that should be changed.
|
* @param {string} name The name of the preference that should be changed.
|
||||||
|
Loading…
Reference in New Issue
Block a user