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:
parent
1d523d3ec1
commit
caebe335b2
31
web/app.js
31
web/app.js
@ -1545,29 +1545,32 @@ const PDFViewerApplication = {
|
||||
async _initializeAutoPrint(pdfDocument, openActionPromise) {
|
||||
const [openAction, jsActions] = await Promise.all([
|
||||
openActionPromise,
|
||||
!this.pdfViewer.enableScripting ? pdfDocument.getJSActions() : null,
|
||||
this.pdfViewer.enableScripting ? null : pdfDocument.getJSActions(),
|
||||
]);
|
||||
|
||||
if (pdfDocument !== this.pdfDocument) {
|
||||
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) {
|
||||
for (const name in jsActions) {
|
||||
if (jsActions[name]) {
|
||||
console.warn("Warning: JavaScript support is not enabled");
|
||||
break;
|
||||
}
|
||||
}
|
||||
console.warn("Warning: JavaScript support is not enabled");
|
||||
|
||||
// Hack to support auto printing.
|
||||
triggerAutoPrint ||= !!(
|
||||
jsActions.OpenAction && AutoPrintRegExp.test(jsActions.OpenAction)
|
||||
);
|
||||
for (const name in jsActions) {
|
||||
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) {
|
||||
|
Loading…
Reference in New Issue
Block a user