Merge pull request #14063 from Snuffleupagus/disablePreferences-warning

[GENERIC viewer] Warn about AppOptions being overridden by Preferences during loading
This commit is contained in:
Tim van der Meij 2021-09-22 22:33:40 +02:00 committed by GitHub
commit 8dc22f40c7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 20 additions and 6 deletions

View File

@ -301,14 +301,21 @@ const PDFViewerApplication = {
*/ */
async _readPreferences() { async _readPreferences() {
if ( if (
(typeof PDFJSDev === "undefined" || typeof PDFJSDev === "undefined" ||
PDFJSDev.test("!PRODUCTION || GENERIC")) && PDFJSDev.test("!PRODUCTION || GENERIC")
AppOptions.get("disablePreferences")
) { ) {
if (AppOptions.get("disablePreferences")) {
// Give custom implementations of the default viewer a simpler way to // Give custom implementations of the default viewer a simpler way to
// opt-out of having the `Preferences` override existing `AppOptions`. // opt-out of having the `Preferences` override existing `AppOptions`.
return; return;
} }
if (AppOptions._hasUserOptions()) {
console.warn(
"_readPreferences: The Preferences may override manually set AppOptions; " +
'please use the "disablePreferences"-option in order to prevent that.'
);
}
}
try { try {
AppOptions.setAll(await this.preferences.getAll()); AppOptions.setAll(await this.preferences.getAll());
} catch (reason) { } catch (reason) {

View File

@ -379,6 +379,13 @@ class AppOptions {
static remove(name) { static remove(name) {
delete userOptions[name]; delete userOptions[name];
} }
/**
* @ignore
*/
static _hasUserOptions() {
return Object.keys(userOptions).length > 0;
}
} }
export { AppOptions, compatibilityParams, OptionKind }; export { AppOptions, compatibilityParams, OptionKind };