Merge pull request #14888 from Snuffleupagus/attachmentsCount-zero
Try to fix dispatching of "attachmentsloaded"-events, when the document contains no "regular" attachments (PR 8788, 12163 follow-up)
This commit is contained in:
commit
753abc383e
@ -15,6 +15,7 @@
|
|||||||
|
|
||||||
import { createPromiseCapability, getFilenameFromUrl } from "pdfjs-lib";
|
import { createPromiseCapability, getFilenameFromUrl } from "pdfjs-lib";
|
||||||
import { BaseTreeViewer } from "./base_tree_viewer.js";
|
import { BaseTreeViewer } from "./base_tree_viewer.js";
|
||||||
|
import { waitOnEventOrTimeout } from "./event_utils.js";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @typedef {Object} PDFAttachmentViewerOptions
|
* @typedef {Object} PDFAttachmentViewerOptions
|
||||||
@ -51,36 +52,33 @@ class PDFAttachmentViewer extends BaseTreeViewer {
|
|||||||
// replaced is when appending FileAttachment annotations.
|
// replaced is when appending FileAttachment annotations.
|
||||||
this._renderedCapability = createPromiseCapability();
|
this._renderedCapability = createPromiseCapability();
|
||||||
}
|
}
|
||||||
if (this._pendingDispatchEvent) {
|
this._pendingDispatchEvent = false;
|
||||||
clearTimeout(this._pendingDispatchEvent);
|
|
||||||
}
|
|
||||||
this._pendingDispatchEvent = null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @private
|
* @private
|
||||||
*/
|
*/
|
||||||
_dispatchEvent(attachmentsCount) {
|
async _dispatchEvent(attachmentsCount) {
|
||||||
this._renderedCapability.resolve();
|
this._renderedCapability.resolve();
|
||||||
|
|
||||||
if (this._pendingDispatchEvent) {
|
if (attachmentsCount === 0 && !this._pendingDispatchEvent) {
|
||||||
clearTimeout(this._pendingDispatchEvent);
|
|
||||||
this._pendingDispatchEvent = null;
|
|
||||||
}
|
|
||||||
if (attachmentsCount === 0) {
|
|
||||||
// Delay the event when no "regular" attachments exist, to allow time for
|
// Delay the event when no "regular" attachments exist, to allow time for
|
||||||
// parsing of any FileAttachment annotations that may be present on the
|
// parsing of any FileAttachment annotations that may be present on the
|
||||||
// *initially* rendered page; this reduces the likelihood of temporarily
|
// *initially* rendered page; this reduces the likelihood of temporarily
|
||||||
// disabling the attachmentsView when the `PDFSidebar` handles the event.
|
// disabling the attachmentsView when the `PDFSidebar` handles the event.
|
||||||
this._pendingDispatchEvent = setTimeout(() => {
|
this._pendingDispatchEvent = true;
|
||||||
this.eventBus.dispatch("attachmentsloaded", {
|
|
||||||
source: this,
|
await waitOnEventOrTimeout({
|
||||||
attachmentsCount: 0,
|
target: this.eventBus,
|
||||||
});
|
name: "annotationlayerrendered",
|
||||||
this._pendingDispatchEvent = null;
|
delay: 1000,
|
||||||
});
|
});
|
||||||
return;
|
|
||||||
|
if (!this._pendingDispatchEvent) {
|
||||||
|
return; // There was already another `_dispatchEvent`-call`.
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
this._pendingDispatchEvent = false;
|
||||||
|
|
||||||
this.eventBus.dispatch("attachmentsloaded", {
|
this.eventBus.dispatch("attachmentsloaded", {
|
||||||
source: this,
|
source: this,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user