Don't dispatch a "doc/Open" event in the sandbox when creating it failed
There's really no point, as far as I can tell, to attempt to dispatch an event in a non-existent sandbox. Generally speaking, even trying to do this *could* possibly even lead to errors in some cases. Furthermore, utilize optional chaining to simplify some `dispatchEventInSandbox` calls throughout the viewer. Finally, replace superfluous `return` statements with `break` in the switch-statement in the `updateFromSandbox` event-handler.
This commit is contained in:
parent
c78f153bda
commit
54f45dc935
49
web/app.js
49
web/app.js
@ -1036,13 +1036,10 @@ const PDFViewerApplication = {
|
||||
this.download({ sourceEventType });
|
||||
return;
|
||||
}
|
||||
|
||||
if (this._scriptingInstance) {
|
||||
this._scriptingInstance.scripting.dispatchEventInSandbox({
|
||||
id: "doc",
|
||||
name: "WillSave",
|
||||
});
|
||||
}
|
||||
this._scriptingInstance?.scripting.dispatchEventInSandbox({
|
||||
id: "doc",
|
||||
name: "WillSave",
|
||||
});
|
||||
|
||||
this._saveInProgress = true;
|
||||
this.pdfDocument
|
||||
@ -1051,12 +1048,10 @@ const PDFViewerApplication = {
|
||||
const blob = new Blob([data], { type: "application/pdf" });
|
||||
downloadManager.download(blob, url, filename, sourceEventType);
|
||||
|
||||
if (this._scriptingInstance) {
|
||||
this._scriptingInstance.scripting.dispatchEventInSandbox({
|
||||
id: "doc",
|
||||
name: "DidSave",
|
||||
});
|
||||
}
|
||||
this._scriptingInstance?.scripting.dispatchEventInSandbox({
|
||||
id: "doc",
|
||||
name: "DidSave",
|
||||
});
|
||||
})
|
||||
.catch(() => {
|
||||
this.download({ sourceEventType });
|
||||
@ -1514,15 +1509,15 @@ const PDFViewerApplication = {
|
||||
break;
|
||||
case "layout":
|
||||
this.pdfViewer.spreadMode = apiPageLayoutToSpreadMode(value);
|
||||
return;
|
||||
break;
|
||||
case "page-num":
|
||||
this.pdfViewer.currentPageNumber = value + 1;
|
||||
return;
|
||||
break;
|
||||
case "print":
|
||||
this.pdfViewer.pagesPromise.then(() => {
|
||||
this.triggerPrinting();
|
||||
});
|
||||
return;
|
||||
break;
|
||||
case "println":
|
||||
console.log(value);
|
||||
break;
|
||||
@ -1608,7 +1603,9 @@ const PDFViewerApplication = {
|
||||
}
|
||||
} catch (error) {
|
||||
console.error(`_initializeJavaScript: "${error?.message}".`);
|
||||
|
||||
this._destroyScriptingInstance();
|
||||
return;
|
||||
}
|
||||
|
||||
scripting.dispatchEventInSandbox({
|
||||
@ -2033,21 +2030,17 @@ const PDFViewerApplication = {
|
||||
if (!this.supportsPrinting) {
|
||||
return;
|
||||
}
|
||||
if (this._scriptingInstance) {
|
||||
this._scriptingInstance.scripting.dispatchEventInSandbox({
|
||||
id: "doc",
|
||||
name: "WillPrint",
|
||||
});
|
||||
}
|
||||
this._scriptingInstance?.scripting.dispatchEventInSandbox({
|
||||
id: "doc",
|
||||
name: "WillPrint",
|
||||
});
|
||||
|
||||
window.print();
|
||||
|
||||
if (this._scriptingInstance) {
|
||||
this._scriptingInstance.scripting.dispatchEventInSandbox({
|
||||
id: "doc",
|
||||
name: "DidPrint",
|
||||
});
|
||||
}
|
||||
this._scriptingInstance?.scripting.dispatchEventInSandbox({
|
||||
id: "doc",
|
||||
name: "DidPrint",
|
||||
});
|
||||
},
|
||||
|
||||
bindEvents() {
|
||||
|
Loading…
x
Reference in New Issue
Block a user