mirror of
https://github.com/mozilla/pdf.js.git
synced 2025-04-22 16:18:08 +02:00
Merge pull request #16766 from calixteman/fix_willprint
Make sure WillPrint ran before starting printing
This commit is contained in:
commit
621c92dbdd
4 changed files with 58 additions and 20 deletions
|
@ -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);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue