mirror of
https://github.com/mozilla/pdf.js.git
synced 2025-04-22 16:18:08 +02:00
Merge pull request #18573 from calixteman/cancel_ai_requests
[Editor] Dispatch changes in prefs enableAltTextModelDownload and enableGuessAltText to the viewer (bug 1912024)
This commit is contained in:
commit
fef2853263
6 changed files with 164 additions and 53 deletions
|
@ -141,9 +141,11 @@ class StampEditor extends AnnotationEditor {
|
|||
this._uiManager.useNewAltTextFlow &&
|
||||
this.#bitmap
|
||||
) {
|
||||
// The alt-text dialog isn't opened but we still want to guess the alt
|
||||
// text.
|
||||
this.mlGuessAltText();
|
||||
try {
|
||||
// The alt-text dialog isn't opened but we still want to guess the alt
|
||||
// text.
|
||||
this.mlGuessAltText();
|
||||
} catch {}
|
||||
}
|
||||
|
||||
this.div.focus();
|
||||
|
@ -155,8 +157,11 @@ class StampEditor extends AnnotationEditor {
|
|||
}
|
||||
|
||||
const { mlManager } = this._uiManager;
|
||||
if (!mlManager || !(await mlManager.isEnabledFor("altText"))) {
|
||||
return null;
|
||||
if (!mlManager) {
|
||||
throw new Error("No ML.");
|
||||
}
|
||||
if (!(await mlManager.isEnabledFor("altText"))) {
|
||||
throw new Error("ML isn't enabled for alt text.");
|
||||
}
|
||||
const { data, width, height } =
|
||||
imageData ||
|
||||
|
@ -170,9 +175,18 @@ class StampEditor extends AnnotationEditor {
|
|||
channels: data.length / (width * height),
|
||||
},
|
||||
});
|
||||
if (!response || response.error || !response.output) {
|
||||
if (!response) {
|
||||
throw new Error("No response from the AI service.");
|
||||
}
|
||||
if (response.error) {
|
||||
throw new Error("Error from the AI service.");
|
||||
}
|
||||
if (response.cancel) {
|
||||
return null;
|
||||
}
|
||||
if (!response.output) {
|
||||
throw new Error("No valid response from the AI service.");
|
||||
}
|
||||
const altText = response.output;
|
||||
await this.setGuessedAltText(altText);
|
||||
if (updateAltTextData && !this.hasAltTextData()) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue