From a81b071d2df551b00487bc45390b55c063803d3f Mon Sep 17 00:00:00 2001 From: Calixte Denizet Date: Fri, 2 Aug 2024 15:00:41 +0200 Subject: [PATCH] [Editor] Load the model when the user switch to the stamp editing mode --- web/firefoxcom.js | 10 ++++++---- web/genericcom.js | 2 ++ web/pdf_viewer.js | 6 ++++++ 3 files changed, 14 insertions(+), 4 deletions(-) diff --git a/web/firefoxcom.js b/web/firefoxcom.js index 881919820e9a1..51b7376cbaa96 100644 --- a/web/firefoxcom.js +++ b/web/firefoxcom.js @@ -329,10 +329,6 @@ class MLManager { this.altTextLearnMoreUrl = altTextLearnMoreUrl; this.enableAltTextModelDownload = enableAltTextModelDownload; this.enableGuessAltText = enableGuessAltText; - - if (enableAltTextModelDownload) { - this.#loadAltTextEngine(false); - } } async isEnabledFor(name) { @@ -356,6 +352,12 @@ class MLManager { ]); } + async loadModel(name) { + if (name === "altText" && this.enableAltTextModelDownload) { + await this.#loadAltTextEngine(false); + } + } + async downloadModel(name) { if (name !== "altText") { return null; diff --git a/web/genericcom.js b/web/genericcom.js index 0d1b58b9566ef..4abde7e8ad980 100644 --- a/web/genericcom.js +++ b/web/genericcom.js @@ -88,6 +88,8 @@ class FakeMLManager { return null; } + async loadModel(_name) {} + async downloadModel(_name) { // Simulate downloading the model but with progress. // The progress can be seen in the new alt-text dialog. diff --git a/web/pdf_viewer.js b/web/pdf_viewer.js index 43089d007add6..5faa1d3734bda 100644 --- a/web/pdf_viewer.js +++ b/web/pdf_viewer.js @@ -906,6 +906,9 @@ class PDFViewer { uiManager: this.#annotationEditorUIManager, }); if (mode !== AnnotationEditorType.NONE) { + if (mode === AnnotationEditorType.STAMP) { + this.#mlManager?.loadModel("altText"); + } this.#annotationEditorUIManager.updateMode(mode); } } else { @@ -2311,6 +2314,9 @@ class PDFViewer { if (!this.pdfDocument) { return; } + if (mode === AnnotationEditorType.STAMP) { + this.#mlManager?.loadModel("altText"); + } const { eventBus } = this; const updater = () => {