Skip to content

Commit

Permalink
Move the "updatedPreference" event listener registration
Browse files Browse the repository at this point in the history
This patch fixes a situation that'll probably never happen, but nonetheless seems like something that we should address.
Currently the "updatedPreference" listener isn't registered *until after* the preferences have been read and initialized, which leaves a very short window of time where a preference change could theoretically be skipped.
  • Loading branch information
Snuffleupagus committed Jul 6, 2024
1 parent db91156 commit 9e352a8
Showing 1 changed file with 5 additions and 7 deletions.
12 changes: 5 additions & 7 deletions web/preferences.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,16 +67,13 @@ class BasePreferences {
typeof prefVal === typeof val ? prefVal : val;
}
AppOptions.setAll(options, /* init = */ true);

if (typeof PDFJSDev !== "undefined" && PDFJSDev.test("MOZCENTRAL")) {
window.addEventListener("updatedPreference", evt => {
this.#updatePref(evt.detail);
});
}
}
);

if (typeof PDFJSDev !== "undefined" && PDFJSDev.test("MOZCENTRAL")) {
window.addEventListener("updatedPreference", evt => {
this.#updatePref(evt.detail);
});
this.eventBus = null;
}
}
Expand All @@ -101,10 +98,11 @@ class BasePreferences {
throw new Error("Not implemented: _readFromStorage");
}

#updatePref({ name, value }) {
async #updatePref({ name, value }) {
if (typeof PDFJSDev === "undefined" || !PDFJSDev.test("MOZCENTRAL")) {
throw new Error("Not implemented: #updatePref");
}
await this.#initializedPromise;

if (name in this.#browserDefaults) {
if (typeof value !== typeof this.#browserDefaults[name]) {
Expand Down

0 comments on commit 9e352a8

Please sign in to comment.