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.preferences = this.externalServices.createPreferences();
this.appConfig = appConfig; this.appConfig = appConfig;
await this._readPreferences(); await this._initializeOptions();
await this._parseHashParameters();
this._forceCssTheme(); this._forceCssTheme();
await this._initializeL10n(); await this._initializeL10n();
@ -267,19 +266,19 @@ const PDFViewerApplication = {
/** /**
* @private * @private
*/ */
async _readPreferences() { async _initializeOptions() {
if ( if (typeof PDFJSDev === "undefined" || PDFJSDev.test("GENERIC")) {
typeof PDFJSDev === "undefined" ||
PDFJSDev.test("!PRODUCTION || GENERIC")
) {
if (AppOptions.get("disablePreferences")) { if (AppOptions.get("disablePreferences")) {
if (AppOptions.get("pdfBugEnabled")) {
await this._parseHashParams();
}
// 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()) { if (AppOptions._hasUserOptions()) {
console.warn( 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.' 'please use the "disablePreferences"-option in order to prevent that.'
); );
} }
@ -287,7 +286,11 @@ const PDFViewerApplication = {
try { try {
AppOptions.setAll(await this.preferences.getAll()); AppOptions.setAll(await this.preferences.getAll());
} catch (reason) { } 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. * Potentially parse special debugging flags in the hash section of the URL.
* @private * @private
*/ */
async _parseHashParameters() { async _parseHashParams() {
if (!AppOptions.get("pdfBugEnabled")) {
return;
}
const hash = document.location.hash.substring(1); const hash = document.location.hash.substring(1);
if (!hash) { if (!hash) {
return; return;
@ -315,7 +315,7 @@ const PDFViewerApplication = {
try { try {
await loadFakeWorker(); await loadFakeWorker();
} catch (ex) { } catch (ex) {
console.error(`_parseHashParameters: "${ex.message}".`); console.error(`_parseHashParams: "${ex.message}".`);
} }
} }
if (params.has("disablerange")) { if (params.has("disablerange")) {
@ -355,7 +355,7 @@ const PDFViewerApplication = {
await loadPDFBug(this); await loadPDFBug(this);
this._PDFBug.loadCSS(); this._PDFBug.loadCSS();
} catch (ex) { } catch (ex) {
console.error(`_parseHashParameters: "${ex.message}".`); console.error(`_parseHashParams: "${ex.message}".`);
} }
break; break;
} }
@ -369,7 +369,7 @@ const PDFViewerApplication = {
await loadPDFBug(this); await loadPDFBug(this);
this._PDFBug.init({ OPS }, mainContainer, enabled); this._PDFBug.init({ OPS }, mainContainer, enabled);
} catch (ex) { } catch (ex) {
console.error(`_parseHashParameters: "${ex.message}".`); console.error(`_parseHashParams: "${ex.message}".`);
} }
} }
// It is not possible to change locale for the (various) extension builds. // It is not possible to change locale for the (various) extension builds.

View File

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