Skip to content

Re-run OCR immediately when the OCR source changes - #84

Open
bee-san wants to merge 1 commit into
sohilsayed:mainfrom
bee-san:feat/ocr-source-auto-run
Open

Re-run OCR immediately when the OCR source changes#84
bee-san wants to merge 1 commit into
sohilsayed:mainfrom
bee-san:feat/ocr-source-auto-run

Conversation

@bee-san

@bee-san bee-san commented Jul 29, 2026

Copy link
Copy Markdown
Contributor

Follow-up to #81.

Problem

Changing the OCR source from the long-press menu on the reader OCR action didn't visibly do anything. setOcrSource() stored the preference, cancelled the in-flight scan and cleared ocrScannedChapterIds, but nothing started a new scan — the chapter-wide OCR pass only restarts from onPageSelected -> scanOcrPages(). So picking Google Lens while sitting on a page left the reader idle until the user swiped.

Fix

setOcrSource() now restarts the scan for the currently selected page right away, when the OCR overlay is enabled:

if (isOcrEnabled()) {
    getSelectedReaderPage()?.let { scanOcrPages(it) }
}

This mirrors what the existing ocrOverlayEnabled().changes() collector already does when OCR is toggled on.

Note the visible page was already being re-OCR'd by the setOcrEnabled(false) / setOcrEnabled(true) dance in ReaderActivity.selectOcrSourceFromReader. What was missing is the chapter-wide background rescan under the new source (and its progress HUD), which is what this restores. No duplicate network work: both paths go through getOcrBlocks(), which dedupes concurrent fetches via ocrInFlight keyed on (chapterId, pageIndex, ocrSource).

Drive-by

ReaderOcrSourceTest.availableSources() was still calling the old single-argument signature and doesn't compile on main#81 added the mokuroAvailable parameter to ReaderOcrSource.availableSources() but didn't update the test. One call site, two arguments. Without this testReleaseUnitTest fails to compile, so it's included here rather than left broken.

Verification

  • ./gradlew testReleaseUnitTest — passes (fails to compile on main without the test fix above)

Changing the reader OCR source (e.g. Automatic -> Google Lens) updated the
stored preference and cleared the scan state, but nothing kicked off a new
scan. The chapter-wide OCR pass only restarted on the next page change, so
the source switch appeared to do nothing until the user swiped.

setOcrSource() now restarts the scan for the current page right away when
the OCR overlay is enabled.

Also fixes the ReaderOcrSourceTest call to availableSources(), which was
left with the old single-argument signature and does not compile.
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