1
0
Fork 0
mirror of https://github.com/mozilla/pdf.js.git synced 2025-04-22 16:18:08 +02:00

Make sure WillPrint ran before starting printing

This commit is contained in:
Calixte Denizet 2023-07-29 17:33:13 +02:00
parent 7ae5a0fef7
commit 8439e11160
4 changed files with 58 additions and 20 deletions

View file

@ -51,6 +51,8 @@ class PDFScriptingManager {
#scripting = null;
#willPrintCapability = null;
/**
* @param {PDFScriptingManagerOptions} options
*/
@ -203,10 +205,23 @@ class PDFScriptingManager {
}
async dispatchWillPrint() {
return this.#scripting?.dispatchEventInSandbox({
id: "doc",
name: "WillPrint",
});
if (!this.#scripting) {
return;
}
await this.#willPrintCapability?.promise;
this.#willPrintCapability = new PromiseCapability();
try {
await this.#scripting.dispatchEventInSandbox({
id: "doc",
name: "WillPrint",
});
} catch (ex) {
this.#willPrintCapability.resolve();
this.#willPrintCapability = null;
throw ex;
}
await this.#willPrintCapability.promise;
}
async dispatchDidPrint() {
@ -306,6 +321,10 @@ class PDFScriptingManager {
pdfViewer.decreaseScale();
}
break;
case "WillPrintFinished":
this.#willPrintCapability?.resolve();
this.#willPrintCapability = null;
break;
}
return;
}
@ -432,6 +451,9 @@ class PDFScriptingManager {
await this.#scripting.destroySandbox();
} catch {}
this.#willPrintCapability?.reject(new Error("Scripting destroyed."));
this.#willPrintCapability = null;
for (const [name, listener] of this._internalEvents) {
this.#eventBus._off(name, listener);
}