Re-factor DefaultExternalServices into a regular class, without static methods

The `DefaultExternalServices` code, which is used to provide build-specific functionality, is very old. This results in a pattern where we first initialize `PDFViewerApplication.externalServices` and then *override* it for the different builds.

By converting `DefaultExternalServices` into a "regular" class, and leveraging import maps, we can directly initialize the correct instance depending on the build.
This commit is contained in:
Jonas Jenwald 2024-01-26 14:31:42 +01:00
parent d1080e785a
commit 5dd25b6e80
9 changed files with 80 additions and 61 deletions

View file

@ -13,8 +13,8 @@
* limitations under the License.
*/
import { DefaultExternalServices, PDFViewerApplication } from "./app.js";
import { AppOptions } from "./app_options.js";
import { BaseExternalServices } from "./external_services.js";
import { BasePreferences } from "./preferences.js";
import { GenericL10n } from "./genericl10n.js";
import { GenericScripting } from "./generic_scripting.js";
@ -37,15 +37,14 @@ class Preferences extends BasePreferences {
}
}
class GenericExternalServices extends DefaultExternalServices {
static async createL10n() {
class ExternalServices extends BaseExternalServices {
async createL10n() {
return new GenericL10n(AppOptions.get("locale"));
}
static createScripting() {
createScripting() {
return new GenericScripting(AppOptions.get("sandboxBundleSrc"));
}
}
PDFViewerApplication.externalServices = GenericExternalServices;
export { GenericCom, Preferences };
export { ExternalServices, GenericCom, Preferences };