Skip to content

fix(reader): 恢复 PDF 打开时的阅读进度 - #783

Open
jenken827 wants to merge 1 commit into
codedogQBY:mainfrom
jenken827:fix/pdf-progress-restore
Open

jenken827 wants to merge 1 commit into
codedogQBY:mainfrom
jenken827:fix/pdf-progress-restore

Conversation

@jenken827

Copy link
Copy Markdown

问题

PDF(及 CBZ 等固定版式)书籍每次打开都从第一页开始,不论上次读到哪里。EPUB 恢复正常。

根因

打开书籍的初始化流程中,固定版式分支被硬编码丢弃了上次阅读位置:

if (isFixedLayout) {
  await view.init({});              // ← PDF:lastLocation 被丢弃
} else if (lastLocation) {
  await view.init({ lastLocation }); // ← EPUB:正常恢复
}

保存侧完全正常(books.current_cfi 正确存储页级定位 epubcfi(/6/N)),只是打开时未使用。

修复

固定版式分支同样将 lastLocation 传入 view.init。PDF 的页级 fake CFI(epubcfi(/6/N))可通过 PDF 后端的 resolveCFI 解析回对应页,与注释/书签跳转使用同一套已验证机制。

验证

  • 打开 PDF 翻至第 5 页 → 关书重开 → 正确恢复第 5 页;
  • 翻至第 8 页 → 直接关闭应用窗口 → beforeunload 兜底保存 → 重启应用打开 → 恢复第 8 页;
  • core 全量 584 个单元测试通过。

注:本次代码修改和PR信息由AI生成

Fixed-layout books (PDF/CBZ) always opened at the beginning: the open
flow called view.init({}) for fixed layout, deliberately(?) discarding
the lastLocation prop — so the saved position (books.current_cfi, e.g.
epubcfi(/6/16) for page 8) was never applied on open, while EPUB
restored fine through the sibling branch.

The fake page CFI (epubcfi(/6/N)) that the save side stores resolves
through the PDF backend's resolveCFI back to the recorded page, so
passing lastLocation to view.init restores the exact page. Verified
end-to-end on dev: read to page 5, close book, reopen -> page 5;
close app mid-read -> position flushed via beforeunload -> reopen ->
restored.

Also drops the temporary [RelocateDiag] probe logs.
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.

1 participant