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

Delay loading of percentageFromCfi until displayedCFI is ready. #49

Merged
merged 1 commit into from
Jul 14, 2024

Conversation

Neulus
Copy link
Contributor

@Neulus Neulus commented Jul 5, 2024

When loading a .txt file, I observed that percentageFromCfi is invoked with displayedCFI before displayedCFI is fully initialized. This premature loading can cause issues similar to those reported in #47.

Changes

  • Added a check to ensure displayedCFI is loaded before invoking percentageFromCfi.

@btpf
Copy link
Owner

btpf commented Jul 14, 2024

Nice job tracking it down.

I think a small change I would prefer is just setting the currentPercentage to 0 if the displayedCFI is not ready.

24a6b4d#diff-5fbaa34ea6def579f01b427ae5834cbdd8811adc65b5fa7cd82520e075eabb7eR110-R114
to just

  // wait until displayedCFI is loaded
  const currentPercentage = displayedCFI ? renditionInstance?.book.locations.percentageFromCfi(displayedCFI):0

Ill merge this in and make the changes. Thanks!

@btpf btpf merged commit d3885dc into btpf:main Jul 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants