Let the toggle button in the alt-text dialog downloading (resp. delete) the model and enabling (resp. disabling) alt-text guessing (bug 2014167)

This commit is contained in:
Calixte Denizet 2026-02-03 20:27:06 +01:00
parent 1c12b07726
commit ea993bfc1b
No known key found for this signature in database
GPG Key ID: 0C5442631EE0691F
2 changed files with 33 additions and 8 deletions

View File

@ -1174,7 +1174,9 @@ describe("Stamp Editor", () => {
// Run sequentially to avoid clipboard issues.
for (const [, page] of pages) {
await page.evaluate(() => {
window.PDFViewerApplication.mlManager.enableAltTextModelDownload = false;
const { mlManager } = window.PDFViewerApplication;
mlManager.enableGuessAltText =
mlManager.enableAltTextModelDownload = false;
});
await switchToStamp(page);
@ -1197,7 +1199,9 @@ describe("Stamp Editor", () => {
// Run sequentially to avoid clipboard issues.
for (const [browserName, page] of pages) {
await page.evaluate(() => {
window.PDFViewerApplication.mlManager.enableAltTextModelDownload = true;
const { mlManager } = window.PDFViewerApplication;
mlManager.enableGuessAltText =
mlManager.enableAltTextModelDownload = true;
});
await switchToStamp(page);

View File

@ -122,7 +122,21 @@ class NewAltTextManager {
});
if (this.#uiManager) {
this.#uiManager.setPreference("enableGuessAltText", checked);
const isAltTextEnabled =
await this.#uiManager.mlManager.isEnabledFor("altText");
this.#createAutomaticallyButton.disabled = true;
if (checked && !isAltTextEnabled) {
this.#textarea.value = "";
this.#setProgress();
this.#uiManager.setPreference("enableGuessAltText", true);
await this.#uiManager.mlManager.downloadModel("altText");
this.#setPref("enableAltTextModelDownload", true);
} else if (!checked && isAltTextEnabled) {
this.#uiManager.setPreference("enableGuessAltText", false);
await this.#uiManager.mlManager.deleteModel("altText");
this.#setPref("enableAltTextModelDownload", false);
}
this.#createAutomaticallyButton.disabled = false;
await this.#uiManager.mlManager.toggleService("altText", checked);
}
this.#toggleGuessAltText(checked, /* isInitial = */ false);
@ -165,6 +179,14 @@ class NewAltTextManager {
});
}
#setPref(name, value) {
this.#eventBus.dispatch("setpreference", {
source: this,
name,
value,
});
}
#toggleLoading(value) {
if (!this.#uiManager || this.#isAILoading === value) {
return;
@ -180,7 +202,7 @@ class NewAltTextManager {
this.#dialog.classList.toggle("error", value);
}
async #toggleGuessAltText(value, isInitial = false) {
async #toggleGuessAltText(value, isInitial) {
if (!this.#uiManager) {
return;
}
@ -353,16 +375,15 @@ class NewAltTextManager {
}
this.#firstTime = firstTime;
let { mlManager } = uiManager;
let hasAI = !!mlManager;
const { mlManager } = uiManager;
const hasAI = !!mlManager;
this.#toggleTitleAndDisclaimer();
if (mlManager && !mlManager.isReady("altText")) {
hasAI = false;
if (mlManager.hasProgress) {
this.#setProgress();
} else {
mlManager = null;
this.#createAutomaticallyButton.setAttribute("aria-pressed", false);
}
} else {
this.#downloadModel.classList.toggle("hidden", true);