Slightly re-factor preferences/options initialization in the viewer
Given that the debugging hash-parameters will only be used when the `pdfBugEnabled` option is manually set[1], we can skip a *tiny* bit of asynchronicity for "regular" users. --- [1] Note that it's enabled by default in the development viewer, i.e. in `gulp server` mode.
This commit is contained in:
parent
6c158da5a8
commit
0e070c805e
27
web/app.js
27
web/app.js
@ -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,16 +266,19 @@ const PDFViewerApplication = {
|
|||||||
/**
|
/**
|
||||||
* @private
|
* @private
|
||||||
*/
|
*/
|
||||||
async _readPreferences() {
|
async _initializeOptions() {
|
||||||
if (typeof PDFJSDev === "undefined" || PDFJSDev.test("GENERIC")) {
|
if (typeof PDFJSDev === "undefined" || PDFJSDev.test("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.'
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@ -284,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();
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
@ -292,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;
|
||||||
@ -312,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")) {
|
||||||
@ -352,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;
|
||||||
}
|
}
|
||||||
@ -366,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.
|
||||||
|
Loading…
x
Reference in New Issue
Block a user