Merge pull request #16045 from Snuffleupagus/viewer-initializeOptions

Slightly re-factor preferences/options initialization in the viewer
This commit is contained in:
Tim van der Meij 2023-02-11 19:01:31 +01:00 committed by GitHub
commit 3daf4274e8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 20 additions and 21 deletions

View File

@ -233,8 +233,7 @@ const PDFViewerApplication = {
this.preferences = this.externalServices.createPreferences();
this.appConfig = appConfig;
await this._readPreferences();
await this._parseHashParameters();
await this._initializeOptions();
this._forceCssTheme();
await this._initializeL10n();
@ -267,19 +266,19 @@ const PDFViewerApplication = {
/**
* @private
*/
async _readPreferences() {
if (
typeof PDFJSDev === "undefined" ||
PDFJSDev.test("!PRODUCTION || GENERIC")
) {
async _initializeOptions() {
if (typeof PDFJSDev === "undefined" || PDFJSDev.test("GENERIC")) {
if (AppOptions.get("disablePreferences")) {
if (AppOptions.get("pdfBugEnabled")) {
await this._parseHashParams();
}
// Give custom implementations of the default viewer a simpler way to
// opt-out of having the `Preferences` override existing `AppOptions`.
return;
}
if (AppOptions._hasUserOptions()) {
console.warn(
"_readPreferences: The Preferences may override manually set AppOptions; " +
"_initializeOptions: The Preferences may override manually set AppOptions; " +
'please use the "disablePreferences"-option in order to prevent that.'
);
}
@ -287,7 +286,11 @@ const PDFViewerApplication = {
try {
AppOptions.setAll(await this.preferences.getAll());
} catch (reason) {
console.error(`_readPreferences: "${reason?.message}".`);
console.error(`_initializeOptions: "${reason.message}".`);
}
if (AppOptions.get("pdfBugEnabled")) {
await this._parseHashParams();
}
},
@ -295,10 +298,7 @@ const PDFViewerApplication = {
* Potentially parse special debugging flags in the hash section of the URL.
* @private
*/
async _parseHashParameters() {
if (!AppOptions.get("pdfBugEnabled")) {
return;
}
async _parseHashParams() {
const hash = document.location.hash.substring(1);
if (!hash) {
return;
@ -315,7 +315,7 @@ const PDFViewerApplication = {
try {
await loadFakeWorker();
} catch (ex) {
console.error(`_parseHashParameters: "${ex.message}".`);
console.error(`_parseHashParams: "${ex.message}".`);
}
}
if (params.has("disablerange")) {
@ -355,7 +355,7 @@ const PDFViewerApplication = {
await loadPDFBug(this);
this._PDFBug.loadCSS();
} catch (ex) {
console.error(`_parseHashParameters: "${ex.message}".`);
console.error(`_parseHashParams: "${ex.message}".`);
}
break;
}
@ -369,7 +369,7 @@ const PDFViewerApplication = {
await loadPDFBug(this);
this._PDFBug.init({ OPS }, mainContainer, enabled);
} catch (ex) {
console.error(`_parseHashParameters: "${ex.message}".`);
console.error(`_parseHashParams: "${ex.message}".`);
}
}
// It is not possible to change locale for the (various) extension builds.

View File

@ -404,13 +404,12 @@ class AppOptions {
static remove(name) {
delete userOptions[name];
}
}
/**
* @ignore
*/
static _hasUserOptions() {
if (typeof PDFJSDev === "undefined" || PDFJSDev.test("GENERIC")) {
AppOptions._hasUserOptions = function () {
return Object.keys(userOptions).length > 0;
}
};
}
export { AppOptions, compatibilityParams, OptionKind };