Skip to content

Commit 96b38f6

Browse files
committed
[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.
1 parent 6381158 commit 96b38f6

File tree

2 files changed

+20
-6
lines changed

2 files changed

+20
-6
lines changed

web/app.js

+13-6
Original file line numberDiff line numberDiff line change
@@ -301,13 +301,20 @@ const PDFViewerApplication = {
301301
*/
302302
async _readPreferences() {
303303
if (
304-
(typeof PDFJSDev === "undefined" ||
305-
PDFJSDev.test("!PRODUCTION || GENERIC")) &&
306-
AppOptions.get("disablePreferences")
304+
typeof PDFJSDev === "undefined" ||
305+
PDFJSDev.test("!PRODUCTION || GENERIC")
307306
) {
308-
// Give custom implementations of the default viewer a simpler way to
309-
// opt-out of having the `Preferences` override existing `AppOptions`.
310-
return;
307+
if (AppOptions.get("disablePreferences")) {
308+
// Give custom implementations of the default viewer a simpler way to
309+
// opt-out of having the `Preferences` override existing `AppOptions`.
310+
return;
311+
}
312+
if (AppOptions._hasUserOptions()) {
313+
console.warn(
314+
"_readPreferences: The Preferences may override manually set AppOptions; " +
315+
'please use the "disablePreferences"-option in order to prevent that.'
316+
);
317+
}
311318
}
312319
try {
313320
AppOptions.setAll(await this.preferences.getAll());

web/app_options.js

+7
Original file line numberDiff line numberDiff line change
@@ -379,6 +379,13 @@ class AppOptions {
379379
static remove(name) {
380380
delete userOptions[name];
381381
}
382+
383+
/**
384+
* @ignore
385+
*/
386+
static _hasUserOptions() {
387+
return Object.keys(userOptions).length > 0;
388+
}
382389
}
383390

384391
export { AppOptions, compatibilityParams, OptionKind };

0 commit comments

Comments
 (0)