mirror of
https://github.com/zen-browser/pdf.js.git
synced 2025-07-10 02:05:37 +02:00
Re-factor the dispatching of "attachmentsloaded" events, when the PDF document contains no "regular" attachments
Since the attachment fetching/parsing is already asynchronous, possibly delaying the dispatching of an "attachmentsloaded" event should thus not be a problem in general. Note that in some cases, i.e. PDF documents with no "regular" attachments and only FileAttachment annotations, we'll thus no longer dispatch an "attachmentsloaded" event when `attachmentsCount === 0` and instead wait for the FileAttachment parsing to finish. (The use of a timeout still guarantees that an "attachmentsloaded" event is *eventually* dispatched though.) This patch *considerably* simplifies the "attachmentsloaded" event handler, in `PDFSidebar`, since the details are now abstracted away from the consumer. Finally, add a check in `_appendAttachment` to ensure (indirectly) that the FileAttachment annotation is actually relevant for the active document.
This commit is contained in:
parent
24d8933023
commit
0b65d4cacd
2 changed files with 39 additions and 25 deletions
|
@ -445,31 +445,17 @@ class PDFSidebar {
|
|||
});
|
||||
|
||||
this.eventBus._on("attachmentsloaded", evt => {
|
||||
if (evt.attachmentsCount) {
|
||||
this.attachmentsButton.disabled = false;
|
||||
const attachmentsCount = evt.attachmentsCount;
|
||||
|
||||
this.attachmentsButton.disabled = !attachmentsCount;
|
||||
|
||||
if (attachmentsCount) {
|
||||
this._showUINotification(SidebarView.ATTACHMENTS);
|
||||
return;
|
||||
} else if (this.active === SidebarView.ATTACHMENTS) {
|
||||
// If the attachments view was opened during document load, switch away
|
||||
// from it if it turns out that the document has no attachments.
|
||||
this.switchView(SidebarView.THUMBS);
|
||||
}
|
||||
|
||||
// Attempt to avoid temporarily disabling, and switching away from, the
|
||||
// attachment view for documents that do not contain proper attachments
|
||||
// but *only* FileAttachment annotations. Hence we defer those operations
|
||||
// slightly to allow time for parsing any FileAttachment annotations that
|
||||
// may be present on the *initially* rendered page of the document.
|
||||
Promise.resolve().then(() => {
|
||||
if (this.attachmentsView.hasChildNodes()) {
|
||||
// FileAttachment annotations were appended to the attachment view.
|
||||
return;
|
||||
}
|
||||
this.attachmentsButton.disabled = true;
|
||||
|
||||
if (this.active === SidebarView.ATTACHMENTS) {
|
||||
// If the attachment view was opened during document load, switch away
|
||||
// from it if it turns out that the document has no attachments.
|
||||
this.switchView(SidebarView.THUMBS);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
// Update the thumbnailViewer, if visible, when exiting presentation mode.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue