1
0
Fork 0
mirror of https://github.com/mozilla/pdf.js.git synced 2025-04-19 22:58:07 +02:00

[Firefox] Remove the "loadaiengineprogress" listener with AbortSignal.any()

This commit is contained in:
Jonas Jenwald 2024-08-10 11:16:42 +02:00
parent b6b99a7b75
commit 723c76929c

View file

@ -466,24 +466,28 @@ class MLManager {
});
(this.#enabled ||= new Map()).set("altText", promise);
if (listenToProgress) {
const ac = new AbortController();
const signal = AbortSignal.any([this.#abortSignal, ac.signal]);
this.hasProgress = true;
const callback = ({ detail }) => {
this.#eventBus.dispatch("loadaiengineprogress", {
source: this,
detail,
});
if (detail.finished) {
this.hasProgress = false;
window.removeEventListener("loadAIEngineProgress", callback);
}
};
window.addEventListener("loadAIEngineProgress", callback, {
signal: this.#abortSignal,
});
window.addEventListener(
"loadAIEngineProgress",
({ detail }) => {
this.#eventBus.dispatch("loadaiengineprogress", {
source: this,
detail,
});
if (detail.finished) {
ac.abort();
this.hasProgress = false;
}
},
{ signal }
);
promise.then(ok => {
if (!ok) {
ac.abort();
this.hasProgress = false;
window.removeEventListener("loadAIEngineProgress", callback);
}
});
}