mirror of
https://github.com/zen-browser/pdf.js.git
synced 2025-07-08 01:10:08 +02:00
[Editor] Add a new dialog for alt-text settings (bug 1909604)
This patch adds a new entry in the secondary menu in order to open a dialog to let the user: - disables the alt-text generation thanks to a ML model; - deletes the alt-text model downloaded in Firefox; - disabled the new alt-text flow.
This commit is contained in:
parent
d562e0525d
commit
32d09276f0
17 changed files with 627 additions and 54 deletions
|
@ -70,20 +70,57 @@ class MLManager {
|
|||
}
|
||||
|
||||
class FakeMLManager {
|
||||
constructor({ enableGuessAltText }) {
|
||||
eventBus = null;
|
||||
|
||||
hasProgress = false;
|
||||
|
||||
constructor({ enableGuessAltText, enableAltTextModelDownload }) {
|
||||
this.enableGuessAltText = enableGuessAltText;
|
||||
this.enableAltTextModelDownload = enableAltTextModelDownload;
|
||||
}
|
||||
|
||||
async isEnabledFor(_name) {
|
||||
return this.enableGuessAltText;
|
||||
}
|
||||
|
||||
async deleteModel(_service) {
|
||||
async deleteModel(_name) {
|
||||
this.enableAltTextModelDownload = false;
|
||||
return null;
|
||||
}
|
||||
|
||||
async downloadModel(_name) {
|
||||
// Simulate downloading the model but with progress.
|
||||
// The progress can be seen in the new alt-text dialog.
|
||||
this.hasProgress = true;
|
||||
|
||||
const { promise, resolve } = Promise.withResolvers();
|
||||
const total = 1e8;
|
||||
const end = 1.5 * total;
|
||||
const increment = 5e6;
|
||||
let loaded = 0;
|
||||
const id = setInterval(() => {
|
||||
loaded += increment;
|
||||
if (loaded <= end) {
|
||||
this.eventBus.dispatch("loadaiengineprogress", {
|
||||
source: this,
|
||||
detail: {
|
||||
total,
|
||||
totalLoaded: loaded,
|
||||
finished: loaded + increment >= end,
|
||||
},
|
||||
});
|
||||
return;
|
||||
}
|
||||
clearInterval(id);
|
||||
this.hasProgress = false;
|
||||
this.enableAltTextModelDownload = true;
|
||||
resolve(true);
|
||||
}, 900);
|
||||
return promise;
|
||||
}
|
||||
|
||||
isReady(_name) {
|
||||
return true;
|
||||
return this.enableAltTextModelDownload;
|
||||
}
|
||||
|
||||
guess({ request: { data } }) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue