mirror of
https://github.com/mozilla/pdf.js.git
synced 2026-02-07 16:11:12 +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.
|
||||
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);
|
||||
|
||||
|
||||
@ -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);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user