Run AnnotationStorage.resetModified
when destroying the PDFDocumentLoadingTask
/PDFDocumentProxy
This will, in a very simple way using the existing events, thus allow the viewer to remove the "beforeunload" `window` event listener when the document is closed. Generally speaking we want to avoid having *global* event listeners for the PDF document instance, which is why the `EventBus` exists, and instead reserve global events for the viewer itself. However, the `AnnotationStorage` "beforeunload" event unfortunately needs to be document-specific and we should thus ensure that it's correctly removed when the document is destroyed.
This commit is contained in:
parent
517af6b6ab
commit
f9530e56da
@ -2127,6 +2127,10 @@ class WorkerTransport {
|
||||
this.setupMessageHandler();
|
||||
}
|
||||
|
||||
get loadingTaskSettled() {
|
||||
return this.loadingTask._capability.settled;
|
||||
}
|
||||
|
||||
destroy() {
|
||||
if (this.destroyCapability) {
|
||||
return this.destroyCapability.promise;
|
||||
@ -2154,6 +2158,18 @@ class WorkerTransport {
|
||||
// We also need to wait for the worker to finish its long running tasks.
|
||||
const terminated = this.messageHandler.sendWithPromise("Terminate", null);
|
||||
waitOn.push(terminated);
|
||||
// Allow `AnnotationStorage`-related clean-up when destroying the document.
|
||||
if (this.loadingTaskSettled) {
|
||||
const annotationStorageResetModified = this.loadingTask.promise
|
||||
.then(pdfDocument => {
|
||||
// Avoid initializing the `annotationStorage` if it doesn't exist.
|
||||
if (pdfDocument.hasOwnProperty("annotationStorage")) {
|
||||
pdfDocument.annotationStorage.resetModified();
|
||||
}
|
||||
})
|
||||
.catch(() => {});
|
||||
waitOn.push(annotationStorageResetModified);
|
||||
}
|
||||
Promise.all(waitOn).then(() => {
|
||||
this.commonObjs.clear();
|
||||
this.fontLoader.clear();
|
||||
|
Loading…
x
Reference in New Issue
Block a user