Add Global Bookmark feature

This commit is contained in:
jpirnay
2026-04-15 09:32:52 +02:00
parent f7bf43d39b
commit 2f4cea3706
19 changed files with 737 additions and 8 deletions
@@ -18,6 +18,7 @@
#include "EpubReaderChapterSelectionActivity.h"
#include "EpubReaderFootnotesActivity.h"
#include "EpubReaderPercentSelectionActivity.h"
#include "GlobalBookmarkIndex.h"
#include "KOReaderCredentialStore.h"
#include "MappedInputManager.h"
#include "QrDisplayActivity.h"
@@ -93,6 +94,7 @@ void EpubReaderActivity::onEnter() {
epub->setupCacheDir();
applyPendingSyncSession();
applyPendingBookmarkJump();
FsFile f;
if (Storage.openFileForRead("ERS", epub->getCachePath() + "/progress.bin", f)) {
@@ -145,6 +147,9 @@ void EpubReaderActivity::onExit() {
// Save bookmarks before exit
bookmarkStore.save();
if (epub) {
GLOBAL_BOOKMARKS.syncFromStore(bookmarkStore, epub->getPath(), epub->getCachePath(), epub->getTitle(), false);
}
// Reset orientation back to portrait for the rest of the UI
renderer.setOrientation(GfxRenderer::Orientation::Portrait);
@@ -560,6 +565,8 @@ void EpubReaderActivity::onReaderMenuConfirm(EpubReaderMenuActivity::MenuAction
if (!bookmarkStore.isEmpty()) {
bookmarkStore.markDirty();
bookmarkStore.save();
GLOBAL_BOOKMARKS.syncFromStore(bookmarkStore, epub->getPath(), epub->getCachePath(), epub->getTitle(),
false);
}
}
}
@@ -689,6 +696,25 @@ void EpubReaderActivity::applyPendingSyncSession() {
logReaderMemSnapshot("after_apply_pending_sync_session");
}
void EpubReaderActivity::applyPendingBookmarkJump() {
auto& jump = APP_STATE.pendingBookmarkJump;
if (!jump.active || !epub || jump.bookPath != epub->getPath()) {
return;
}
LOG_DBG("ERS", "Applying pending bookmark jump: spine=%u page=%u", jump.spineIndex, jump.pageNumber);
if (writeReaderProgressCache(epub->getCachePath(), jump.spineIndex, jump.pageNumber, 0)) {
cachedSpineIndex = jump.spineIndex;
cachedChapterTotalPageCount = 0;
} else {
currentSpineIndex = jump.spineIndex;
nextPageNumber = jump.pageNumber;
cachedSpineIndex = jump.spineIndex;
cachedChapterTotalPageCount = 0;
}
jump.clear();
APP_STATE.saveToFile();
}
void EpubReaderActivity::applyOrientation(const uint8_t orientation) {
// No-op if the selected orientation matches current settings.
if (SETTINGS.orientation == orientation) {
@@ -80,6 +80,10 @@ class EpubReaderActivity final : public Activity {
// reader startup path reads it. Upload-complete leaves the existing local
// progress.bin untouched and simply clears the pending session marker.
void applyPendingSyncSession();
// Consume a persisted bookmark-jump request (from GlobalBookmarksActivity) for
// this book. Rewrites progress.bin to the bookmarked position before the normal
// reader startup path reads it.
void applyPendingBookmarkJump();
void applyOrientation(uint8_t orientation);
void applyTextDarkness(uint8_t textDarkness);
void toggleAutoPageTurn(uint8_t selectedPageTurnOption);
@@ -9,6 +9,7 @@
#include "CrossPointSettings.h"
#include "CrossPointState.h"
#include "GlobalBookmarkIndex.h"
#include "MappedInputManager.h"
#include "ReaderUtils.h"
#include "RecentBooksStore.h"
@@ -99,6 +100,7 @@ void TxtReaderActivity::onEnter() {
}
txt->setupCacheDir();
applyPendingBookmarkJump();
// Load bookmarks for this file
bookmarkStore.load(txt->getCachePath());
@@ -119,6 +121,9 @@ void TxtReaderActivity::onExit() {
// Save bookmarks before exit
bookmarkStore.save();
if (txt) {
GLOBAL_BOOKMARKS.syncFromStore(bookmarkStore, txt->getPath(), txt->getCachePath(), txt->getTitle(), true);
}
// Reset orientation back to portrait for the rest of the UI
renderer.setOrientation(GfxRenderer::Orientation::Portrait);
@@ -427,6 +432,26 @@ void TxtReaderActivity::saveProgress() const {
}
}
void TxtReaderActivity::applyPendingBookmarkJump() {
auto& jump = APP_STATE.pendingBookmarkJump;
if (!jump.active || !txt || jump.bookPath != txt->getPath()) {
return;
}
LOG_DBG("TRS", "Applying pending bookmark jump: page=%u", jump.pageNumber);
FsFile f;
if (Storage.openFileForWrite("TRS", txt->getCachePath() + "/progress.bin", f)) {
uint8_t data[6] = {0};
data[0] = jump.pageNumber & 0xFF;
data[1] = (jump.pageNumber >> 8) & 0xFF;
// Offset bytes stay 0: loadProgress reads only the page, and the lazy
// initializeReader() rebuilds the page index on first render anyway.
f.write(data, 6);
f.close();
}
jump.clear();
APP_STATE.saveToFile();
}
void TxtReaderActivity::loadProgress() {
FsFile f;
if (Storage.openFileForRead("TRS", txt->getCachePath() + "/progress.bin", f)) {
@@ -46,6 +46,9 @@ class TxtReaderActivity final : public Activity {
void savePageIndexCache() const;
void saveProgress() const;
void loadProgress();
// Consume a persisted bookmark-jump request (from GlobalBookmarksActivity) for
// this TXT file. Rewrites progress.bin before initializeReader() reads it.
void applyPendingBookmarkJump();
public:
explicit TxtReaderActivity(GfxRenderer& renderer, MappedInputManager& mappedInput, std::unique_ptr<Txt> txt)