Skip to content

Refactor EPUB navigation: use jumpTo instead of gotoEpubCfi#213

Open
Quinver wants to merge 3 commits into
JellyBookOrg:mainfrom
Quinver:save-chapter-index
Open

Refactor EPUB navigation: use jumpTo instead of gotoEpubCfi#213
Quinver wants to merge 3 commits into
JellyBookOrg:mainfrom
Quinver:save-chapter-index

Conversation

@Quinver
Copy link
Copy Markdown
Contributor

@Quinver Quinver commented Dec 11, 2025

Problem:

  • The existing gotoEpubCfi approach didn't reliably jump to the saved position in my testing.

Solution:

  • Refactored to save the chapter index instead and use jumpTo(index) to restore the last read position.
  • This works consistently in my tests and preserves the "resume where you left off" functionality.

Notes:

  • I wasn't able to make gotoEpubCfi work reliably, so this is an alternative approach.
  • Happy to adjust if maintainers prefer another method.

Also fixes issue #203.

Copy link
Copy Markdown
Member

@Kara-Zor-El Kara-Zor-El left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks good overall, just fix up in a few areas

Comment thread lib/screens/readingScreens/epubReader.dart Outdated
Comment thread lib/screens/readingScreens/epubReader.dart Outdated
Comment on lines +318 to +321
logger.d("Restoring chapter index: $savedIndex");
Future.delayed(Duration(milliseconds: 500), () {
_epubController.jumpTo(index: savedIndex);
});
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i don't actually remember why i had it wait 5 seconds (assuming its to let the book load). If possible can we instead have this done on a hook once the book loads?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not entirely sure how to implement it as a hook yet, but I’ve resolved the delay issue as mentioned in my comment below. I might look into adding a proper hook later once I’ve had a deeper dive into the codebase.

Comment on lines +205 to +219
Future<void> onBookLoaded() async {
// Restore saved chapter index
final savedIndex = await loadChapterIndex();
if (savedIndex != null) {
logger.d("Restoring chapter index: $savedIndex");

// Wait for frame to fully load
WidgetsBinding.instance.addPostFrameCallback((_) {
_epubController.jumpTo(index: savedIndex);
});
}

// Add other book loaded tasks here
logger.d("Book is fully loaded");
}
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added helper function to run actions after book frame is fully rendered

This should reliably handle tasks that depend on the book being fully loaded,
fixing issues where onDocumentLoaded fires before the UI is ready.

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