Re-factor PDFViewerApplication._initializeAutoPrint slightly (PR 16779 follow-up)

After the `src/core/`-changes in PR 16779 the `PDFDocumentProxy.getJSActions` method should no longer be able to return *empty* entries, which means that we can simplify the "JavaScript support is not enabled"-warning in the viewer.
Furthermore, improve the auto-printing hack used when scripting is disabled.
This commit is contained in:
Jonas Jenwald 2023-08-09 10:38:27 +02:00
parent 1d523d3ec1
commit caebe335b2

View File

@ -1545,29 +1545,32 @@ const PDFViewerApplication = {
async _initializeAutoPrint(pdfDocument, openActionPromise) { async _initializeAutoPrint(pdfDocument, openActionPromise) {
const [openAction, jsActions] = await Promise.all([ const [openAction, jsActions] = await Promise.all([
openActionPromise, openActionPromise,
!this.pdfViewer.enableScripting ? pdfDocument.getJSActions() : null, this.pdfViewer.enableScripting ? null : pdfDocument.getJSActions(),
]); ]);
if (pdfDocument !== this.pdfDocument) { if (pdfDocument !== this.pdfDocument) {
return; // The document was closed while the auto print data resolved. return; // The document was closed while the auto print data resolved.
} }
let triggerAutoPrint = false; let triggerAutoPrint = openAction?.action === "Print";
if (openAction?.action === "Print") {
triggerAutoPrint = true;
}
if (jsActions) { if (jsActions) {
for (const name in jsActions) {
if (jsActions[name]) {
console.warn("Warning: JavaScript support is not enabled"); console.warn("Warning: JavaScript support is not enabled");
break;
}
}
// Hack to support auto printing. // Hack to support auto printing.
triggerAutoPrint ||= !!( for (const name in jsActions) {
jsActions.OpenAction && AutoPrintRegExp.test(jsActions.OpenAction) if (triggerAutoPrint) {
); break;
}
switch (name) {
case "WillClose":
case "WillSave":
case "DidSave":
case "WillPrint":
case "DidPrint":
continue;
}
triggerAutoPrint = jsActions[name].some(js => AutoPrintRegExp.test(js));
}
} }
if (triggerAutoPrint) { if (triggerAutoPrint) {