btpf / Alexandria

A minimalistic cross-platform eBook reader built with Tauri, Epub.js, and Typescript
GNU General Public License v3.0
2.07k stars 42 forks source link

Delay loading of `percentageFromCfi` until `displayedCFI` is ready. #49

Closed Neulus closed 5 days ago

Neulus commented 2 weeks ago

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

btpf commented 5 days ago

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.

https://github.com/btpf/Alexandria/pull/49/commits/24a6b4dca075753a7102c0e77c2c50e25a8f4743#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!