mirror of
https://github.com/mozilla/pdf.js.git
synced 2026-02-08 00:21:11 +01:00
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:
parent
1c12b07726
commit
ea993bfc1b
@ -1174,7 +1174,9 @@ describe("Stamp Editor", () => {
|
|||||||
// Run sequentially to avoid clipboard issues.
|
// Run sequentially to avoid clipboard issues.
|
||||||
for (const [, page] of pages) {
|
for (const [, page] of pages) {
|
||||||
await page.evaluate(() => {
|
await page.evaluate(() => {
|
||||||
window.PDFViewerApplication.mlManager.enableAltTextModelDownload = false;
|
const { mlManager } = window.PDFViewerApplication;
|
||||||
|
mlManager.enableGuessAltText =
|
||||||
|
mlManager.enableAltTextModelDownload = false;
|
||||||
});
|
});
|
||||||
|
|
||||||
await switchToStamp(page);
|
await switchToStamp(page);
|
||||||
@ -1197,7 +1199,9 @@ describe("Stamp Editor", () => {
|
|||||||
// Run sequentially to avoid clipboard issues.
|
// Run sequentially to avoid clipboard issues.
|
||||||
for (const [browserName, page] of pages) {
|
for (const [browserName, page] of pages) {
|
||||||
await page.evaluate(() => {
|
await page.evaluate(() => {
|
||||||
window.PDFViewerApplication.mlManager.enableAltTextModelDownload = true;
|
const { mlManager } = window.PDFViewerApplication;
|
||||||
|
mlManager.enableGuessAltText =
|
||||||
|
mlManager.enableAltTextModelDownload = true;
|
||||||
});
|
});
|
||||||
await switchToStamp(page);
|
await switchToStamp(page);
|
||||||
|
|
||||||
|
|||||||
@ -122,7 +122,21 @@ class NewAltTextManager {
|
|||||||
});
|
});
|
||||||
|
|
||||||
if (this.#uiManager) {
|
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);
|
await this.#uiManager.mlManager.toggleService("altText", checked);
|
||||||
}
|
}
|
||||||
this.#toggleGuessAltText(checked, /* isInitial = */ false);
|
this.#toggleGuessAltText(checked, /* isInitial = */ false);
|
||||||
@ -165,6 +179,14 @@ class NewAltTextManager {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#setPref(name, value) {
|
||||||
|
this.#eventBus.dispatch("setpreference", {
|
||||||
|
source: this,
|
||||||
|
name,
|
||||||
|
value,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
#toggleLoading(value) {
|
#toggleLoading(value) {
|
||||||
if (!this.#uiManager || this.#isAILoading === value) {
|
if (!this.#uiManager || this.#isAILoading === value) {
|
||||||
return;
|
return;
|
||||||
@ -180,7 +202,7 @@ class NewAltTextManager {
|
|||||||
this.#dialog.classList.toggle("error", value);
|
this.#dialog.classList.toggle("error", value);
|
||||||
}
|
}
|
||||||
|
|
||||||
async #toggleGuessAltText(value, isInitial = false) {
|
async #toggleGuessAltText(value, isInitial) {
|
||||||
if (!this.#uiManager) {
|
if (!this.#uiManager) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -353,16 +375,15 @@ class NewAltTextManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
this.#firstTime = firstTime;
|
this.#firstTime = firstTime;
|
||||||
let { mlManager } = uiManager;
|
const { mlManager } = uiManager;
|
||||||
let hasAI = !!mlManager;
|
const hasAI = !!mlManager;
|
||||||
this.#toggleTitleAndDisclaimer();
|
this.#toggleTitleAndDisclaimer();
|
||||||
|
|
||||||
if (mlManager && !mlManager.isReady("altText")) {
|
if (mlManager && !mlManager.isReady("altText")) {
|
||||||
hasAI = false;
|
|
||||||
if (mlManager.hasProgress) {
|
if (mlManager.hasProgress) {
|
||||||
this.#setProgress();
|
this.#setProgress();
|
||||||
} else {
|
} else {
|
||||||
mlManager = null;
|
this.#createAutomaticallyButton.setAttribute("aria-pressed", false);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
this.#downloadModel.classList.toggle("hidden", true);
|
this.#downloadModel.classList.toggle("hidden", true);
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user