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 });
|
this.download({ sourceEventType });
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
this._scriptingInstance?.scripting.dispatchEventInSandbox({
|
||||||
if (this._scriptingInstance) {
|
id: "doc",
|
||||||
this._scriptingInstance.scripting.dispatchEventInSandbox({
|
name: "WillSave",
|
||||||
id: "doc",
|
});
|
||||||
name: "WillSave",
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
this._saveInProgress = true;
|
this._saveInProgress = true;
|
||||||
this.pdfDocument
|
this.pdfDocument
|
||||||
@ -1051,12 +1048,10 @@ const PDFViewerApplication = {
|
|||||||
const blob = new Blob([data], { type: "application/pdf" });
|
const blob = new Blob([data], { type: "application/pdf" });
|
||||||
downloadManager.download(blob, url, filename, sourceEventType);
|
downloadManager.download(blob, url, filename, sourceEventType);
|
||||||
|
|
||||||
if (this._scriptingInstance) {
|
this._scriptingInstance?.scripting.dispatchEventInSandbox({
|
||||||
this._scriptingInstance.scripting.dispatchEventInSandbox({
|
id: "doc",
|
||||||
id: "doc",
|
name: "DidSave",
|
||||||
name: "DidSave",
|
});
|
||||||
});
|
|
||||||
}
|
|
||||||
})
|
})
|
||||||
.catch(() => {
|
.catch(() => {
|
||||||
this.download({ sourceEventType });
|
this.download({ sourceEventType });
|
||||||
@ -1514,15 +1509,15 @@ const PDFViewerApplication = {
|
|||||||
break;
|
break;
|
||||||
case "layout":
|
case "layout":
|
||||||
this.pdfViewer.spreadMode = apiPageLayoutToSpreadMode(value);
|
this.pdfViewer.spreadMode = apiPageLayoutToSpreadMode(value);
|
||||||
return;
|
break;
|
||||||
case "page-num":
|
case "page-num":
|
||||||
this.pdfViewer.currentPageNumber = value + 1;
|
this.pdfViewer.currentPageNumber = value + 1;
|
||||||
return;
|
break;
|
||||||
case "print":
|
case "print":
|
||||||
this.pdfViewer.pagesPromise.then(() => {
|
this.pdfViewer.pagesPromise.then(() => {
|
||||||
this.triggerPrinting();
|
this.triggerPrinting();
|
||||||
});
|
});
|
||||||
return;
|
break;
|
||||||
case "println":
|
case "println":
|
||||||
console.log(value);
|
console.log(value);
|
||||||
break;
|
break;
|
||||||
@ -1608,7 +1603,9 @@ const PDFViewerApplication = {
|
|||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error(`_initializeJavaScript: "${error?.message}".`);
|
console.error(`_initializeJavaScript: "${error?.message}".`);
|
||||||
|
|
||||||
this._destroyScriptingInstance();
|
this._destroyScriptingInstance();
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
scripting.dispatchEventInSandbox({
|
scripting.dispatchEventInSandbox({
|
||||||
@ -2033,21 +2030,17 @@ const PDFViewerApplication = {
|
|||||||
if (!this.supportsPrinting) {
|
if (!this.supportsPrinting) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (this._scriptingInstance) {
|
this._scriptingInstance?.scripting.dispatchEventInSandbox({
|
||||||
this._scriptingInstance.scripting.dispatchEventInSandbox({
|
id: "doc",
|
||||||
id: "doc",
|
name: "WillPrint",
|
||||||
name: "WillPrint",
|
});
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
window.print();
|
window.print();
|
||||||
|
|
||||||
if (this._scriptingInstance) {
|
this._scriptingInstance?.scripting.dispatchEventInSandbox({
|
||||||
this._scriptingInstance.scripting.dispatchEventInSandbox({
|
id: "doc",
|
||||||
id: "doc",
|
name: "DidPrint",
|
||||||
name: "DidPrint",
|
});
|
||||||
});
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
|
|
||||||
bindEvents() {
|
bindEvents() {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user