Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a PDFViewerApplication.initializedPromise property to allow (easier) tracking of when the default viewer has been initialized #11607

Merged
merged 1 commit into from
Feb 18, 2020

Conversation

Snuffleupagus
Copy link
Collaborator

This complements the existing PDFViewerApplication.initialized boolean property, and may be helpful for custom implementations of the default viewer. This will thus provide users of the default viewer an alternative to setting the preference to dispatch events to the DOM (and listen for the "localized" event), since they can instead use:

document.addEventListener("webviewerloaded", function() {
  PDFViewerApplication.initializedPromise.then(function() {
    // The viewer has now been initialized.
  })
});

Note that in order to avoid manually tracking the initialization state twice, this implementation purposely uses the PromiseCapability functionality to handle both PDFViewerApplication.initialized and PDFViewerApplication.initializedPromise internally.

…sier) tracking of when the default viewer has been initialized

This complements the existing `PDFViewerApplication.initialized` boolean property, and may be helpful for custom implementations of the default viewer. This will thus provide users of the default viewer an alternative to setting the preference to dispatch events to the DOM (and listen for the "localized" event), since they can instead use:
```javascript
document.addEventListener("webviewerloaded", function() {
  PDFViewerApplication.initializedPromise.then(function() {
    // The viewer has now been initialized.
  })
});
```

Note that in order to avoid manually tracking the initialization state *twice*, this implementation purposely uses the `PromiseCapability` functionality to handle both `PDFViewerApplication.initialized` and `PDFViewerApplication.initializedPromise` internally.
@Snuffleupagus
Copy link
Collaborator Author

/botio-linux preview

@pdfjsbot
Copy link

From: Bot.io (Linux m4)


Received

Command cmd_preview from @Snuffleupagus received. Current queue size: 0

Live output at: http://54.67.70.0:8877/87325bd249d38b6/output.txt

@pdfjsbot
Copy link

From: Bot.io (Linux m4)


Success

Full output at http://54.67.70.0:8877/87325bd249d38b6/output.txt

Total script time: 2.52 mins

Published

@timvandermeij
Copy link
Contributor

Perhaps a bit off-topic for this particular patch, but I'm wondering how we should document the availability of this (and other) features for third-party users. There are quite a few tips and tricks third-party implementers can use, but we don't really document them nor do we have examples for all of them. This is one of those things that can be really useful, but there should be a way to discover that it exists.

Do you have ideas for this? I'm thinking a wiki page could suffice and we can update it incrementally.

@Snuffleupagus
Copy link
Collaborator Author

Snuffleupagus commented Feb 17, 2020

[...] but I'm wondering how we should document the availability of this (and other) features for third-party users. There are quite a few tips and tricks third-party implementers can use, but we don't really document them nor do we have examples for all of them.

That seems like a fair point!

As long as any documentation prominently features the standard "please don't use the viewer as-is"-disclaimer, then I suppose that more documentation cannot hurt.

Furthermore, you'd probably also need to make it very clear that while the general PDF.js library is versioned and shouldn't simply break in backwards incompatible ways (the latter probably applies to some extent to the "viewer components" too), the default viewer itself shouldn't be considered completely stable and things may change/break as required for e.g. Firefox's needs.

I'm thinking a wiki page could suffice and we can update it incrementally.

That sounds like the easiest solution, and shouldn't be too much effort to keep up-to-date.

@timvandermeij timvandermeij merged commit e2b30e9 into mozilla:master Feb 18, 2020
@timvandermeij
Copy link
Contributor

Nice improvement! I have made https://github.com/mozilla/pdf.js/wiki/Third-party-viewer-usage to track tips and tricks for custom viewer deployments. If you have additions, feel free to let me know and we can update the page.

@Snuffleupagus Snuffleupagus deleted the app-initializedPromise branch February 18, 2020 23:08
robertknight added a commit to hypothesis/browser-extension that referenced this pull request Sep 17, 2021
 - Remove the `eventBusDispatchToDOM` option, as the client now watches
   for these events on the event bus. See [1].
 - Use `PDFViewerApplication.initializedPromise` to simplify waiting for
   app to load. This was added in PDF.js v2.10.377. See [2].

[1] hypothesis/client#2641
[2] mozilla/pdf.js#11607
robertknight added a commit to hypothesis/browser-extension that referenced this pull request Sep 20, 2021
 - Remove the `eventBusDispatchToDOM` option, as the client now watches
   for these events on the event bus. See [1].
 - Use `PDFViewerApplication.initializedPromise` to simplify waiting for
   app to load. This was added in PDF.js v2.10.377. See [2].

[1] hypothesis/client#2641
[2] mozilla/pdf.js#11607
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants