[GENERIC viewer] Warn about AppOptions being overridden by Preferences during loading
Currently any AppOptions set using e.g. the "webviewerloaded" event listener can/will by default be overridden when the Preferences are read. To avoid that happening the "disablePreferences"-option can be used, however unless it's been explicitly set all non-default AppOptions will be silently ignored. This patch thus attempts to improve the current situation somewhat, for third-party implementations, by logging a warning in the console when this happens.
This commit is contained in:
parent
6381158855
commit
96b38f6cbd
19
web/app.js
19
web/app.js
@ -301,13 +301,20 @@ 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")
|
|
||||||
) {
|
) {
|
||||||
// Give custom implementations of the default viewer a simpler way to
|
if (AppOptions.get("disablePreferences")) {
|
||||||
// opt-out of having the `Preferences` override existing `AppOptions`.
|
// Give custom implementations of the default viewer a simpler way to
|
||||||
return;
|
// opt-out of having the `Preferences` override existing `AppOptions`.
|
||||||
|
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());
|
||||||
|
@ -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 };
|
||||||
|
Loading…
Reference in New Issue
Block a user