Remove the createPreferences
method from DefaultExternalServices
Given the simplicity of the `createPreferences` method, we can leverage import maps to directly initialize the correct `Preferences`-instance depending on the build.
This commit is contained in:
parent
1698991ae2
commit
d1080e785a
@ -281,6 +281,7 @@ function createWebpackConfig(
|
||||
"web-pdf_presentation_mode": "web/pdf_presentation_mode.js",
|
||||
"web-pdf_sidebar": "web/pdf_sidebar.js",
|
||||
"web-pdf_thumbnail_viewer": "web/pdf_thumbnail_viewer.js",
|
||||
"web-preferences": "",
|
||||
"web-print_service": "",
|
||||
"web-secondary_toolbar": "web/secondary_toolbar.js",
|
||||
"web-toolbar": "web/toolbar.js",
|
||||
@ -291,6 +292,7 @@ function createWebpackConfig(
|
||||
|
||||
viewerAlias["web-com"] = "web/chromecom.js";
|
||||
viewerAlias["web-download_manager"] = "web/download_manager.js";
|
||||
viewerAlias["web-preferences"] = "web/chromecom.js";
|
||||
viewerAlias["web-print_service"] = "web/pdf_print_service.js";
|
||||
} else if (bundleDefines.GENERIC) {
|
||||
// Aliases defined here must also be replicated in the paths section of
|
||||
@ -304,6 +306,7 @@ function createWebpackConfig(
|
||||
viewerAlias["web-com"] = "web/genericcom.js";
|
||||
viewerAlias["web-download_manager"] = "web/download_manager.js";
|
||||
viewerAlias["web-l10n_utils"] = "web/l10n_utils.js";
|
||||
viewerAlias["web-preferences"] = "web/genericcom.js";
|
||||
viewerAlias["web-print_service"] = "web/pdf_print_service.js";
|
||||
} else if (bundleDefines.MOZCENTRAL) {
|
||||
if (bundleDefines.GECKOVIEW) {
|
||||
@ -317,6 +320,7 @@ function createWebpackConfig(
|
||||
}
|
||||
viewerAlias["web-com"] = "web/firefoxcom.js";
|
||||
viewerAlias["web-download_manager"] = "web/firefoxcom.js";
|
||||
viewerAlias["web-preferences"] = "web/firefoxcom.js";
|
||||
viewerAlias["web-print_service"] = "web/firefox_print_service.js";
|
||||
}
|
||||
const alias = { ...basicAlias, ...libraryAlias, ...viewerAlias };
|
||||
|
@ -39,6 +39,7 @@
|
||||
"web-pdf_presentation_mode": "../../web/pdf_presentation_mode.js",
|
||||
"web-pdf_sidebar": "../../web/pdf_sidebar.js",
|
||||
"web-pdf_thumbnail_viewer": "../../web/pdf_thumbnail_viewer.js",
|
||||
"web-preferences": "../../web/genericcom.js",
|
||||
"web-print_service": "../../web/pdf_print_service.js",
|
||||
"web-secondary_toolbar": "../../web/secondary_toolbar.js",
|
||||
"web-toolbar": "../../web/toolbar.js"
|
||||
|
@ -73,6 +73,7 @@ import { PDFScriptingManager } from "./pdf_scripting_manager.js";
|
||||
import { PDFSidebar } from "web-pdf_sidebar";
|
||||
import { PDFThumbnailViewer } from "web-pdf_thumbnail_viewer";
|
||||
import { PDFViewer } from "./pdf_viewer.js";
|
||||
import { Preferences } from "web-preferences";
|
||||
import { SecondaryToolbar } from "web-secondary_toolbar";
|
||||
import { Toolbar } from "web-toolbar";
|
||||
import { ViewHistory } from "./view_history.js";
|
||||
@ -99,10 +100,6 @@ class DefaultExternalServices {
|
||||
|
||||
static reportTelemetry(data) {}
|
||||
|
||||
static createPreferences() {
|
||||
throw new Error("Not implemented: createPreferences");
|
||||
}
|
||||
|
||||
static async createL10n() {
|
||||
throw new Error("Not implemented: createL10n");
|
||||
}
|
||||
@ -617,7 +614,7 @@ const PDFViewerApplication = {
|
||||
},
|
||||
|
||||
async run(config) {
|
||||
this.preferences = this.externalServices.createPreferences();
|
||||
this.preferences = new Preferences();
|
||||
await this.initialize(config);
|
||||
|
||||
const { appConfig, eventBus } = this;
|
||||
|
@ -325,7 +325,7 @@ function setReferer(url, callback) {
|
||||
// chrome.storage.local to chrome.storage.sync when needed.
|
||||
const storageArea = chrome.storage.sync || chrome.storage.local;
|
||||
|
||||
class ChromePreferences extends BasePreferences {
|
||||
class Preferences extends BasePreferences {
|
||||
async _writeToStorage(prefObj) {
|
||||
return new Promise(resolve => {
|
||||
if (prefObj === this.defaults) {
|
||||
@ -426,10 +426,6 @@ class ChromeExternalServices extends DefaultExternalServices {
|
||||
);
|
||||
}
|
||||
|
||||
static createPreferences() {
|
||||
return new ChromePreferences();
|
||||
}
|
||||
|
||||
static async createL10n() {
|
||||
return new GenericL10n(navigator.language);
|
||||
}
|
||||
@ -440,4 +436,4 @@ class ChromeExternalServices extends DefaultExternalServices {
|
||||
}
|
||||
PDFViewerApplication.externalServices = ChromeExternalServices;
|
||||
|
||||
export { ChromeCom };
|
||||
export { ChromeCom, Preferences };
|
||||
|
@ -147,7 +147,7 @@ class DownloadManager {
|
||||
}
|
||||
}
|
||||
|
||||
class FirefoxPreferences extends BasePreferences {
|
||||
class Preferences extends BasePreferences {
|
||||
async _readFromStorage(prefObj) {
|
||||
return FirefoxCom.requestAsync("getPreferences", prefObj);
|
||||
}
|
||||
@ -382,10 +382,6 @@ class FirefoxExternalServices extends DefaultExternalServices {
|
||||
FirefoxCom.request("reportTelemetry", JSON.stringify(data));
|
||||
}
|
||||
|
||||
static createPreferences() {
|
||||
return new FirefoxPreferences();
|
||||
}
|
||||
|
||||
static updateEditorStates(data) {
|
||||
FirefoxCom.request("updateEditorStates", data);
|
||||
}
|
||||
@ -412,4 +408,4 @@ class FirefoxExternalServices extends DefaultExternalServices {
|
||||
}
|
||||
PDFViewerApplication.externalServices = FirefoxExternalServices;
|
||||
|
||||
export { DownloadManager, FirefoxCom };
|
||||
export { DownloadManager, FirefoxCom, Preferences };
|
||||
|
@ -27,7 +27,7 @@ if (typeof PDFJSDev !== "undefined" && !PDFJSDev.test("GENERIC")) {
|
||||
|
||||
const GenericCom = {};
|
||||
|
||||
class GenericPreferences extends BasePreferences {
|
||||
class Preferences extends BasePreferences {
|
||||
async _writeToStorage(prefObj) {
|
||||
localStorage.setItem("pdfjs.preferences", JSON.stringify(prefObj));
|
||||
}
|
||||
@ -38,10 +38,6 @@ class GenericPreferences extends BasePreferences {
|
||||
}
|
||||
|
||||
class GenericExternalServices extends DefaultExternalServices {
|
||||
static createPreferences() {
|
||||
return new GenericPreferences();
|
||||
}
|
||||
|
||||
static async createL10n() {
|
||||
return new GenericL10n(AppOptions.get("locale"));
|
||||
}
|
||||
@ -52,4 +48,4 @@ class GenericExternalServices extends DefaultExternalServices {
|
||||
}
|
||||
PDFViewerApplication.externalServices = GenericExternalServices;
|
||||
|
||||
export { GenericCom };
|
||||
export { GenericCom, Preferences };
|
||||
|
@ -72,6 +72,7 @@ See https://github.com/adobe-type-tools/cmap-resources
|
||||
"web-pdf_presentation_mode": "./stubs-geckoview.js",
|
||||
"web-pdf_sidebar": "./stubs-geckoview.js",
|
||||
"web-pdf_thumbnail_viewer": "./stubs-geckoview.js",
|
||||
"web-preferences": "./genericcom.js",
|
||||
"web-print_service": "./pdf_print_service.js",
|
||||
"web-secondary_toolbar": "./stubs-geckoview.js",
|
||||
"web-toolbar": "./toolbar-geckoview.js"
|
||||
|
@ -81,6 +81,7 @@ See https://github.com/adobe-type-tools/cmap-resources
|
||||
"web-pdf_presentation_mode": "./pdf_presentation_mode.js",
|
||||
"web-pdf_sidebar": "./pdf_sidebar.js",
|
||||
"web-pdf_thumbnail_viewer": "./pdf_thumbnail_viewer.js",
|
||||
"web-preferences": "./genericcom.js",
|
||||
"web-print_service": "./pdf_print_service.js",
|
||||
"web-secondary_toolbar": "./secondary_toolbar.js",
|
||||
"web-toolbar": "./toolbar.js"
|
||||
|
Loading…
Reference in New Issue
Block a user