Add the possibility to change some pdfjs preferences from the viewer (bug 1908483)

This commit is contained in:
Calixte Denizet 2024-07-17 19:51:53 +02:00
parent 86eb5ba700
commit 6cc32b699f
2 changed files with 9 additions and 5 deletions

View file

@ -150,6 +150,10 @@ class Preferences extends BasePreferences {
async _readFromStorage(prefObj) { async _readFromStorage(prefObj) {
return FirefoxCom.requestAsync("getPreferences", prefObj); return FirefoxCom.requestAsync("getPreferences", prefObj);
} }
async _writeToStorage(prefObj) {
return FirefoxCom.requestAsync("setPreferences", prefObj);
}
} }
(function listenFindEvents() { (function listenFindEvents() {

View file

@ -108,14 +108,14 @@ class BasePreferences {
* provided that the preference exists and the types match. * provided that the preference exists and the types match.
*/ */
async set(name, value) { async set(name, value) {
if (typeof PDFJSDev !== "undefined" && PDFJSDev.test("MOZCENTRAL")) {
throw new Error("Please use `about:config` to change preferences.");
}
await this.#initializedPromise; await this.#initializedPromise;
AppOptions.setAll({ [name]: value }, /* prefs = */ true); AppOptions.setAll({ [name]: value }, /* prefs = */ true);
const prefs = AppOptions.getAll(OptionKind.PREFERENCE); await this._writeToStorage(
await this._writeToStorage(prefs); typeof PDFJSDev !== "undefined" && PDFJSDev.test("MOZCENTRAL")
? { [name]: AppOptions.get(name) }
: AppOptions.getAll(OptionKind.PREFERENCE)
);
} }
/** /**