mod: restore missing mod features from resync audit

Re-add KOReaderSyncActivity PUSH_ONLY mode (PR #1090):
- SyncMode enum with INTERACTIVE/PUSH_ONLY, deferFinish pattern
- Push & Sleep menu action in EpubReaderMenuActivity
- ActivityManager::requestSleep() for activity-initiated sleep
- main.cpp checks isSleepRequested() each loop iteration

Wire EndOfBookMenuActivity into EpubReaderActivity:
- pendingEndOfBookMenu deferred flag avoids render-lock deadlock
- Handles all 6 actions: ARCHIVE, DELETE, TABLE_OF_CONTENTS,
  BACK_TO_BEGINNING, CLOSE_BOOK, CLOSE_MENU

Add book management to reader menu:
- ARCHIVE_BOOK, DELETE_BOOK, REINDEX_BOOK actions with handlers

Port silent next-chapter pre-indexing:
- silentIndexNextChapterIfNeeded() proactively indexes next chapter
  when user is near end of current one, eliminating load screens

Add per-book letterbox fill toggle in reader menu:
- LETTERBOX_FILL cycles Default/Dithered/Solid/None
- Loads/saves per-book override via BookSettings
- bookCachePath constructor param added to EpubReaderMenuActivity

Made-with: Cursor
This commit is contained in:
cottongin
2026-03-07 16:53:17 -05:00
parent 60a3e21c0e
commit 9464df1727
12 changed files with 422 additions and 11 deletions

View File

@@ -0,0 +1,50 @@
# Fresh Replay: Sync mod/master with upstream/master (continued)
## Task
Continue the "Fresh Replay" synchronization of mod/master with upstream/master (HEAD: 170cc25). This session picked up from Phase 2c (GfxRenderer/theme modifications) and completed through Phase 4 (verification).
## Changes Made
### Phase 2c-e: GfxRenderer, themes, SleepActivity, SettingsActivity, platformio
- Added `drawPixelGray` to GfxRenderer for letterbox fill rendering
- Added `PRERENDER_THUMB_HEIGHTS` to UITheme for placeholder cover generation
- Added `[env:mod]` build environment to platformio.ini
- Implemented sleep screen letterbox fill (solid/dithered) with edge caching in SleepActivity
- Added placeholder cover fallback (PlaceholderCoverGenerator) for XTC/TXT/EPUB sleep screens
- Added Clock settings category to SettingsActivity with timezone, NTP sync, set-time actions
- Replaced CalibreSettingsActivity with OpdsServerListActivity for OPDS server management
- Added DynamicEnum rendering support for settings
- Added long-press book management to RecentBooksActivity
### Phase 3: Re-port unmerged upstream PRs
- **#1055** (byte-level framebuffer writes): fillPhysicalHSpan*, optimized fillRect/drawLine/fillRectDither/fillPolygon
- **#1027** (word-width cache): 128-entry FNV-1a cache, hyphenation early exit (7-9% layout speedup)
- **#1068** (URL hyphenation): Already present in upstream
- **#1019** (file extensions in browser): Already present in upstream
- **#1090/#1185/#1217** (KOReader sync): Binary credential store, document hash caching, ChapterXPathIndexer
- **#1209** (OPDS multi-server): OpdsBookBrowserActivity accepts OpdsServer, directory picker, download-complete prompt
- **#857** (Dictionary): Activities already ported in Phase 1/2
- **#1003** (Placeholder covers): Already integrated in Phase 2
### Fixes
- Added `STR_OFF` i18n string for clock format setting
- Fixed include paths (ActivityResult.h from subdirectories)
- Replaced `Epub::isValidThumbnailBmp` with `Storage.exists()` (method doesn't exist in upstream)
- Replaced `StringUtils::checkFileExtension` with `FsHelpers` equivalents
### Image pipeline decision
- Kept upstream's JPEGDEC implementation — mod's picojpeg was a workaround for the older codebase
- No mod-specific image pipeline changes needed
## Branch Status
- **mod/master-resync**: 6 commits ahead of upstream/master (170cc25)
- **mod/backup-pre-sync-2026-03-07**: Safety snapshot of original mod/master
- 189 files changed, ~114,566 insertions, ~379 deletions vs upstream
## Follow-up Items
- Run full PlatformIO build on hardware to verify compilation
- Run clang-format on all modified files
- Test on device: clock display, sleep screen letterbox fill, dictionary, OPDS browsing
- KOReaderSyncActivity PUSH_ONLY mode (from PR #1090) not yet re-added to activity
- Consider adding `StringUtils.h` if other mod code needs `checkFileExtension`
- Update mod version string

View File

@@ -0,0 +1,42 @@
# KOReaderSyncActivity PUSH_ONLY Mode Re-addition
**Date**: 2026-03-07
**Branch**: `mod/master-resync`
## Task
Re-add the `PUSH_ONLY` sync mode to `KOReaderSyncActivity` that was lost during the upstream resync/ActivityManager migration (originally from PR #1090). This mode allows the reader to silently push local progress to the KOReader sync server and then enter deep sleep — no interactive UI.
## Changes
### `src/activities/reader/KOReaderSyncActivity.h`
- Added `enum class SyncMode { INTERACTIVE, PUSH_ONLY }` to the class
- Added `syncMode` constructor parameter (defaults to `INTERACTIVE`)
- Added `deferFinish(bool success)`, `pendingFinish`, `pendingFinishSuccess` for safe async finish from blocking calls
### `src/activities/reader/KOReaderSyncActivity.cpp`
- Implemented `deferFinish()` — sets a flag that `loop()` picks up to call `setResult()`/`finish()`
- `onEnter()`: In PUSH_ONLY mode, silently finish if no credentials (no error UI)
- `performSync()`: In PUSH_ONLY mode, skip remote fetch entirely and go straight to `performUpload()`
- `performUpload()`: In PUSH_ONLY mode, use `deferFinish()` instead of setting UI state on success/failure
- `loop()`: Check `pendingFinish` first and perform deferred finish if set
### `src/activities/ActivityManager.h`
- Added `requestSleep()` / `isSleepRequested()` — allows activities to signal that the device should enter deep sleep. Checked by the main loop.
### `src/main.cpp`
- Added `activityManager.isSleepRequested()` check in the main loop, before the auto-sleep timeout check
### `src/activities/reader/EpubReaderMenuActivity.h` / `.cpp`
- Added `PUSH_AND_SLEEP` to the `MenuAction` enum
- Added menu item `{PUSH_AND_SLEEP, STR_PUSH_AND_SLEEP}` between SYNC and CLOSE_BOOK
### `src/activities/reader/EpubReaderActivity.cpp`
- Added `#include "activities/ActivityManager.h"`
- Added `PUSH_AND_SLEEP` case in `onReaderMenuConfirm`: launches `KOReaderSyncActivity` in `PUSH_ONLY` mode, then calls `activityManager.requestSleep()` on completion (regardless of success/failure)
### `lib/I18n/translations/english.yaml` / `lib/I18n/I18nKeys.h`
- Added `STR_PUSH_AND_SLEEP: "Push & Sleep"` and regenerated I18n keys
## Follow-up Items
- None

View File

@@ -0,0 +1,61 @@
# Missing Mod Features Audit — Implementation
**Date**: 2026-03-07
**Branch**: `mod/master-resync`
## Task
Comprehensive audit of `mod/master-resync` vs `mod/backup-pre-sync-2026-03-07` identified 4 mod features lost during the upstream resync. All 4 have been re-implemented.
## Changes
### 1. EndOfBookMenuActivity wired into EpubReaderActivity (HIGH)
**Files**: `EpubReaderActivity.h`, `EpubReaderActivity.cpp`
- Added `pendingEndOfBookMenu` and `endOfBookMenuOpened` flags
- In `render()`: when reaching end-of-book, sets `pendingEndOfBookMenu = true` (deferred to avoid render-lock deadlock)
- In `loop()`: checks flag and launches `EndOfBookMenuActivity` via `startActivityForResult`
- Result handler covers all 6 actions: ARCHIVE (→ goHome), DELETE (→ goHome), TABLE_OF_CONTENTS (→ last chapter), BACK_TO_BEGINNING (→ spine 0), CLOSE_BOOK (→ goHome), CLOSE_MENU (→ stay at end)
- Added `#include "EndOfBookMenuActivity.h"` and `#include "util/BookManager.h"`
### 2. Book management from reader menu (MEDIUM)
**Files**: `EpubReaderMenuActivity.h`, `EpubReaderMenuActivity.cpp`, `EpubReaderActivity.cpp`
- Added `ARCHIVE_BOOK`, `DELETE_BOOK`, `REINDEX_BOOK` to `MenuAction` enum
- Added corresponding menu items between CLOSE_BOOK and DELETE_CACHE
- Added handlers in `onReaderMenuConfirm`: each calls `BookManager::archiveBook/deleteBook/reindexBook` then `activityManager.goHome()`
### 3. Silent next-chapter pre-indexing (MEDIUM)
**Files**: `EpubReaderActivity.h`, `EpubReaderActivity.cpp`
- Added `preIndexedNextSpine` field and `silentIndexNextChapterIfNeeded()` method
- Triggers when user is on second-to-last or last page of a chapter
- Creates section file for `currentSpineIndex + 1` in advance
- Called after every page turn in `loop()`
- ~35 lines of self-contained implementation
### 4. Letterbox fill toggle in reader menu (LOW)
**Files**: `EpubReaderMenuActivity.h`, `EpubReaderMenuActivity.cpp`, `EpubReaderActivity.cpp`
- Added `LETTERBOX_FILL` to `MenuAction` enum
- Added `bookCachePath` constructor parameter (with default `""` for backward compat)
- Added per-book `pendingLetterboxFill`, `letterboxFillLabels`, `letterboxFillToIndex()`, `indexToLetterboxFill()`, `saveLetterboxFill()`
- Cycles Default → Dithered → Solid → None → Default on Confirm
- Renders current value on right edge of menu item
- Loads/saves per-book setting via `BookSettings`
- Updated call site in `EpubReaderActivity` to pass `epub->getCachePath()`
## Audit False Positives (confirmed NOT gaps)
- GfxRenderer kerning/ligatures/wrappedText — present on resync
- HttpDownloader auth fallback — present with OPDS settings fallback
- Lyra3CoversTheme — exists on resync
- ActivityWithSubactivity → Activity migration — intentional upstream change
- EndOfBookMenuActivity callbacks → setResult/finish — correctly migrated
## Follow-up Items
- None