Commit graph

3400 commits

Author SHA1 Message Date
Huang Xin
052bbc8e77
feat(library): remove selected books from the device only (#7324)
* feat(library): remove selected books from the device only (#7318)

Bulk delete in selection mode always deleted from cloud and device; the
device-only removal was only in Book Details, one book at a time. The
bulk delete confirmation now has a "Remove from Device Only" toggle. It
runs the existing local delete for the selected books that have a cloud
copy (or an Audiobookshelf offline download) and skips the rest, so a
bulk action never leaves a book with no copy anywhere. With it on, the
purge toggle and the delete message are hidden and the button reads
"Remove".

Verified:
- Tests written first. Before the change, library-utils.test.ts failed
  with "canRemoveFromDeviceOnly is not a function" and
  DeleteConfirmAlert.test.tsx with "Unable to find ... checkbox
  'Remove from Device Only'"; the hidden-message check failed with
  "expected <div class="text-start text-sm"></div> to be null". All
  pass now (176 tests across library-utils, DeleteConfirmAlert,
  Bookshelf and BookDetailModal), plus alert-width-stability browser
  test (3 tests).
- pnpm lint and pnpm format:check clean.
- dev-web with Playwright on a fresh profile: imported 3 EPUBs, gave 2
  a stand-in cloud copy (uploadedAt), selected all 9 books, turned the
  toggle on and confirmed. The 2 lost their local file and
  downloadedAt and stayed in the library; the local-only book and the
  demo books were untouched. Dialog checked in light, dark, e-ink
  (data-eink), RTL and at 390 px.
- Not run: a real cloud account (the cloud copy was faked), native
  desktop/Android/iOS builds, and confirming the toggle-off Delete path
  in the app (covered by the unit test).

Reported by poife on GitHub.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* fix(library): keep Enter on a delete toggle and a cancelled delete from misfiring

Two CodeRabbit findings on #7324:
- Alert confirms on any Enter, so Enter on the focused "Remove from Device
  Only" toggle ran a cloud-and-device delete. Enter on a toggle now flips
  it instead (capture phase, ahead of Alert's listener).
- Cancel set the abort flag even with no deletion running, so the next
  confirmed bulk delete stopped before its first batch and deleted
  nothing. runDeletion now clears the flag when it starts.

Verified:
- DeleteConfirmAlert.test.tsx "toggles instead of confirming when Enter
  is pressed on a toggle" failed before the fix with 'expected "vi.fn()"
  to not be called at all, but actually been called 1 times'.
- library.test.tsx "deletes the books after an earlier delete
  confirmation was cancelled" failed before the fix with 'expected
  "vi.fn()" to be called 2 times, but got 0 times'.
- Both pass now, with 178 tests across the four related suites and the
  alert-width browser test; pnpm lint and pnpm format:check clean.
- dev-web with Playwright: Cancel, reopen, focus the toggle, press Enter:
  the toggle turned on and the dialog stayed open; Remove then dropped
  the local files of the 2 books with a cloud copy.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* fix(library): keep each bulk deletion's cancel to its own run

CodeRabbit on #7324: clearing a shared abort flag at the start of a run
let a cancelled run continue with its remaining batches when a new
deletion started before its current batch finished, and the old run
could then close the newer alert. Each run now takes a token; Cancel and
any newer run make it stale, so it stops before its next batch and leaves
the alert alone. Also fixes the Romanian plural forms of the new string
("al 1 carte" was ungrammatical).

Verified:
- library.test.tsx "stops a cancelled deletion even when another one
  starts before its batch ends" failed before the fix with 'expected
  "vi.fn()" to be called 21 times, but got 41 times' and passes now; 179
  tests across the four related suites pass; pnpm lint and
  pnpm format:check clean.
- dev-web with Playwright: Cancel, reopen, Enter on the toggle, Remove
  still drops the local files of the 2 books with a cloud copy.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-04 15:29:12 +01:00
Huang Xin
8e2270aba4
feat(tts): preview voices and pick a default voice per language (#7322)
Some checks are pending
CodeQL Advanced / Analyze (actions) (push) Waiting to run
CodeQL Advanced / Analyze (javascript-typescript) (push) Waiting to run
CodeQL Advanced / Analyze (rust) (push) Waiting to run
Publish Docker image / build (linux/amd64, ubuntu-latest) (push) Waiting to run
Publish Docker image / build (linux/arm64, ubuntu-24.04-arm) (push) Waiting to run
Publish Docker image / merge (push) Blocked by required conditions
Build with Nix / tests (push) Waiting to run
PR checks / koplugin_rust_lint (push) Waiting to run
PR checks / nix_flake_check (push) Waiting to run
PR checks / rust_lint (push) Waiting to run
PR checks / build_web_app (push) Waiting to run
PR checks / test_web_app (1) (push) Waiting to run
PR checks / test_web_app (2) (push) Waiting to run
PR checks / test_web_browser (push) Waiting to run
PR checks / test_extensions (push) Waiting to run
PR checks / build_tauri_app (push) Waiting to run
Scorecard supply-chain security / Scorecard analysis (push) Waiting to run
Deploy to vercel on merge / build_and_deploy (push) Waiting to run
* feat(tts): preview voices and pick a default voice per language

Settings > TTS gets a Voice Library page, and the player's voice list
is rebuilt on the same component (VoiceList). Each row shows the
voice's gender, its language and region, and a play button.

- Opened from the library, the page lists every language that has
  voices, with a gender filter. Previews read a sample sentence in the
  voice's language (75 languages, gender-neutral wording).
- With a book open, only the book language's voices are listed, and
  previews read whole sentences from the start of the current page:
  at least 5 s of estimated speech, at most 400 characters.
- Choosing a voice in Settings makes it the default for that language
  only. Picking one in the player sets that language's default too, and
  TTSController switches to a language's engine when the reading
  language changes.
- In the player, a preview pauses reading. Picking the voice just
  heard resumes reading with it; leaving the list keeps it paused.
- Readest Voice previews need a signed-in reader; the other engines
  don't. /api/tts/readest/stream takes a `preview` lane: any signed-in
  plan, any offered voice, one segment of at most 400 characters, and a
  6,000-character daily floor for plans without Readest Voice. The
  voice service sees an ordinary listening window under its own client
  id, so its contract is unchanged.
- Gender comes from a generated map for Edge, from the voice id for
  Kokoro voices (Readest Voice and custom services), and from
  AVSpeechSynthesisVoice on iOS. Android and Web Speech report none, so
  those rows have no badge.
- The Voice Library lists Linux Speech Dispatcher voices (#7314) as it
  does Android and iOS system voices.

Tests that fail without the change (old file put back, new test run):
- tts-readest-stream-route.test.ts: 6 preview tests, e.g. "expected
  403 to be 200" and "expected { error: 'PLAN_REQUIRED' } to deeply
  equal { error: 'VOICE_TIER_REQUIRED' }".
- tts-controller-readest.test.ts: 4 tests on the per-language engine,
  e.g. "expected Mock{ name: 'edge-tts', ... } to be Mock{ name:
  'readest-tts', ... }".
- edgeTTS.test.ts: "expected undefined to be 'female'";
  readest-voice-catalog.test.ts: 2 gender tests.
- useTTSControl.test.tsx: "reads on with the new voice when asked to,
  though reading is stopped" fails with "expected vi.fn() to be called
  at least once".
- tts-voice-library.test.ts, Linux: "expected [] to deeply equal
  [ 'de' ]".

Checks on this tree, rebased on origin/main 6ab667bd2: pnpm test (15365
passed, 16 skipped), pnpm test:browser (934 passed, 1 skipped), pnpm
lint, pnpm format:check, pnpm fmt:check, pnpm clippy:check, pnpm
test:rust (206 passed).

Real use, macOS tauri dev build (before the rebase onto 6ab667bd2,
which changed only the native client and the library's platform list):
- Edge previews synthesized in about 2 s and played 7-12 s samples to
  the end. A macOS system voice spoke its sample. Starting a second
  preview stopped the first.
- In a German EPUB, the Voice Library listed only German voices and
  the preview read the page's heading and first sentence.
- Player: reading, then preview, then picking the voice resumed reading
  with it. Preview, then back, left reading paused until Play.
- Both screens in dark, light, e-ink, RTL and phone width.
- Found while testing: WebKit could not decode the 1-sample silent WAV
  that unlocks autoplay; previews now prime with a 0.1 s clip.

Not run:
- A Readest Voice preview end to end: a dev origin can't reach the
  production voice service, so the route tests cover the lane. Apps can
  preview Readest voices once the web server is deployed.
- iOS (the Swift change was only parsed), Android, and Linux previews.
- OmniVoice voices have no gender badge until the readest-voice catalog
  export adds a gender field.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* test(tts): page preview text from a section document without a root

CodeRabbit asked for a guard in textFromBlock for a section document
that a remount left without a root, where createTreeWalker(null) would
throw and leave the preview button loading. The reader's progress
range is a live Range (foliate builds it with doc.createRange()), so
removing the root collapses it onto the document. closestBlock() then
finds no block, getPagePreviewText() returns null before any tree
walker is made, and the preview reads the sample text instead.

The new test removes a page's root and checks that the range now sits
on the document and that the preview text is null. jsdom throws
"parameter 1 is not of type 'Node'" for createTreeWalker(null), so the
test fails if the walker is ever reached in that state.

Checks: tts-voice-preview-text.test.ts (7 passed); the pre-push hook
runs format:check, lint and the full suite on this commit.

Raised by CodeRabbit on #7322.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-04 13:37:48 +01:00
Huang Xin
d5a249e7eb
fix(reader): reach the last page when a book ends partway into a spread (#7320)
* fix(reader): reach the last page when a book ends partway into a spread

Sections are sized by columns so the next one can start beside the
previous one's end. The book's last section has no next section, so in a
two-column layout the book could end on the left column of a spread, and
the paginator's scroll container stopped half a spread short. The final
spread showed the column before the last one again. With fractional page
widths, as under Windows display scaling, the reader either never reached
the end (the counter stayed at 1443 / 1447) or stopped a page early and
never showed the last column.

foliate-js (readest/foliate-js#147) now pads the views to whole pages and
counts a partial last page as a page.

Fixes #7303. Reported by gonwan on GitHub.

Verification:
- paginator-last-page.browser.test.ts turns pages to the end of 5-column
  and 3+4-column books, LTR, RTL and vertical-rl, at page sizes 1000,
  1003.3, 1011.1 and 1017.9. With main's foliate-js all 16 cases fail
  (`expected 974.140625 to be less than 472.1015625`, `expected false to
  be true` on atEnd); with the change all pass.
- The 27 browser suites that load the paginator pass (196 tests), as do
  the jsdom paginator suites. pnpm lint and pnpm format:check pass.
- dev-web, Playwright Chromium at DPR 1.25, the reporter's EPUB, last
  chapter turned to the end at 39 window widths: main failed 12 (at 1681
  the last ~14 paragraphs were never shown while the counter read
  1447 / 1447); the change passes all 39, with Use Book Layout on and off,
  and in dark mode.
- Not run: Windows WebView2 itself, iOS/macOS WebKit, Android.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* test(reader): bound the right edge of the last right-to-left column

The right-to-left case checked only where the last column starts, so a
column running off the right edge of the page would still pass. It now
checks the column's right edge stays within the page.

Verified: the 16 last-page browser tests pass with the fix; with
foliate-js at main (2e4dbc1) the four right-to-left cases fail
("expected false to be true", "expected -442 to be greater than or
equal to 471.1015625"). Biome and tsc are clean.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* chore(deps): pin foliate-js to the merged paginator fix (#147)

Moves the submodule from the PR branch commit 86e5d61 to c14f30c, the
squash of readest/foliate-js#147 on foliate-js main. The trees are
identical (`git diff 86e5d61 c14f30c` is empty).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-04 13:37:19 +01:00
Huang Xin
2d75e0937b
fix(sync): give HTML chapter files their own sync identity (#7321)
* fix(sync): give HTML chapter files their own sync identity

Web-novel downloaders such as the legado and moon KOReader plugins save
each chapter as its own HTML file under the book's title and author. The
metadata hash, which syncs reading progress across devices, then matched
every chapter of the book, so opening a new chapter could pull the
previous chapter's position. #7231 does not cover this: a chapter opened
for the first time has no save of its own, so a sibling's newer position
still wins.

HTML files (.html, .htm, .xhtml, .xhtm, .mhtml, .mht) now salt the meta
hash with the base filename, as PDFs already do (#5411), in both the
KOReader plugin and the app. The app keeps the salted hash from import
and never recomputes it on a metadata refresh. Files already opened keep
their cached hash; chapters opened after the update get their own.

Verified:
- Tests that fail without the fix:
  - spec/syncconfig_spec.lua "gives per-chapter HTML files of one book
    distinct hashes": expected 'Sword Coming|Fenghuo Xizhuhou||0001',
    got the hash source without the filename.
  - import-metahash.test.ts "imports HTML chapters with identical
    metadata as separate books" (expected the salted hash, got the
    shared one) and "refreshBookMetadata preserves the salted metaHash
    for HTML" (expected 'salted-import-hash', got the recomputed hash).
- All koplugin busted specs pass (513), luajit syntax check clean; the
  related app suites pass (34 files); pnpm lint and format:check clean.
- On a Kindle with KOReader, two HTML files sharing a title got the same
  meta_hash_v1 under the old plugin and distinct ones under the fix,
  each equal to md5 of "<title>|||<basename>".
- Not run: the cross-device sync round trip, because sync from that
  Kindle currently fails for an unrelated reason.

Closes #7313
Reported by zzzh3ng on GitHub

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* fix(sync): salt the HTML metaHash when an existing row has none

An existing HTML row with no metaHash (imported before metaHashes
existed) kept undefined on re-import instead of getting a salted hash.
Keep the stored hash only when there is one.

Verified: the new import-metahash test "salts the metaHash when
re-importing an HTML book that has none" fails without this change
(expected undefined to be the salted hash) and passes with it; related
suites pass (35 files, 543 tests); pnpm lint and format:check clean.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-04 13:25:49 +01:00
Huang Xin
6ab667bd26
fix(annotator): clear a moved highlight's old anchors on the server too (#7319)
Moving a highlight's range cleared its KOReader xpointers and CrossPoint
anchor as undefined, and the push drops undefined fields. When the new
range then couldn't be anchored, the server kept the old range's anchors,
and the next pull merged them back over the local note, so KOReader and
CrossPoint kept the old range. They are now cleared as null, which the
push sends, so the server forgets the old range either way, and the next
session tries to anchor the new one again.

From CodeRabbit's review of #7317 (outside the diff).

Fails without the change: useAnnotationEditor "a moved range drops the
KOReader and CrossPoint anchors of the old one" (expected undefined to be
null). transform "sends anchors cleared by a moved range as null, so the
server forgets them" pins that a null reaches the server record.

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-04 11:56:56 +01:00
Huang Xin
045beb4d1a
feat(crosspoint): sync CrossPoint 2.0 clippings with Readest highlights (#7317)
* feat(crosspoint): sync CrossPoint 2.0 clippings with Readest highlights

CrossPoint 2.0's Sync Clippings first probes
{KOSync server}/api/v1/clippings/{document} for sync_version 2, and stops
the whole sync, progress included, when the probe fails. Readest's KOSync
endpoint had no such route, so a reader signed in with the Readest plugin
showed "Could Not Sync Clippings" and stopped syncing progress once the
setting was on.

- /api/crosspoint/api/v1/clippings/{document} serves the clippings API
  (sync_version 2, cursor paging, tombstones). A clipping is a book_notes
  highlight whose new `crosspoint` column holds the reader's anchor (spine
  plus a code-point range), the way xpointer0/xpointer1 hold KOReader's.
  Only items the firmware can decode are sent, up to the 256 an X3/X4
  holds per book. A rewritten copy (Optimize EPUB) syncs as the library
  book it is linked to, and its first clippings move to that book when
  its progress upload links it.
- Readest apps turn a clipping into a CFI when they open the book, and
  give each EPUB highlight a CrossPoint anchor when they push it (tried
  once a session). Moving a highlight's range drops the old anchors.
- Migration 033 adds book_notes.crosspoint (nullable jsonb). Apply it
  before the web deploy.
- Plugin README: CrossPoint 2.0 names and requirements, and highlights.

Fails without the change: useNotesSync-crosspoint (4 of 5, e.g. "turns a
clipping a reader synced into a highlight at its CFI"), transform "carries
the anchor in the crosspoint column, both ways", useAnnotationEditor "a
moved range drops the KOReader and CrossPoint anchors of the old one"
(expected the old xpointer to be undefined), and the route test "moves a
rewritten copy's clippings to the library book it gets linked to". The
clippings route tests can't run without the route.

Verified on a real X4 (CrossPoint 2.0.0) with Sync Clippings on: the
probe and uploads answer 200, a reader clipping shows in Readest on its
words, a Readest highlight shows on the X4, and deletions go both ways.

Reported by itsthisjustin (CrossPoint).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* feat(crosspoint): sync a document a reader names by its file name

A reader set to match documents by file name (CrossPoint's default, and
the alternate lookup of its Smart Sync) sends md5 of the book's file
name, as KOReader does. Since #7237 Readest keeps the name a book was
imported under (books.original_filename), and #7253 digests it the same
way in Readest's own KOSync client.

Progress, clippings and reading sessions now resolve such a document to
the library book imported under that name, link it on first sight like a
rewritten copy, and move clippings saved under the name's id to the book.
When two books were imported under one name, the most recently read one
wins. A document that is a book's own id is never looked up by name, and
an NFD spelling of the name does not match.

Fails without the change: 5 of the 6 tests in "a document named by its
file name", e.g. "syncs it as the library book imported under that name,
linked on first sight" (the link write and the library book's queries
never happen). The sixth, a name no book has, passed before too.

Not run on a device: the books in the test library were imported before
#7237 and have no original_filename.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* fix(crosspoint): page the file-name lookup, and retry a failed clipping move

From CodeRabbit's review of this PR:

- The lookup of the book imported under a file name read the user's books
  in one request, and PostgREST answers at most 1000 rows (db-max-rows),
  so a match past them was never found. It now pages through them by
  book_hash.
- A copy was linked before its clippings moved to the library book, and a
  failed move only logged a warning. Every later request followed the
  link, so those clippings stayed under the copy's id for good. They now
  move first, and a failed move fails that sync, leaving the copy
  unlinked so the next sync tries again.

Fails without the change: "finds the book past the first 1000 imported
under a name" (no link written: expected [ …(20) ] to deeply equal
ArrayContaining{…}), and "links a copy only once its clippings have
moved, so a failed move is tried again" (expected 200 to be 500).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-04 11:22:58 +01:00
Huang Xin
3384fa679e
feat(vocabulary): redesign the mobile header (#7315)
* feat(vocabulary): redesign the mobile header (owner: "the header is not modern and appealing")

The Vocabulary window's header on phones was a plain input, two text
export buttons and a boxed book select. It is now:

- a rounded search field with a clear button, and one round Export
  button that opens a menu (Export CSV, Export to Anki);
- a row of filter chips (All, Looked Up, Learning, Mastered, each with
  its count) ending in a book chip, scrolling sideways on narrow screens;
- in the word detail, the back button, the word, and Look up and Delete
  icons on one line, replacing the text buttons at the bottom.

The book chip is last in the scrolling row and its picker lines up with
the chip's edge, so a half-hidden chip opened a half-hidden picker.
Pressing the chip now scrolls it fully into view first (keeping the
16px gutter), and so does choosing a book, since the chip widens to
the title.

Verified:
- New test "brings the book chip fully into view before its picker
  opens" fails without the pointerdown handler ("expected vi.fn() to be
  called with arguments: [{ block: 'nearest', ... }]") and passes with it.
- Xiaomi 2211133C (Android, dark) release build with real taps: export
  menu, chip row swipe, book picker and filtering, the one-line detail
  header, and the selected long-title chip fully in view.
- Chrome on dev-web at 500px: tapping the half-hidden chip scrolls it in
  and the picker opens on screen, also after picking a long title.
- Playwright at 393px: light, dark, e-ink and RTL, list, menu, picker
  and detail; 1100px desktop list and detail.
- Not run on the device: Look up, Delete and saving an export, to keep
  sample words out of a synced account. Their handlers are unchanged.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* fix(vocabulary): keep the window inside screens 640-760px wide

From the sm breakpoint the window took a fixed 760px width, capped only
at 768px, so on screens from 640 to 760px wide it overflowed and was
clipped on both sides. Cap it at 90vw, as other wide dialogs do.

Verified:
- New browser test vocabulary-dialog-layout opens the window at 390,
  640, 666, 720 and 1100px. Without the fix it fails at 640, 666 and
  720px ("expected -60 / -47 / -20 to be greater than or equal to 0",
  the box's left edge); with it all five pass.
- Playwright screenshot at 666px: the whole window, list and detail fit.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* fix(vocabulary): close the export menu, 44px header buttons, focus rings

From review on #7315:
- Export CSV / Export to Anki left the menu and its overlay open; both
  items are now transient.
- Back, Look up and Delete in the word detail were 36px; Back navigates
  away and Delete isn't undoable, so they are now 44px (DESIGN.md hit
  targets). The row's edge margins grow to match, so the icons stay
  aligned with the content.
- The search field's clear button was 28px; now 32px.
- Tabbing to the book chip showed nothing, and the search field's only
  focus cue (a background shift) is off under e-ink. The chip now shows
  a ring on keyboard focus, and the search field a solid ring under e-ink.

Verified:
- "exports only the words the filters show" now also expects the menu
  closed; without `transient` it fails with "expected <button
  role="menuitem" …> to be null".
- Browser test "gives the phone header buttons a big enough tap target"
  fails without the change ("expected 28 to be greater than or equal to
  32" for Clear; with only the old detail header, "Back: expected 36 to
  be greater than or equal to 44").
- Browser tests "shows keyboard focus on the search field and book chip"
  (e-ink off and on) tab to each control and fail without the change: the
  chip's computed box-shadow/background/outline didn't change.
- pnpm lint clean; pnpm test 15274 passed; the browser test file 8/8.
- Playwright at 393px: word detail in dark, e-ink and RTL.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-04 10:46:35 +01:00
Huang Xin
50c4ae8258
feat(tts): read aloud with Speech Dispatcher voices on Linux (#7314)
* feat(tts): read aloud with Speech Dispatcher voices on Linux

Read Aloud on Linux can now use the voices installed in Speech
Dispatcher (eSpeak NG, or Piper through a module) under System TTS.
The native-tts plugin speaks SSIP over the daemon's Unix socket with
no speech library linked, so the AppImage uses the host daemon and the
Flatpak needs --filesystem=xdg-run/speech-dispatcher:ro
(docs/linux-system-tts.md). Each reader window gets its own
connection, closed when the window is destroyed. If the daemon or its
voices are unavailable, the other engines remain.

- Voices keep their Speech Dispatcher names; eSpeak NG's per-variant
  copies ("English (America)+Annie") are dropped, so English lists 9
  voices instead of 945. The module is appended only when two modules
  list voices.
- Pause stops the sentence and Play reads it again, as on Android. A
  speechd PAUSE holds back the restarted SPEAK, and RESUME then
  cancels it, so Play skipped the paused sentence.
- A closing window cancels its speech: speechd finishes a disconnected
  client's message.
- Events that arrive before the speak reply are kept, and an aborted
  utterance is canceled by ID so a late reply cannot stop its
  replacement. Rates go to speechd as given, without the mobile
  exponent.

Tests that fail without the change:
- Rust (plugin): pause_cancels_so_the_restarted_sentence_is_not_held_back
  (left "PAUSE SELF\r\n", right "CANCEL SELF\r\n");
  lists_each_espeak_voice_once_rather_than_once_per_variant (4 voices,
  expected 2); closing_a_reader_window_silences_its_speech (left "",
  right "CANCEL SELF\r\n").
- TS: 8 tests in native-tts-client.test.ts and tts-controller.test.ts
  fail against the old NativeTTSClient/TTSController, 7 on assertions
  (e.g. "expected [] to deeply equal [ 'boundary', 'end' ]",
  "expected null not to be null" for the Linux system voices) and one
  on its 5 s timeout (overlapping speak replies).

Real use, Linux CEF dev build, isolated HOME, host speech-dispatcher
0.12.1 with its eSpeak NG module:
- Pause/Play 3 of 3 re-read the paused sentence with no "Speech
  interrupted"; before the fix 3 of 3 skipped it.
- Speak on a selection while paused speaks (before: silent).
- Picker lists 9 System TTS voices; choosing another voice and pressing
  Play reads on in that voice.
- Speed: 2.7 s per sentence at 1.5x, 5.2 s at 0.95x.
- Closing the book at +1.4 s into a sentence: speech ends 1 s later;
  without the cancel it ran 3.6 s to the sentence's end.
- SPEECHD_ADDRESS at a missing socket: "System TTS unavailable" is
  logged and Read Aloud falls back to Edge TTS.

Checks: plugin cargo test (36 passed), pnpm test:rust (204 passed),
the two TS suites (171 passed), pnpm lint, pnpm fmt:check, pnpm
clippy:check, cargo check of the plugin for x86_64-pc-windows-gnu and
aarch64-linux-android.

Not run: the AppImage and Flatpak packages, two reader windows reading
at once, light/dark/e-ink (no UI changed). Chinese books get no System
TTS voice: eSpeak NG labels them cmn/yue and language matching expects
zh.

Closes #6805

Reported by ell1e on GitHub.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* fix(tts): keep a slow Speech Dispatcher voice list from disabling System TTS

Every command waited at most 3 s, and a timeout closes the connection
because a late reply would answer the next command. eSpeak NG sends
about 15k voice rows for LIST SYNTHESIS_VOICES: 0.4 s here, warm or
cold, so a slow machine or module could run past 3 s. voices() then
took the dead connection for a module without voices and failed with
"Speech Dispatcher has no installed voices".

The voice list now gets 10 s, under the reader's 15 s engine init
limit. A lost connection ends the listing with its cause ("Speech
Dispatcher did not answer in time while listing piper voices"); a
module that answers with an error is still skipped.

Raised by CodeRabbit on #7314.

Tests that fail without the change:
- waits_for_a_slow_voice_list: the reply comes 3.5 s after the request;
  fails at "a voice list slower than one command must still arrive".
- a_lost_connection_while_listing_voices_reports_the_cause: left
  Some("Speech Dispatcher has no installed voices"), right
  Some("Speech Dispatcher disconnected while listing espeak-ng voices").

Checks: plugin cargo test --lib (38 passed), pnpm test:rust (204
passed), pnpm fmt:check, pnpm clippy:check, cargo fmt --check in the
plugin. Real daemon (speech-dispatcher 0.12.1, eSpeak NG): init()
lists 141 voices in 0.43 s.

Not run: a real slow module (the delay is simulated in the test), and
the Tauri app after this change.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* fix(tts): give every reader speed its own Speech Dispatcher rate

The reader offers 0.5x to 3x (the speed ruler and RSVP's rate list),
but the Linux bridge sent (rate - 1) * 100 clamped to SSIP's -100..100,
so 2x, 2.5x and 3x all became 100 and sounded the same, and 0.5x only
reached -50. 0.5x-1x now spreads over -100..0 and 1x-3x over 0..100.

Raised by CodeRabbit on #7314.

Test that fails without the change:
every_reader_speed_has_its_own_ssip_rate, left
[-50, -25, 0, 50, 100, 100, 100], right [-100, -50, 0, 25, 50, 75, 100]
for 0.5, 0.75, 1, 1.5, 2, 2.5, 3.

Real daemon (speech-dispatcher 0.12.1, eSpeak NG), one sentence spoken
through SpeechDispatcher at each speed, begin to end: 0.5x 12.17 s,
1x 5.57 s, 1.5x 3.91 s, 2x 2.97 s, 2.5x 2.29 s, 3x 1.82 s (0.46x,
1.42x, 1.88x, 2.44x, 3.05x of 1x).

Checks: plugin cargo test --lib (39 passed), pnpm test:rust (204
passed), pnpm fmt:check, pnpm clippy:check, cargo fmt --check in the
plugin.

Not run: the speed ruler in the Tauri app after this change; the
mapping from the ruler to set_rate is unchanged.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-04 10:38:54 +01:00
Hwang Kyu Do (황규도)
8f36b28982
fix(sync): sync a re-enabled or cleared custom TTS field to other devices (#7307)
* fix(sync): sync a re-enabled or cleared custom TTS field to other devices

Replica fields merge per key, and a key left out of the push keeps its
old value on the server. Re-enabling a custom TTS service dropped the
'disabled' key instead of sending false, so the next pull disabled the
service again; clearing instructions, voices or the response format came
back the same way. Always send these keys, as the custom translator
adapter already does.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* chore: trim comments

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* style: format customTTS adapter test

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* test(sync): assert the clearing value in the custom TTS adapter test

`toHaveProperty` also passed when pack() wrote `undefined`, which JSON
drops, so a broken fix would still have passed. Assert `false` for
`disabled` and `null` for the other fields, as CodeRabbit pointed out.

Verified: writing `fields['instructions'] = s.instructions` (no `?? null`)
now fails "clearing instructions reaches other devices" with
"expected undefined to be null"; with the PR's fix all 8 cases pass.
Full `pnpm test` (15267 passed) and `pnpm lint` pass on this head. Main's
newer commits touch no sync or TTS files and the merge is clean.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Co-authored-by: Huang Xin <chrox.huang@gmail.com>
2026-11-04 08:54:03 +01:00
Huang Xin
8380b8c6f7
fix(send): allow PATCH through CORS so the apps can approve a sender (#7312)
Tapping the checkmark on a pending sender in Send to Readest sends PATCH
/api/send/senders. PATCH was missing from the methods the API allows, so
the desktop and mobile apps, which call the API cross-origin, had it
blocked at preflight and showed "Could not approve sender". Adding and
removing a sender use POST and DELETE and were not affected. The web app
is same-origin, so it was not affected either.

src/middleware.ts is the fix: it answers every /api OPTIONS request first.
src/utils/cors.ts gets the same word so the two lists agree. Its methods
are not reached on /api, so it has no test of its own.

This was the only blocked call. /api/notion is the only other PATCH route;
the web app reaches it same-origin and the native client bypasses it. The
OPDS proxy's read-only list is correct as it is.

Fails without the change: src/__tests__/middleware.test.ts "allows PATCH
so the native apps can approve a pending Send to Readest sender", with
"expected [ Array(5) ] to include 'PATCH'".

Verified in WebKit and Chromium through Playwright, from a page on an
allowed origin calling a dev server with the same request as
approveSender():
  before: PATCH blocked (WebKit "TypeError: Load failed"), DELETE reached
          the route
  after:  PATCH and DELETE both reached the route (403 for the probe's
          fake token)

pnpm test: 15264 passed, 16 skipped. pnpm lint, pnpm format:check and
pnpm build-web pass.

Not run: approving a real pending sender from a signed-in app. The apps
call production, so this can only be checked after the web deploy.

Reported by a user by email.

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-04 08:46:30 +01:00
Huang Xin
a389b68b35
feat(annotator): draw a global annotation's copies as a dashed underline (#7309)
* feat(annotator): draw a global annotation's copies as a dashed underline (owner: "showing dashed underline without note icon")

Every other occurrence of a global annotation's text used to get the
annotation's own highlight plus a note icon. Each copy now draws one
fine dashed underline in the theme's text color at 50% (solid on
black-and-white e-ink) and no note icon. Clicking a copy opens the note
when the annotation has one, and the highlight toolbar otherwise. The
original keeps its highlight and note icon.

- The underline strokes var(--color-base-content) set as a style, so it
  follows a light/dark switch: overlays aren't redrawn on a theme change,
  and a resolved color drawn in dark mode stayed light gray on a light
  page.
- Global annotations are now also bucketed under their own section.
  They were kept out of it, so the original's note icon was never drawn
  after the book reopened; the copies' icons used to hide that.
- Click resolution moved into resolveAnnotationClick so it can be tested.

Verified:
- With the source reverted to origin/main, 9 of the new tests fail: 6 on
  assertions (6 overlays instead of 3 for a global note, 'highlight'
  instead of 'global' for a copy, no theme-variable stroke, a global note
  missing from its section's notes) and 3 because resolveAnnotationClick
  did not exist. All pass with the change.
- pnpm format:check, pnpm lint and pnpm test (1253 files) pass.
- In Chrome on pnpm dev-web, with a global "Alice" plus a note in
  Alice's Adventures in Wonderland: copies across chapters draw dashed
  with no icon; clicking one opens the note; after a reload the original
  keeps its highlight and icon; a live dark/light switch recolors the
  dashes; on e-ink all 53 copies on the open pages draw solid.
- Not checked: vertical writing mode, mobile devices.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* fix(annotator): keep toolbar actions on a global copy bound to its highlight

Answers CodeRabbit on #7309. Clicking a copy of a global highlight with no
note opens the toolbar with the highlight's cfi but the copy's range.
handleHighlight recomputed the CFI from that range, so Delete Highlight
(and a restyle) missed the highlight and added a new one at the copy. An
annotated single-range selection now keeps its cfi, as popup selections
already did; the range editor keeps that cfi in step when it resizes a
highlight. A copy also no longer opens the range handles: dragging them
moved the highlight itself to the copy's text.

Black-and-white e-ink draws the copies dashed at full opacity, not solid
as the first commit said: a solid line would look like an Underline
highlight. The comment and test say so.

Verified:
- Two new tests in AnnotatorShowImportedAnnotation.test.tsx fail without
  the fix: Delete Highlight on a copy left
  `expected [ { …(2) }, { …(2) } ] to deeply equal [ { …(2) } ]` (the
  highlight kept plus a new record at the copy), and the copy rendered
  the range editor. Both pass with it.
- pnpm lint and pnpm test (1253 files) pass.
- In Chrome on pnpm dev-web: a global "Rabbit" with no note, clicked on a
  copy, opens the toolbar with no handles; Delete Highlight removes the
  highlight and all its copies, and a reload shows nothing left behind.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* refactor(annotator): draw global copies with foliate's Overlayer.dashedUnderline (owner: "should we draw the dashed line in foliate overlayer?")

drawDashedUnderline copied Overlayer.underline's placement (the edge,
the padding, the vertical writing-mode branch) into annotatorUtil. The
dashed line now lives in foliate-js as Overlayer.dashedUnderline
(readest/foliate-js#146), next to underline and squiggly. Readest still
chooses the look: var(--color-base-content) as the color, 50% opacity,
full opacity on black-and-white e-ink.

The submodule points at the PR branch's commit 31d584c. It has to be
re-pointed at the merged commit once readest/foliate-js#146 is merged.

Verified:
- overlayer-dashed-underline.test.ts fails before the method exists
  (`Overlayer.dashedUnderline is not a function`) and passes with it. It
  checks the stroke, opacity, width and dash attributes, and that each
  line runs along the centre of underline's rect, horizontally and in
  vertical-rl.
- The existing drawAnnotationOverlay tests pass unchanged against the
  foliate method. pnpm lint and pnpm test (1254 files) pass.
- In Chrome on pnpm dev-web from this branch: 29 copies on the open
  pages draw with stroke var(--color-base-content) (rgb(23, 23, 23) in
  the light theme), opacity 0.5, width 1, dashes 2 2.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* chore(foliate-js): point at the merged dashedUnderline (#146)

readest/foliate-js#146 merged as 2e4dbc1, with the same content as the
branch commit 31d584c this PR pointed at before (empty diff between them).

Verified: overlayer-dashed-underline.test.ts and annotatorUtil.test.ts
pass against 2e4dbc1.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* fix(annotator): open the note editor when annotating a global copy

Answers CodeRabbit's outside-diff finding on #7309. After dbee344de,
Annotate on a copy of a global highlight with no note found the highlight
in handleHighlight (it keeps the selection's cfi) but looked the target up
again by the copy's range, found nothing and returned: no editor opened.
Both now use keepsSelectionCfi, so the editor opens on the highlight.

Verified: a new test in AnnotatorShowImportedAnnotation.test.tsx fails
without this (`expected null not to be null`: no note editor) and passes
with it, with no record added. pnpm lint and pnpm test (1254 files) pass.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-04 08:13:11 +01:00
Huang Xin
16a5468921
fix(annotator): line the note card up with its popup box (#7310)
* fix(annotator): line the note card up with its popup box (owner: "two popups overlayed and the corner is not well aligned")

A note opens as its own bordered card inside the toolbar's 44px popup
box. The box has a 1px border in every mode and the card sat at offset 0
inside it, 1px in from the box's outer edge, where the triangle joins.
The box's frame showed around the card and the corners didn't match.
With the popup above the text, the triangle's fill covered the box's
border row but not the card's, one row up, leaving a line across the
triangle's base.

The card and the note editor now sit at -1px on the triangle edge and
the side, so they cover the box exactly. The e-ink-only
translate(-1px, -1px) on .annotation-notes is gone: it only fixed popups
below the text and put popups above it 2px off.

Verified:
- New browser test in annotation-popup-layout.browser.test.tsx measures
  the card against the box with the triangle up and down, e-ink on and
  off. With the source reverted to origin/main, 3 of the 4 fail:
  `expected { left: 21, right: 321, bottom: 199 } to deeply equal
  { left: 20, right: 320, bottom: 200 }` (light/dark, triangle below), 1px
  on the top and left with the triangle above, and 2px at the bottom on
  e-ink with the triangle below. All 4 pass with the change.
- pnpm format:check, pnpm lint, pnpm test (1253 files) and the popup
  browser tests (annotation-popup-layout, footnote-popup-toolbar-stacking,
  popup-safe-area) pass.
- In Chrome on pnpm dev-web, a note popup above and one below the text
  have card and box edges equal to the pixel, with no line at the triangle.
- Not checked in the app: the note editor (same -1px placement), vertical
  writing mode, mobile devices.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* test(annotator): measure the note editor against its popup box too

Answers CodeRabbit's nitpick on #7310: the alignment test measured the
note card only, so the editor's -1px offsets could regress unnoticed. Each
case now also opens the note editor and checks its left, right and
triangle-side edges against the popup box.

Verified: with only AnnotationPopup.tsx (the editor's offsets) reverted
to origin/main, all 4 cases fail on `.annotation-note-editor`; with the
change they pass. pnpm lint passes.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* test(annotator): cover vertical writing in the note card alignment test

Answers CodeRabbit's nitpick on #7310: the card and editor offsets have a
vertical branch (right/left plus top), but the test only rendered
horizontal text. It now runs all four triangle directions (up, down,
left, right) with e-ink on and off, and checks the triangle's edge and the
two edges across from it for both the note card and the note editor.

Verified: with AnnotationNotes.tsx, AnnotationPopup.tsx and globals.css
put back to origin/main, all 8 cases fail; with the change they pass.
pnpm lint and the popup browser tests (annotation-popup-layout,
footnote-popup-toolbar-stacking, popup-safe-area) pass.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-04 08:11:53 +01:00
Huang Xin
8c10025f37
fix(auth): keep the sign-in callback URL out of logs (#7305)
Some checks are pending
CodeQL Advanced / Analyze (actions) (push) Waiting to run
CodeQL Advanced / Analyze (javascript-typescript) (push) Waiting to run
CodeQL Advanced / Analyze (rust) (push) Waiting to run
Publish Docker image / build (linux/amd64, ubuntu-latest) (push) Waiting to run
Publish Docker image / build (linux/arm64, ubuntu-24.04-arm) (push) Waiting to run
Publish Docker image / merge (push) Blocked by required conditions
Build with Nix / tests (push) Waiting to run
PR checks / nix_flake_check (push) Waiting to run
PR checks / rust_lint (push) Waiting to run
PR checks / koplugin_rust_lint (push) Waiting to run
PR checks / build_web_app (push) Waiting to run
PR checks / test_web_app (1) (push) Waiting to run
PR checks / test_web_app (2) (push) Waiting to run
PR checks / test_web_browser (push) Waiting to run
PR checks / test_extensions (push) Waiting to run
PR checks / build_tauri_app (push) Waiting to run
Scorecard supply-chain security / Scorecard analysis (push) Waiting to run
Deploy to vercel on merge / build_and_deploy (push) Waiting to run
The macOS auth session logged the full callback URL at INFO, which the
release build writes to Readest.log. Its fragment holds the session's
access and refresh tokens (and the provider token for Google sign-in).
Log only that the callback arrived. The auth page also printed the same
URL, and the single-instance payload carrying it, to the webview console;
drop both.

Verified: the change only removes log output, so there is no behavior to
test. `pnpm lint` passes and `cargo fmt --check` passes on the file. Not
run: a macOS build or sign-in, since this machine has no macOS target;
the edited line only drops the format argument from a `log::info!` call.

Reported by ts-eva on GitHub.

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-04 03:26:50 +01:00
Huang Xin
cc9ac61c4b
fix(bookdrop): keep received file names inside the inbox (#7304)
* fix(bookdrop): keep received file names inside the inbox

The Nearby BookDrop receiver joined the file name the sending device
declared straight onto the inbox folder, so a name with `../` segments or
an absolute path was saved outside it. Use only the last path component of
the declared name, falling back to "file" when there is none.

The web-browser download path has its own unique_path, but both of its
callers already reduce the name to one component first.

Verified:
- localsend::service::tests::unique_path_keeps_peer_file_names_inside_the_inbox
  fails without the change: left "/tmp/ls-up-trav-…/../../evil.epub",
  right "/tmp/ls-up-trav-…/evil.epub". It passes with it.
- pnpm test:rust (203 passed), pnpm clippy:check, pnpm fmt:check.
- In the Linux CEF dev build (isolated profile), a LocalSend v2 client sent
  "../../../../../../../../../../tmp/claude-adv/pwned-target/evil.epub";
  after Accept the upload returned 200 and the file was saved as
  localsend/inbox/evil.epub, with nothing written to the target folder.
- Not run: the same request against the unfixed build in the app (the
  dev target directory was shared with another running app), or on
  Windows, where `\` is also a separator for Path::file_name.

Reported by ccsimplyspolit on GitHub.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* fix(bookdrop): reserve each inbox name before the upload writes it

Uploads in one session are handled concurrently, and keeping only the
last path component makes `a/book.epub` and `b/book.epub` both pick
`book.epub`: two uploads could pass the exists() check together and
write the same file. unique_path now claims the name with an empty file
(create_new) and moves to the next numbered name when it is taken. The
upstream writer opens the target with File::create, so it truncates the
placeholder as before. A failed reservation fails that upload.

Verified: unique_path_reserves_the_name_it_returns fails without the
change (left "/tmp/ls-up-res-…/book.epub", right "…/book (2).epub") and
passes with it. pnpm test:rust (204 passed), pnpm clippy:check and
pnpm fmt:check pass. Not run: an in-app transfer of two same-named
files, since the dev build's target directory is shared with another
running app.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* fix(bookdrop): report a failed inbox reservation like a failed upload

When the inbox name couldn't be reserved, the upload was dropped without
the per-file done event, so the app never heard that file had failed or
why. The reservation error now goes through the same completion task as
a failed write: the file counts as failed, `localsend:receive-file-done`
carries the error with no path, and the session-end check runs.

Verified: pnpm test:rust (204 passed), pnpm clippy:check and pnpm
fmt:check pass. Not run: a test or in-app run of the failure path. No
test in this crate builds an AppHandle (tauri's `test` feature is off),
and the dev build's target directory is shared with another running app.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-04 03:26:02 +01:00
Huang Xin
e9490ee4a9
fix(reader): preserve publisher font lists and category fallbacks (#7302)
Some checks are pending
CodeQL Advanced / Analyze (actions) (push) Waiting to run
CodeQL Advanced / Analyze (javascript-typescript) (push) Waiting to run
CodeQL Advanced / Analyze (rust) (push) Waiting to run
Publish Docker image / build (linux/amd64, ubuntu-latest) (push) Waiting to run
Publish Docker image / build (linux/arm64, ubuntu-24.04-arm) (push) Waiting to run
Publish Docker image / merge (push) Blocked by required conditions
Build with Nix / tests (push) Waiting to run
PR checks / build_web_app (push) Waiting to run
PR checks / test_web_app (1) (push) Waiting to run
PR checks / nix_flake_check (push) Waiting to run
PR checks / rust_lint (push) Waiting to run
PR checks / koplugin_rust_lint (push) Waiting to run
PR checks / test_web_app (2) (push) Waiting to run
PR checks / test_web_browser (push) Waiting to run
PR checks / test_extensions (push) Waiting to run
PR checks / build_tauri_app (push) Waiting to run
Scorecard supply-chain security / Scorecard analysis (push) Waiting to run
Deploy to vercel on merge / build_and_deploy (push) Waiting to run
Tokenize family lists locally so quotes, comments, CSS escapes and function
commas remain intact. Use the same tokenization for generic detection and
replacement, and nest every eligible category in publisher list order.
Preserve the existing encoded-apostrophe fix from aae1b6517.

Verification:
- New tests failed before the fix: quoted names were changed, commented
  generics were missed, and later enabled categories kept PublisherMixed.
  Four unit and two computed-style browser regressions failed.
- Related unit suites: 224 passed; focused Chromium suites: 10 passed,
  including the existing encoded O'Neill regression.
- Running web reader with generated EPUB: quoted/apostrophe names preserved,
  commented serif and later monospace switches work, original fonts restored.
- Formatting, lint and the full unit suite run through the pre-push hook.
- Native Linux, Android and iOS checks not run for this parser follow-up.

Co-authored-by: Claude Code <noreply@anthropic.com>
2026-11-03 20:02:19 +01:00
Huang Xin
ba8cc03573
fix(reader): draw PDF text at the screen's full resolution on iOS and Android (#7300)
* fix(reader): draw PDF text at the screen's full resolution on iOS and Android

PDF pages on mobile are drawn within a memory budget (#5118): at most 2x
and about 3.1 Mpx per page. A 3x iPhone drew text at 2x, an iPad page
fitted to the screen came out at 1.85x on a 2x screen, and zooming lowered
it toward 1x, so text got softer the further the reader zoomed.

foliate-js (readest/foliate-js#144) keeps the budgeted page and adds a
canvas over only the on-screen part of it at the full device pixel ratio.
Its size is bounded by the screen, so the budget still holds. The page is
cut away under it, since Readest's mix-blend-mode would otherwise show the
coarse page through as a halo. Desktop is unchanged.

Verification:
- New pdf-detail-canvas.test.ts: with main's foliate-js 3 of its 5 tests
  fail ("expected undefined to be truthy" for the detail canvas, and
  "expected '' to match /^polygon\(evenodd.../" for the clip); all 5 pass
  with the change.
- pnpm test: 1252 files passed, 4 skipped (15217 tests passed).
- pnpm lint and pnpm format:check passed; eslint on foliate pdf.js passed.
- iPad Air 11" M2, iPadOS 27, release build with devtools, a text PDF
  driven over the WebKit inspector: the visible page went from 1.85x to
  2.0x at fit and from 1.0x to 2.0x at 300% zoom. Edge blur score (grey
  edge pixels per ink pixel) 1.77 -> 0.87 at fit, 3.64 -> 2.18 at 300%.
  The detail followed a pan; scrolled flow gave each of two visible pages
  its own slice; 25 page turns at 300% left no WebKit memory kill in
  syslog. With mix-blend-mode multiply on a sepia page, the halo shows
  without the clip and is gone with it.
- Not run: an iPhone (3x), Android, e-ink, and themed PDF page colors on a
  device: iOS WebKit has no canvas filter, so "apply theme to PDF" does
  not theme pages on iOS with or without this change.

Reported by ruslanMacari on GitHub (#7100).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* fix(reader): release closed PDF pages' detail canvases, test a page scrolled away

Moves foliate-js to da95896 (readest/foliate-js#144), which holds the
detail canvases' documents weakly: once a reader closed, nothing pruned
them, so each closed page document stayed reachable with its page bitmap
until another PDF opened. Adds a test that a page scrolled off the screen,
with its iframe still visible, drops its detail canvas and clears the clip.
Both raised by CodeRabbit on #7300.

Verification:
- The new test passes; all 33 document test files pass (294 tests).
- eslint on foliate pdf.js passed.
- iPad Air 11" (iPadOS 27), rebuilt release build: detail canvas at 2.0x
  at fit, at 300% and after a pan, and again after closing and reopening
  the book and turning a page.
- Not run: a memory measurement of closing a reader (the leak was only
  reachable references; there is no GC hook to assert it in jsdom).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* chore(deps): move foliate-js to main after #144 and #145 merged

Points the submodule at 95fa3b7, the merge of readest/foliate-js#145 on
top of #144 (b8dd100). Its pdf.js is identical to da95896, the commit this
PR pinned before and that was tested on the iPad (git diff --quiet).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-03 19:44:03 +01:00
Huang Xin
c296a204ae
feat(reader): ignore publisher font names by font category (#7298)
* feat(reader): ignore publisher font names by font category (#7276)

Books often name fonts ahead of the generic family
(`font-family: Palatino, Merriweather, serif`), so the reader's Serif,
Sans-Serif and Monospace choices were never reached. Each font picker now
has an "Ignore publisher font names" switch, off by default, like
KOReader's option of the same name.

A book font list that names serif, sans-serif or monospace is wrapped as
`var(--book-serif, Palatino, ..., serif)`. `--book-serif` is defined only
while that category's switch is on, so with it off the book's own list
applies as before, and toggling takes effect without reloading the
chapter. Linked stylesheets, `<style>` blocks, `style` attributes and the
`font` shorthand are covered. The shorthand's family list is found word
by word after the size and optional `/line-height`, with no backtracking
regex. Lists without one of these generics
(fantasy, cursive) are left alone, and Override Book Font still wins: the
switches are disabled and the variables are not set while it is on.

Verification:
- New browser test publisher-fonts.browser.test.ts. Before the change,
  "swaps only the switched categories for the reader font, live" failed
  with: expected 'PublisherSerif, "Publisher Two", Read…' to match
  /^ReaderSerif,/. It passes with the change. Four style.test.ts
  assertions were updated to the wrapped text.
- New style.test.ts cases for the shorthand. "stays linear on long runs
  of whitespace" took 15153 ms against a first single-regex version
  (expected < 200) and passes now.
- pnpm test (15213 passed), pnpm test:browser (916 passed), pnpm lint.
- dev-web: imported an EPUB with a linked stylesheet, a style block, a
  `font` shorthand, an inline style, code and a fantasy list. Computed
  fonts switched per category live, persisted across reload and were
  restored when switched off. Decorative text was unchanged. The switches
  were disabled under Override Book Font. The panel was checked in light,
  dark, e-ink and RTL.
- Not run: desktop, Android and iOS app builds.

Reported by Alsharad on GitHub.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* fix(reader): keep quotes in encoded inline font names

A `style` attribute with `font-family: &quot;O'Neill&quot;, serif` had
`&quot;` swapped for `'`, so the wrapped list read `'O'Neill', serif`. That
declaration is invalid and the paragraph fell back to the inherited font.
Decode `&quot;` to `"` for the CSS pass and encode it again when writing the
`"`-quoted attribute back; such a value can't hold a raw `"`, so the round
trip is exact.

Verification: publisher-fonts.browser.test.ts gains an O'Neill paragraph.
Before the fix, "keeps the book fonts while every switch is off" failed
with: expected 'ReaderSerif, "LXGW WenKai GB Screen",…' to be
'"O\'Neill", serif'. It passes after.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-03 19:43:42 +01:00
Huang Xin
d1d1391c97
perf(reader): subscribe the vim command line to the store fields it uses (#7301)
VimCommandLine is mounted in every book cell. Destructuring
useBookDataStore() and useReaderStore() subscribed it to the whole
stores, so each cell re-rendered on every page turn even with no find
open. Per-field selectors, as BooksGrid uses (CodeRabbit on #7282).

Verified: e2e/tests/vim-find.spec.ts 14/14 (--repeat-each 2); pre-push
format:check, lint and pnpm test.

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-03 19:26:10 +01:00
Huang Xin
faabbf0fd3
fix(reader): set spread defaults (owner: only change the default for desktop and mobile) (#7299)
Default PDF/CBZ spread to auto in native desktop apps and single-page
elsewhere. Pass the desktop-app flag into settings defaults and preserve
saved global and per-book choices. Keep the existing View menu controls.

Verified: 74 related tests pass; pnpm lint and git diff --check pass.
The full unit suite previously passed with 15,219 tests. Native Linux CEF
verification covered PDF single-page loading, live spread switching, CBZ
two-page rendering, and reopening. Android/iOS devices were not exercised;
platform defaults are covered by unit tests.

Regression evidence: desktop-browser default test fails without the change
(expected 'none', received 'auto'); app-service flag test fails without the
context wiring (missing isDesktopApp: true).

Reported by TOM-PIC on GitHub (#7283).

Co-authored-by: Claude Code <noreply@anthropic.com>
2026-11-03 18:59:31 +01:00
Huang Xin
3e1af7fe88
fix(library): refresh external sources without a Readest login (#7297)
* fix(library): refresh external sources without a Readest login

Route both library pull-to-refresh stages through the same handler. Allow
configured external sources to refresh while signed out, run the existing
file-sync, OPDS and Audiobookshelf checks, and await subscription checks.
Keep the sign-in prompt when no external source is enabled. KOSync remains
reader-scoped; enabling it suppresses the unrelated Readest login prompt.

Verification:
- 59 tests passed across useLibraryRefresh, useBooksSync-routing,
  usePullToRefresh, useLibraryFileSync, useOPDSSubscriptions and useABSSync.
- The new regression tests failed with the original callback behavior:
  signed-out OPDS refresh called navigateToLogin in both stages, and
  signed-in refresh completed before the pending OPDS check resolved.
- pnpm lint and git diff --check passed.
- In an isolated iPad-sized Chromium session, a normal pull downloaded a
  newly published EPUB into the library while signed out; a deeper pull
  checked the feed again without navigating to login.
- Native iOS/iPadOS verification was not run on this Linux host. The full
  unit suite is left to CI, following the related-tests-only preference.

Reported by fake-name on GitHub.
Fixes #7280

Co-Authored-By: Claude Code <noreply@anthropic.com>

* fix(library): retain login fallback for paused file sync

Use the same active-backend gate as pullLibrary when deciding whether a
signed-out refresh has an external file-sync source. An enabled backend
paused by the hosted plan gate cannot refresh and must not suppress login.
OPDS and other eligible sources continue to refresh independently.

Verification:
- New hosted/free-plan regressions failed in both pull stages before the
  fix: expected navigateToLogin to be called, but it was called zero times.
- 63 tests passed across six related refresh and provider suites.
- pnpm lint and git diff --check passed.
- Rechecked both pull gestures in the isolated iPad-sized web app: a new
  OPDS EPUB downloaded into the library without login; a deeper pull
  checked the feed again.
- Native iOS verification was not run on this Linux host.

Co-Authored-By: Claude Code <noreply@anthropic.com>

---------

Co-authored-by: Claude Code <noreply@anthropic.com>
2026-11-03 18:58:27 +01:00
You Gao
0535ac710a
feat(reader): vim-style find to start and extend a selection from the keyboard (#7282)
* feat(reader): search select

* refactor(reader): moved select into view

* feat: added tests for select logic

* fix: does not select from search, only options

* fix: test

* fix: CFI validation

* fix: code cleaning

* Revert "fix: code cleaning"

This reverts commit 00c9ec3b78e7f91828e28d9239f366cafddc4743.

* Revert "Revert "fix: code cleaning""

This reverts commit 2f85d454de39d3f551594a2fe0eb3c146314cbfe.

* Revert "fix: CFI validation"

This reverts commit 9ed92a3d9e6be0707513ba873687d54ad7b59d70.

* fix: cfi validation

* fix: test pt2

* feat(reader): vim-style find to start and extend a selection from the keyboard

A keyboard-only reader could act on a selection (Ctrl+H/U/N/D/T/R/C)
and adjust it with Shift+Arrows (#4728), but couldn't start one without
a mouse (#7281). Vim-style find fills that gap:

- `/` opens a command line at the bottom of the book. Enter searches the
  whole book and selects the first match at or after the current page,
  wrapping to the first. The line shows the term and `[i/N]` until Esc.
- `n` / `Shift+N` jump the selection to the next / previous match.
- While a match is selected, h l w b e j k 0 $ ( ) { } extend its moving
  end and `o` swaps the ends, as in visual mode. The page turns when the
  moving end leaves it. `y` copies (also added to Copy Selection).
- Esc clears the selection and ends it. The search stays live across
  Ctrl+H, so `/term`, Ctrl+H, `n`, Ctrl+H highlights match after match.

None of these keys change meaning unless a find is live: the handlers sit
ahead of page navigation and the Notebook in one shortcut listener and
fall through otherwise. The sidebar search and Previous/Next Result are
unchanged and keep using goTo(); vim find runs its own search so their
highlights are left alone.

A selection made by view.select(), and the keyboard extending it, opens
the toolbar and never runs the instant quick action, until the next
pointer press. Jumping to a match clears the last one's selection in
another section under the guard the cross-page path uses, so the
throttled popup dismiss can't close the new toolbar.

Chromium quirks handled: `paragraph` steps keep the caret's x, and a
forward selection won't extend back to a line or paragraph boundary, so
`}` steps to paragraphboundary and `0`/`{` move a collapsed caret and
re-extend. `w`/`e` skip spaces so they land the same with macOS and
Windows word steps.

This replaces the PR's first approach: the select() wrapper in
types/view.ts and its test are removed (foliate's view.select() already
selects), and the sidebar result click is back to goTo().

Text objects (iw/is/ip) were left out: a two-key sequence doesn't fit
the shortcut config without bare s/p bindings.

Verified:
- e2e/tests/vim-find.spec.ts (7 tests): 28/28 with --repeat-each 4.
  Before the feature 5 of 6 failed (no find line); the sidebar test
  passed. Resetting the navigated mark after the first selection fails
  "a match never runs the instant quick action, nor does extending it"
  (Dictionary opens on `e`). Dropping the stale-selection clear fails
  "n and N step through matches" (the old match stays selected).
- dev-web, Chromium: light, dark, e-ink, chrome shown (line sits above
  the footer); scrolled mode; `}` across a page turns the page; Ctrl+H,
  n, Ctrl+H made two highlights.
- annotation.spec.ts + reading.spec.ts: passed except #6540's "keeps the
  note bubble on restyle", which also fails 3/3 on main under dev-web.
- pnpm test: 1250 files, 15210 tests passed (shortcut tests updated for
  the new `n` / Shift+N defaults). pnpm lint, format:check: clean.
- i18n: 5 new strings added and translated in all 34 locales; nothing
  else in the locale files changed.
- Not run: Windows WebView2 and WebKit (macOS/iOS) word and boundary
  steps, Firefox web (no sentence/paragraph steps), Tauri builds.

Reported by you-gao on GitHub

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

---------

Co-authored-by: Huang Xin <chrox.huang@gmail.com>
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-03 18:45:25 +01:00
Huang Xin
e20fb3b52b
fix(bookorbit): let the web proxy run on Cloudflare Workers (#7296)
* fix(bookorbit): let the web proxy run on Cloudflare Workers

Every /api/bookorbit request on web.readest.com answered 500, so BookOrbit
could not connect on web at all, with or without Cloudflare Access service
tokens. The proxy fetched with redirect: 'error', which the Workers runtime
rejects before sending anything: "Invalid redirect value, must be one of
"follow" or "manual"". Native apps call the server directly and were not
affected.

The proxy now fetches through publicFetch (redirect: 'manual' on Workers,
a resolved-address check on Node, as the KOSync proxy does) and still
refuses to follow a 3xx, so the redirect-based SSRF guard is kept.

Verified:
- bookorbit-ssrf.test.ts "forwards allowed requests on Cloudflare
  Workers" stubs fetch to reject redirect: 'error' like workerd; it fails
  on main with "expected 500 to be 200" and passes with the fix. A 302 to
  169.254.169.254 is not followed.
- pnpm preview (opennext on local workerd): an allowed request reached
  the upstream and its status was relayed (production returns the 500
  above for the same request); custom headers and the
  /api/v1/koreader/plugin/version path arrived at an echo server; an
  http->https 301 is refused; a private address is still a 400.
- pnpm test (15213 passed), pnpm lint.
- Not run: a real BookOrbit server behind Cloudflare Access.

Fixes #7291. Reported by shahram7 on GitHub.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* test(bookorbit): assert manual redirect mode and the forwarded Access secret

Answers CodeRabbit's two nitpicks on #7296. bookorbit-ssrf.test.ts: 6
passed; pnpm lint and pnpm format:check clean.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-03 18:32:43 +01:00
Huang Xin
4148460195
chore(agent): update memories (#7295) 2026-11-03 17:25:39 +01:00
Huang Xin
ba94f098df
fix(reader): keep the sidebar button top-left on tablets, tidy the transparent-image row (#7294)
* fix(settings): render the transparent-image row like its neighbours

"Make White Image Backgrounds Transparent" was wrapped in its own
BoxedList card, so it showed a shaded box between the plain "Invert Image
In Dark Mode" and "Override Book Color" rows in the Color panel. Render it
as the same plain label row, keeping its description line and the PDF
disabled state.

Verification:
- New ThemePanel.image-rows.test.tsx failed before the fix on
  `expect(row.closest('.card')).toBeNull()` ("expected <div …> to be
  null") and passes with it.
- pnpm test: 1251 files passed, 4 skipped (15211 tests passed).
- pnpm lint passed.
- dev-web, reader Settings > Color: checked dark mode, light mode and
  e-ink (data-eink) with no card and aligned with the rows next to it;
  clicking the label still toggles the setting on and off.
- Not checked on an iPad or Windows device, or under RTL.

Reported by noideaforeal on GitHub (#7292).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* fix(settings): shorten the transparent-image label (owner: remove the description and shorten the label for this option)

Rename "Make White Image Backgrounds Transparent" to "Transparent Image
Background" in the Color panel, View Options and the command palette, and
drop the row's description line so it reads like the one-line rows around
it. The command palette keeps "white" among its keywords.

Verification:
- ThemePanel.image-rows.test.tsx now asserts the row's whole text is the
  short label; ViewMenu.test.tsx checks the renamed menu item. 18 tests
  passed.
- pnpm test: 1251 files passed, 4 skipped (15211 tests passed).
- pnpm lint passed.
- dev-web, reader Settings > Color in dark mode: one-line row, aligned
  with "Invert Image In Dark Mode" and "Override Book Color".
- Not checked on a device.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* fix(reader): keep the sidebar toggle top-left on tablets in portrait

On a tablet held portrait the header dropped its sidebar toggle (#5634),
so "Go to Library" took the top-left spot where the toggle sits on
desktop, and readers moving between the two tapped it by mistake. Show
the toggle in the header on tablets in every orientation. Phones are
unchanged (the toggle stays hidden below `sm:`), and iPhone Duo keeps its
phone bars in every pose.

Verification:
- HeaderBar.test.tsx "is shown on tablet portrait" failed before the
  change ("Unable to find an element with the text: sidebar-toggler")
  and passes with it; a new iPhone Duo case pins the unchanged layout.
- pnpm test: 1250 files passed, 4 skipped (15211 tests passed).
- pnpm lint passed.
- pnpm test:browser HeaderBar.browser + SidebarTogglerAlignment.browser:
  12 tests passed.
- Not checked on an iPad, Android tablet or iPhone Duo device.

Reported by noideaforeal on GitHub (#7292).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* test(view-menu): reject the PDF image toggle in either state

The PDF case queried the exact name "Transparent Image Background", but
MenuItem names a toggle "<label> - ON" or "<label> - OFF", so the query
could never match and the test passed even if the toggle rendered. Match
the label as a prefix.

Verification: rendering the PDF case as an EPUB now fails the test
(1 failed | 16 passed); restored, ViewMenu.test.tsx passes 17/17.

Raised by CodeRabbit on #7294.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-03 17:15:44 +01:00
Huang Xin
4000a85797
fix(koplugin): collect sync workers before KOReader exits (#7293)
* fix(koplugin): collect sync workers before KOReader exits

Exiting KOReader from inside a book quits about a second after the
close-time pushes fork their workers. UIManager:quit() empties the task
queue, so the polls that would collect those workers never run and the
workers keep going after KOReader is gone. The reporter's Kindle often
segfaulted at exit when that happened.

The sync client now keeps the pid of every forked worker (sync RPCs,
book and cover downloads) and wraps UIManager.quit: running workers get
up to 5 s to finish, then the rest are killed and reaped before the
original quit runs.

Verified:
- New syncclient specs: a worker that finishes in the grace period is
  waited for, a stuck one is killed after 50 x 100 ms, and quit doesn't
  wait with no workers. Without the change the first two fail
  ("Expected 3, passed 0" and "Expected 50, passed 0").
- pnpm test:lua (510 passed), pnpm lint:lua.
- Kindle Voyage, firmware 5.13.6, KOReader v2026.07.2-300 (no Turbo),
  exiting from inside the book with auto sync on. origin/main: 2 of 5
  exits left workers running after KOReader was gone (reparented to
  init). This change: 4 of 4 exits logged "waiting for sync workers
  before exit", then killed and reaped the 3 workers still stuck in TLS;
  none outlived KOReader. No segfault in either build on this device, so
  the crash itself was not reproduced.
- Not verified: a worker finishing within the grace period on a device
  (every push on the test network timed out in TLS), and Android.

Fixes #6685. Reported by tramch on GitHub.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* fix(koplugin): deliver finished worker results at exit and keep partial covers out of the cache

Review follow-up for #6685:
- The exit wait reaped a worker that finished inside the grace period
  but never ran its poll, so a token refresh that completed there lost
  its rotated refresh token. Sync RPC workers now register their poll
  with trackWorker, and the exit wait runs it for every worker that has
  finished. Workers that callbacks start then share the same 5 s budget.
- A cover worker killed at exit left a partial <hash>.png that the cover
  cache treats as complete. The worker now writes <hash>.png.part and
  renames it only after a 200; failures remove the .part.

Verified: two new specs fail without this change
("delivers the response of a worker that finishes while KOReader quits":
expected 1 reply, got 0; "keeps a cover under a temporary name until it
is complete": the file was at dst mid-transfer). pnpm test:lua (512
passed), pnpm lint:lua. Not run on the device: the Kindle could not
reach the Readest API at the time (curl timed out after 10 s).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* fix(koplugin): give each cover download worker its own temporary file

Review follow-up for #6685. The manual Download Cover action bypasses
the automatic cover queue, so two workers can download the same cover
at once. With one shared <hash>.png.part, one worker could rename it
while the other was still writing, and the second then reported a
failure. Each worker now writes <hash>.png.<pid>.part.

Verified: "keeps a cover under a temporary name until it is complete"
fails without the change (no h1.png.123.part mid-transfer: expected
"file", got nil). pnpm test:lua (512 passed), pnpm lint:lua.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-03 16:41:51 +01:00
Huang Xin
6e2390fe5e
feat(metadata): search for book covers in app (#7290)
Add Google, Bing and DuckDuckGo image search from Edit Metadata, using the
book title and author. Allow device-local custom search engine templates.
Show the original engine page with explicit image selection, then require
app-owned confirmation before a native fetch so remote pages cannot silently
forge a cover selection. Stage the confirmed image through the existing
cover-save flow. Support desktop and mobile native browsers, with an external search
and file-import fallback on web.

Verification on origin/main 617db1aa3:
- Five affected frontend suites: 50 tests passed; pnpm lint passed.
- Rust formatting and CEF Clippy passed; 202 Rust library tests and four
  native bridge model tests passed.
- Regression for editing a search field beneath an overlapping notification
  failed before the fix (expected aria-pressed false, received true) and
  passes with the fix. Chooser regression failed with the old query input.
- Forged native browser results now wait for app-owned confirmation before
  fetching; confirmation and cancellation tests pass. Verified on Android
  that a forged result stops there, then fetch and Save pass after confirmation.
- Native CEF app: Bing cover selection/save/reload, DuckDuckGo native keyboard
  editing, custom engines and phone/dark/RTL/e-ink layouts exercised.
- Android 15 emulator, WebView 124: Bing query editing, iframe selection,
  confirmation, native download and persisted cover after app restart passed.
  DuckDuckGo input editing and selection passed; two proxy downloads timed out.
  Custom engine add/persist/launch/remove passed.
- Google presented a network challenge on Android; iOS was not built or run.
- Full unit suite is run by the pre-push hook and CI.

Fixes #6653
Reported by lifesucksdude101 on GitHub

Co-authored-by: Claude Code <noreply@anthropic.com>
2026-11-03 15:07:39 +01:00
Huang Xin
b58728c29a
feat(vocabulary): vocabulary builder and Learning/Mastered marks for Word Lens (#7284)
* feat(vocabulary): entry model, sentence extraction and merge

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* fix(vocabulary): revive a word looked up after a delete on a stale device

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* feat(vocabulary): local store, file persistence and backup

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* feat(wordlens): hint Learning words and skip Mastered words

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* feat(dictionary): Learning and Mastered chips, capture lookups to Vocabulary

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* feat(sync): vocabulary table and sync route

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* feat(sync): sync vocabulary across devices

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* feat(vocabulary): export to Anki and CSV

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* feat(vocabulary): hint sources from dictionaries and the AI context dictionary

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* feat(vocabulary): vocabulary builder window

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* chore(i18n): vocabulary strings

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* fix(vocabulary): resolve the sync endpoint on use, not at import

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* fix(vocabulary): save the lookup's sentence from its own paragraph with spacing kept

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* fix(vocabulary): take a dictionary hint from the first definition, not the entry header

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* fix(vocabulary): save a hint on Enter inside the Dialog

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* fix(wordlens): re-render hints after the selection clears, keeping the dictionary open

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* fix(vocabulary): leave ruby hints out of saved sentences, dedupe a sentence across CFIs

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* fix(vocabulary): keep book text in its own direction under an RTL interface

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* fix(vocabulary): a lookup never overrides a Learning or Mastered mark from another device

A word first looked up on a device stamped modifiedAt with the current
time, so its empty state beat a mark set elsewhere in the merge. Lookups
now carry modifiedAt 0. Selections with no letters get no chips or entry.
The migration moves to 032 (031 is taken on main).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* fix(vocabulary): keep syncing past a bad row and cap saved sentences

A rejected row failed the whole push, and the push's failure skipped the
pull, so one bad word stopped vocabulary sync on that device. The server
now skips malformed rows and reports them, the client clears them, and a
failed push no longer prevents the pull. Sentences are cut to a window
around the word and pushes go in batches of 50.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* fix(vocabulary): rebuild from the server when the local word list is lost

The pull cursor lives on the device apart from vocabulary.json. With the
file missing or unreadable, the cursor still claimed everything was
pulled, so the words never came back. Sync now starts over when the file
held no words, trusts the cursor again after that full pull, and keeps a
copy of an unreadable file before it is saved over.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* fix(vocabulary): show typed hints as written; harden sentence capture and IME Enter

A saved hint went through the pack gloss cleaner, which cut it at a comma
or slash. A range the sentence reader couldn't handle could throw inside
the annotator; it now falls back to the selected text. WebKit's
IME-confirming Enter (keyCode 229) no longer saves the hint early.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* test(api): keep /api/sync/vocabulary off language detection and DOMPurify

The vocabulary route syncs on every book open, so it joins the hot routes
that #7274 keeps light. It passes as written: the route imports only the
Supabase client, access check, CORS and the vocabulary entry/wire modules.
Checked the case can fail: with `import '@/utils/sanitize'` added to the
route it fails with `expected [ 'dompurify' ] to deeply equal []`.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* docs(vocabulary): describe lookup capture without naming another reader

Comment-only change; no behavior to test.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* fix(vocabulary): drop the lookbehind from export bolding; guard CSV cells against formulas

CodeRabbit on #7284. boldWord used (?<!…), which WebKit before 16.4 rejects
and which failed the build's check:lookbehind-regex (build_web_app). It now
consumes the boundary before the word in a capture group. CSV text cells that
start with = + - @ tab or CR get a leading apostrophe, so a spreadsheet won't
run book text or a hint as a formula.

Tests that fail without it (export.test.ts): 'bolds whole words without
lookbehind support' (RegExp throwing on lookbehind, as old WebKit does) and
'stops spreadsheet apps from running a cell as a formula'. pnpm build-web +
pnpm check:all: no lookbehind in chunks.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* fix(vocabulary): cap a saved sentence when the selection itself is over the limit

CodeRabbit on #7284. With a selection of 300+ characters the window half was 0
and pre.slice(-0) kept the whole text before it. Such a selection is now cut
to the limit on its own.

Test that fails without it (entry.test.ts): 'caps a selection longer than the
limit' (expected 414 to be less than or equal to 302).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* fix(vocabulary): keep unpushed words pending when the word file loads

CodeRabbit on #7284. load() merged the file into memory with mergeEntries,
which drops the dirty flag, so a word restored from a backup or looked up
before the file loaded was never pushed. Either side being dirty now keeps
the merged word dirty, as applyRemote already does.

Test that fails without it (vocabulary-store.test.ts): 'keeps unpushed
changes pending when the file loads over them' (expected undefined to be
true).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* fix(api): keep database errors out of /api/sync/vocabulary responses

CodeRabbit on #7284. The route returned PostgREST error messages to the
client; it now logs them and returns a fixed message. A since_ts that isn't
a timestamp gets a 400 before any query.

Tests that fail without it (sync-vocabulary.test.ts): 'rejects a since_ts
that is not a timestamp before querying' (expected 200 to be 400) and the two
'keeps database error details out of …' cases.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* fix(vocabulary): run one more sync when one is asked for mid-sync

CodeRabbit on #7284. A debounced sync that fired while a sync was running
got the running promise back, so words changed after its push snapshot
waited for the next change. It now sets a flag and the running sync makes
one more pass. Fake timers in the sync tests are restored in afterEach.

Test that fails without it (vocabularySync.test.ts): 'runs once more when a
sync is asked for while one is running' (pull called 1 time, expected 2).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* fix(wordlens): wait to draw hints when a selection starts while the pack loads

CodeRabbit on #7284. whenSelectionClears guarded only the start of a refresh;
a selection made while the gloss index or OpenCC loaded still had hints
drawn under it, which can close the dictionary popup. The draw step now goes
through whenSelectionClears and is dropped if a newer refresh ran.

Tests (wordlens-section.test.ts): 'waits to draw hints when a selection
starts while the pack loads' fails without it (expected [ '尼莫' ] to deeply
equal []); 'drops a waiting draw once a newer refresh has run' guards the
generation check.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* fix(reader): give the Learning/Mastered chips a 32px hit target and focus ring

CodeRabbit on #7284, per DESIGN.md (32px minimum hit target, the canonical
focus-visible ring). Styling only. Checked on dev-web in Chrome: both chips
measure 32px high in the dictionary popup, and Learning toggles on and off.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* fix(vocabulary): drop the context when a selection leaves no room for it

CodeRabbit on #7284. A 299-character selection skipped the over-limit cut,
but the window half was still 0, and pre.slice(-0) kept the whole prefix.
Context is now dropped whenever the half window is 0.

Test that fails without it (entry.test.ts): 'caps the context when the
selection leaves no room for it' (expected 701 to be less than or equal to
302).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* fix(vocabulary): break merge ties on the display word too

CodeRabbit on #7284. Two lookup-only copies of a word (same modifiedAt, state
and hint) could keep "Serendipity" or "serendipity" depending on argument
order, so devices and the server could show different forms. The tie key now
ends with the display word.

Test that fails without it (entry.test.ts): 'keeps the same display word
whatever the argument order' (expected 'Serendipity' to be 'serendipity').

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* fix(vocabulary): save pulled words to the data file before moving the cursor

CodeRabbit on #7284. The pull saved its cursor right after applying a page,
while the file write waited for the 500 ms save delay; quitting in between
left the cursor past rows the file never got, and later pulls start from the
cursor. The store gains flush(), and the pull awaits it before each cursor
write.

Test that fails without it (vocabularySync.test.ts): 'writes the pulled words
to the data file before moving the cursor' (expected [ [] ] to deeply equal
[ [ 'en:a' ] ]).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* fix(wordlens): defer a whole hint refresh while text is selected

CodeRabbit on #7284. The section-load refresh (and any other caller) cleared
hints before checking the selection, which unwraps the <ruby> under it and
can close the dictionary popup. refreshSectionGlosses now defers itself until
the selection clears; its generation bump drops any older pending draw.

Test that fails without it (wordlens-section.test.ts): 'leaves drawn hints
alone until a live selection clears' (expected [] to deeply equal ['尼莫']).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* fix(reader): save a new sentence for the same word while the dictionary stays open

CodeRabbit on #7284. Lookup capture ran only when the word changed, so
selecting the same word in another sentence with the popup still mounted
saved nothing. It now also runs when the occurrence's book or sentence
changes; repeat sentences are still deduplicated by the store.

Test that fails without it (DictionaryVocabularyChips.test.tsx): 'records a
new sentence for the same word while the popup stays open'.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* fix(vocabulary): write the word file one save at a time, and never mid-load

CodeRabbit on #7284: flush() cleared the save timer but not a save already
writing, so that older write could land over the list flush() had just
saved, after the pull had moved its cursor. Writes now run through one
chain, each saving the list as it is when it starts.

The same race reached backup restore, which wrote the file directly while a
delayed save could still land over it. Backup and restore now flush first.
A save that ran while the file was still loading wrote the partial list in
memory over the file; saves now wait until it has loaded, and load saves
the merged list when words were recorded before it finished.

Tests that fail without it:
- vocabulary-store.test.ts 'flush saves the newest list even while a delayed
  save is still writing' (expected [ 'en:first' ] to include 'en:second')
- vocabulary-store.test.ts 'saves a word looked up while the file is loading,
  without dropping the file': without the loaded check, expected [ 'en:new' ]
  to deeply equal [ 'en:new', 'en:old' ]; without the save after load,
  expected [ 'en:old' ] to deeply equal [ 'en:new', 'en:old' ]
- backup-vocabulary.test.ts 'includes a word saved moments ago…' (expected []
  to include 'en:fresh') and 'keeps restored words when an earlier save
  finishes during the restore' (restored word overwritten)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* test(vocabulary): sync the restore race test on flush instead of a delay

CodeRabbit on #7284: a fixed 50 ms wait didn't show the restore was blocked
on the stalled save, so the test could pass or fail on timing. It now
releases the stalled save only once the restore has called flush(), and
always releases it so a failure can't stall later tests.

Checked it still catches the bug: with restore's flush() removed it fails
with 'expected "flush" to be called at least once'; with it, 3 passed.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-03 15:04:02 +01:00
Huang Xin
8bd96ef9b9
feat(reader): add a straight-line reading ruler (#7288)
* feat(reader): add a straight-line reading ruler

Add a Line style alongside the existing Band ruler, with custom color and
1–8 px thickness. Keep surrounding text undimmed and reuse line snapping,
page navigation, pointer dragging and settings persistence. Use an opaque
theme foreground for monochrome e-ink.

Verification:
- New rendering and settings tests failed before implementation because the
  straight guide and style controls were absent.
- Edge-case tests failed before fixes: scrolled style changes kept 34 px
  geometry, large text was capped at 48 px, and boundary guides extended
  to 1002/802 px outside 1000/800 px viewports.
- Focused suites: 83 tests passed across 5 files.
- Full unit suite: 14997 passed, 16 skipped; 1233 files passed, 4 skipped.
- TypeScript/Biome lint passed (one info in unrelated nativePageTurn.ts).
- Formatting and git diff --check passed.
- Browser and Linux CEF checks covered navigation, dragging, persistence,
  light/dark/e-ink/RTL, phone/tablet layouts, scrolling, spreads, PDF and
  vertical writing. A real touch gesture moved the guide in mobile Chromium.
- Native Android/iOS devices were not exercised.

Requested by localcatgirl-dev on GitHub (#6705).

Co-Authored-By: Claude Code <noreply@anthropic.com>

* fix(reader): refresh fixed-layout ruler size when switching style

Discard the previous ruler size when changing Band/Line style so PDF and
other fixed-layout books immediately use the current style's geometry.

Verification:
- Both new PDF style-switch tests failed before the fix: expected 56 to be
  28 for Band to Line, and expected 28 to be 56 for Line to Band.
- Focused ruler/settings/defaults/persistence suites: 85 tests passed.

Co-Authored-By: Claude Code <noreply@anthropic.com>

---------

Co-authored-by: Claude Code <noreply@anthropic.com>
2026-11-03 14:29:53 +01:00
Huang Xin
372082c76d
fix(sync): support provider downloads and generic transfer history (#7289)
Allow Download All to use active file-sync providers before Readest Cloud,
and record selected downloads and automatic provider file operations in
Cloud File Transfers. Show provider names, file names, progress and errors;
persist observed history without scheduling it as executable queue work.
Reuse queued primary book rows and expose the panel while signed out.

Verification: pnpm test --run passed 1,233 suites and 15,018 tests
(4 suites and 16 tests skipped). pnpm lint, changed-file Biome format
checks and git diff --check passed. Before implementation, provider
Download All regressions failed because the action was absent, queued
provider downloads never invoked the provider runner, and provider-log
tests expected history entries but received an empty array.

Actual web app: authenticated loopback WebDAV bulk/selected downloads,
automatic library/config sync, injected failure, persisted clear actions,
and dark/e-ink/RTL/phone layouts passed in fresh browser contexts. Exact
saved bytes and downloadedAt were checked; one binary GET per book and
no duplicate primary rows. Live other providers and native device safe
areas were not exercised. Provider routing is covered by unit tests.

Reported by lvejun123 on GitHub (#6715).

Co-authored-by: Claude Code <noreply@anthropic.com>
2026-11-03 14:28:06 +01:00
Huang Xin
617db1aa3c
fix(dictionary): stream context dictionary responses (#7285)
Some checks are pending
CodeQL Advanced / Analyze (actions) (push) Waiting to run
CodeQL Advanced / Analyze (javascript-typescript) (push) Waiting to run
CodeQL Advanced / Analyze (rust) (push) Waiting to run
Publish Docker image / build (linux/amd64, ubuntu-latest) (push) Waiting to run
Publish Docker image / build (linux/arm64, ubuntu-24.04-arm) (push) Waiting to run
Publish Docker image / merge (push) Blocked by required conditions
Build with Nix / tests (push) Waiting to run
PR checks / test_web_app (2) (push) Waiting to run
PR checks / nix_flake_check (push) Waiting to run
PR checks / rust_lint (push) Waiting to run
PR checks / koplugin_rust_lint (push) Waiting to run
PR checks / build_web_app (push) Waiting to run
PR checks / test_web_app (1) (push) Waiting to run
PR checks / test_web_browser (push) Waiting to run
PR checks / test_extensions (push) Waiting to run
PR checks / build_tauri_app (push) Waiting to run
Scorecard supply-chain security / Scorecard analysis (push) Waiting to run
Deploy to vercel on merge / build_and_deploy (push) Waiting to run
* fix(dictionary): stream context dictionary responses

Request SSE from custom OpenAI-compatible endpoints and reveal structured
entries or sanitized Markdown while generation is still running. Reset the
60-second timeout on stream activity, including reasoning, and preserve
cancellation, final validation, cache integrity, and thinking-option fallback.

Verification on current origin/main:
- New SSE regression fails without the change: expected undefined to be true
  for the request's stream flag; passes with the change.
- Six affected test files: 88 tests passed.
- Full unit suite: 1233 files passed, 4 skipped; 14992 tests passed, 16 skipped.
- pnpm lint, changed-file formatting, and git diff --check passed.
- Google Chrome with local Ollama qwen3 streamed and completed both built-in
  JSON and custom Markdown; partial content appeared before completion.
- Controlled SSE browser checks covered cancellation and phone dark/e-ink/RTL.
- Gemma3 streamed Markdown successfully but returned malformed final JSON,
  which retained the existing visible validation error.
- Native iOS and Tauri were not exercised.

Fixes #7279
Reported by noideaforeal on GitHub

Co-Authored-By: Claude Code <noreply@anthropic.com>

* fix(dictionary): preserve streamed provider error messages

Normalize structured SSE errors into Error instances so the dictionary shows
the provider's explanation instead of [object Object]. Preserve existing Error
instances and their HTTP status for the thinking-option fallback.

Verification:
- New regression fails before the fix: expected the structured provider error
  to be an instance of Error; passes after normalization and checks the message.
- Six affected suites: 89 tests passed.
- git diff --check passed. The push hook runs lint and the full unit suite.

Co-Authored-By: Claude Code <noreply@anthropic.com>

* fix(dictionary): clear partial entries when streaming fails

Remove incomplete context dictionary content before displaying a stream,
timeout, or final-validation failure. Keep the aborted-request guard so an
older lookup cannot clear the next lookup's container.

Verification:
- Three new regression cases fail before the change because the partial
  definition remains visible after an error, and pass with the change.
- Added cancellation regression preserves the next lookup's content.
- Three affected suites: 55 tests passed; git diff --check passed.
- The required push hook runs formatting, lint, and the full unit suite.

Co-Authored-By: Claude Code <noreply@anthropic.com>

---------

Co-authored-by: Claude Code <noreply@anthropic.com>
2026-11-03 13:13:34 +01:00
tkh
7a0e98f533
fix(sync): sign bucket-root listings with a trailing slash (#7278)
* fix(sync): sign bucket-root listings with a trailing slash

MinIO canonicalizes a bucket-only path with a trailing slash when it
verifies SigV4 (`GET /bucket` becomes `/bucket/`), while aws4fetch signs
the literal pathname. Listing the bucket root therefore failed with
SignatureDoesNotMatch, surfacing as an authentication error in the S3
settings probe even though every object operation worked.

Request the bucket root as `/<bucket>/` so the signed path and the
canonicalized path agree. Object paths (`/<bucket>/<key>`) are
canonicalized verbatim and are unaffected; AWS S3 and R2 accept the
trailing-slash form as well.

Add regression tests asserting that the root listing path ends with a
slash and matches the path that was signed, plus the same for the
deleteDir prefix scan.

* fix(sync): delete ordinary keys when scanning the S3 root

Use an empty prefix for deleteDir('/') so ordinary bucket keys are included.
Replace the empty-root regression fixture with a populated mock bucket that
filters on the requested prefix and removes keys only on DELETE.

Verification:
- Before the fix, the root-deletion test fails: expected [] but both
  library.json and Readest/books/h1/config.json remain.
- After the fix, all 18 S3 provider tests pass.
- Sync tests: 965 passed across 77 files.
- Full unit suite: 12913 passed, 16 skipped across 1095 passing files.
- TypeScript and Biome lint pass; Biome format checks 2710 files.
- Checks run in a credential-free sandbox on the original contributor head.
- Not run: live MinIO/app verification. Both image registries rejected the
  pull, and the upstream binary endpoint returned HTTP 410.

Reported by gilgamesh-tkh on GitHub (#7277).

Co-Authored-By: Claude Code <noreply@anthropic.com>

---------

Co-authored-by: Agents Bot <agents@readest.dev>
Co-authored-by: Huang Xin <chrox.huang@gmail.com>
Co-authored-by: Claude Code <noreply@anthropic.com>
2026-11-03 06:14:27 +01:00
Huang Xin
746a13eb0d
feat(translator): add a Thinking setting to custom LLM translators, fix translator field sync (#7275)
* feat(translator): add a Thinking setting to custom LLM translators (#6865)

Custom OpenAI-compatible translators get a Thinking select: Default leaves
the request unchanged, Off asks the service to skip the model's reasoning.
Each service spells that differently, so Off sends the field for the base
URL's host:

- OpenRouter: reasoning.effort = none
- DeepSeek, Zhipu (bigmodel.cn, z.ai), Volcengine Ark: thinking.type = disabled
- SiliconFlow, DashScope: enable_thinking = false
- anything else (OpenAI, Gemini, Ollama, LM Studio): reasoning_effort = none

A model that can't turn thinking off (Gemini 3, GPT-5 before 5.1, models
that always reason, gpt-4.x) answers 400 to the field. The request is then
retried once without it, and that base URL + model stops sending it, so Off
never breaks a translator that worked under Default. The AI context
dictionary shares the same request helper, so it follows the setting too.
The setting syncs with the translator.

Verified:
- thinking.test.ts runs the real AI SDK with a stubbed fetch and checks the
  request body per host, Default sending nothing, and the 400 retry. Before
  the change, the 9 host cases and the retry case failed, for example
  "expected { …(2) } to match object { reasoning_effort: 'none' }".
- customTranslator.test.ts round-trips `thinking`. With the adapter change
  reverted, 2 tests fail on the missing "thinking": "off".
- The real translator ran against a local OpenAI-compatible mock over HTTP.
  The server received {reasoning_effort: "none"} for Off, no field for
  Default, and for a model that answers 400 one request with the field, the
  retry without it, and the next translation without it.
- The editor was rendered in Chromium (vitest browser) at 360 px and 420 px
  in light, dark, e-ink and RTL.
- pnpm test: 1231 files / 14975 tests passed. pnpm lint clean (one existing
  info in an unrelated file).

Not run: a request to a real hosted service (no API keys on this machine),
and the editor inside dev-web (Custom Translators needs Premium and no
account was signed in). The per-host fields come from each service's docs.

Requested by gixxub on GitHub.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* fix(translator): sync Thinking back to Default, test the context dictionary path

Answers the CodeRabbit review on #7275.

- pack always sends `thinking` ('default' when unset). Replica fields merge
  per key, so leaving it out kept a peer's old 'off' after the user switched
  back to Default. New test "switching Thinking back to Default clears Off on
  other devices" failed before with "expected 'off' to be undefined".
- thinking.test.ts gains "applies to the AI context dictionary too", which
  calls lookupInContext with the real SDK. With main's contextDictionary.ts
  it fails with "expected { model: 'qwen3', messages: [ …(2) ] } to match
  object { enable_thinking: false }".

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* fix(sync): sync re-enabling a custom translator and clearing its temperature

The custom translator adapter left a field out of the push when it was
unset. Replica fields merge per key on the server, so the old value stayed
for other devices: a translator re-enabled here stayed disabled there, and
a cleared Temperature kept the old number. pack now always sends
`disabled` (false when unset) and `temperature` (null when unset); unpack
already reads both back as unset, as do older clients.

The API key is left as it is: a device holding no local key (one that
pulled while its passphrase was locked) would push an empty key on any edit
and wipe it for every device.

Verified: "clearing %s reaches other devices" in customTranslator.test.ts
runs thinking, disabled and temperature through a per-key merge. Before
this change the disabled and temperature cases failed with 'expected
{ id: 'rid', …(10) } to not have property "disabled"' (and
"temperature"); they pass now.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-03 06:00:47 +01:00
Huang Xin
42c81714b4
perf(api): stop hot sync routes loading the TTS engine and DOMPurify (#7274)
Some checks are pending
CodeQL Advanced / Analyze (actions) (push) Waiting to run
CodeQL Advanced / Analyze (javascript-typescript) (push) Waiting to run
CodeQL Advanced / Analyze (rust) (push) Waiting to run
Publish Docker image / build (linux/amd64, ubuntu-latest) (push) Waiting to run
Publish Docker image / build (linux/arm64, ubuntu-24.04-arm) (push) Waiting to run
Publish Docker image / merge (push) Blocked by required conditions
Build with Nix / tests (push) Waiting to run
PR checks / nix_flake_check (push) Waiting to run
PR checks / rust_lint (push) Waiting to run
PR checks / koplugin_rust_lint (push) Waiting to run
PR checks / build_web_app (push) Waiting to run
PR checks / test_web_app (1) (push) Waiting to run
PR checks / test_web_app (2) (push) Waiting to run
PR checks / test_web_browser (push) Waiting to run
PR checks / test_extensions (push) Waiting to run
PR checks / build_tauri_app (push) Waiting to run
Scorecard supply-chain security / Scorecard analysis (push) Waiting to run
Deploy to vercel on merge / build_and_deploy (push) Waiting to run
Most of readest-web's CPU goes to cold Worker isolates, and a cold isolate
pays for the full module graph of the route it serves. The three hottest
routes (/api/sync, /api/sync/replicas, /api/send/inbox/claim) only check a
token and read or write rows, yet each loaded 65-80 local modules:

- services/constants.ts imported two TTS gap numbers from TTSController and
  EdgeTTSClient, which pulled the whole TTS engine (controller, Edge client,
  media overlays, audio players, zip.js, foliate-js, Tauri plugins) and,
  through it, the language detection (franc-min, iso-639-2/3).
- utils/access.ts took the localStorage daily-usage helper from
  translators/utils.ts, which imports utils/lang.ts (language detection).
- utils/misc.ts imported utils/lang.ts for isCaselessUILang.
- utils/transform.ts took a NUL-stripping helper from utils/sanitize.ts,
  which loads DOMPurify.
- bookshelves/fields.ts took getBookPageCount from utils/book.ts, which loads
  the document parsers and language detection.

Each helper now lives in, or next to, a module without those imports: the
gap defaults in tts/gap.ts (re-exported from their old homes), the daily
usage in translators/dailyUsage.ts, isCaselessUILang in utils/lang.ts,
sanitizeString in transform.ts, getBookPageCount in bookshelves/fields.ts
(re-exported from utils/book.ts). BufferedTTSClient now imports TTSController
as a type only, which removes a runtime cycle the old constants.ts import
order had been hiding. Static import graphs, by esbuild metafile: /api/sync
70 -> 19 local modules, /api/sync/replicas 80 -> 20, /api/send/inbox/claim
65 -> 14, none loading franc, iso-639, DOMPurify or any TTS module.

Test that fails without the change: sync-route-light-imports.test.ts loads
each route with the four packages trapped. On main it fails for all three
routes ("expected [ 'dompurify', 'franc-min', ... ] to deeply equal []" for
/api/sync; the language packages for the other two); with the change it
passes.

tts-book-cache-store.test.ts now imports @/utils/access statically: it only
reached that mocked module through constants.ts -> TTSController, and once
that path was gone the dynamically imported sync client bound to the real
module before the mock's importOriginal factory finished.

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-03 04:51:08 +01:00
Huang Xin
bd418a575a
perf(web): run the web Worker near Supabase with Smart Placement (#7273)
Some checks are pending
CodeQL Advanced / Analyze (actions) (push) Waiting to run
CodeQL Advanced / Analyze (javascript-typescript) (push) Waiting to run
CodeQL Advanced / Analyze (rust) (push) Waiting to run
Publish Docker image / build (linux/amd64, ubuntu-latest) (push) Waiting to run
Publish Docker image / build (linux/arm64, ubuntu-24.04-arm) (push) Waiting to run
Publish Docker image / merge (push) Blocked by required conditions
Build with Nix / tests (push) Waiting to run
PR checks / koplugin_rust_lint (push) Waiting to run
PR checks / nix_flake_check (push) Waiting to run
PR checks / rust_lint (push) Waiting to run
PR checks / build_web_app (push) Waiting to run
PR checks / test_web_app (1) (push) Waiting to run
PR checks / test_web_app (2) (push) Waiting to run
PR checks / test_web_browser (push) Waiting to run
PR checks / test_extensions (push) Waiting to run
PR checks / build_tauri_app (push) Waiting to run
Scorecard supply-chain security / Scorecard analysis (push) Waiting to run
Deploy to vercel on merge / build_and_deploy (push) Waiting to run
Most of readest-web's CPU bill comes from cold isolates, not steady
requests. Over 2026-10-27..11-02 the median request used ~9 ms of CPU
while the p99 sat near 1 s; in a live tail sample the 2.5% of requests
costing 1-2 s each (tiny bodies, CPU ~= wall time, every route) carried
~73% of all CPU. A local profile of the built worker shows the same
mechanism: a cold POST /api/sync costs ~120 ms of CPU against ~6 ms warm,
almost all of it module initialisation.

Smart Placement runs the Worker near its back end instead of in every
location, so traffic lands on fewer isolates and they stay warm. API
routes make 1-3 round trips to Supabase in us-east-1, so readers far from
it should also see faster sync responses. Static assets are still served
from the nearest location, and the cron `scheduled()` handler is not
placed.

How it was checked: config only, no behaviour to unit-test. wrangler.toml
parses with the new [placement] table. Effect to be measured after deploy
with the GraphQL workersInvocationsAdaptive query (CPU per request,
cpuTimeP99, wallTimeP50) against the 7-day baseline above; revert by
deleting the [placement] table.

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-02 20:30:48 +01:00
Huang Xin
263d76cb14
feat(android): choose the system dictionary lookup app (#4937) (#7272)
* feat(android): choose the system dictionary lookup app (#4937)

Add System Dictionary > Lookup App on Android. It lists every app that
handles ACTION_PROCESS_TEXT, browsers left out, plus "Ask Every Time".
The chosen app gets every lookup directly. Before, a remembered app
counted only when a browser was among the handlers and two or more
dictionaries remained, so on ROMs where a search app registers the
intent but doesn't answer the https browser probe (Baidu on HyperOS),
lookups always fell through to the system chooser.

The picker replaces the System Lookup App reset row from #4568. That
row could never appear: get_lookup_dictionary and
clear_lookup_dictionary had no Rust commands, so Tauri forwarded them
as getLookupDictionary and the plugin answered "No command
getLookupDictionary found" (seen on 0.12.16). The new get_lookup_apps
and set_lookup_app commands are wired through commands.rs, mobile.rs,
desktop.rs and lib.rs.

Test that fails without the change: LookupDispatchTest
noBrowserPresent_chosenApp_launchesChosenDirectly failed with
"expected:<DispatchExplicit(handler=LookupHandler(packageName=org.goldendict.android,
...))> but was:<LookupDispatch$DispatchImplicit>"; 9/9 pass with it.

Verified on origin/main ab8025cb4 plus this change:
- pnpm test --run: 14961 passed, 16 skipped.
- pnpm lint, pnpm format:check: passed (one existing info finding in
  nativePageTurn.ts).
- pnpm fmt:check, cargo fmt -p tauri-plugin-native-bridge --check,
  pnpm clippy:check, pnpm test:rust (203 passed), lookup_models tests
  (4 passed): passed. Run before rebasing onto ab8025cb4, which changes
  no Rust.
- Gradle :tauri-plugin-native-bridge:testFossGenericPenDebugUnitTest
  LookupDispatchTest: 9 passed.
- Release APK on a Xiaomi 13, HyperOS 3 / Android 16. Before (0.12.16):
  a lookup opened the system chooser with Eudic, Read aloud, Baidu
  Search and Baidu Translate. After: the picker listed those four;
  choosing Eudic in Settings sent "hobbit" straight to Eudic's popup,
  the choice survived a force-stop and relaunch, and "Ask Every Time"
  brought the system chooser back. Checked the row in dark mode, e-ink
  and RTL.

Not run: lookups were triggered by calling the plugin's
show_lookup_popover over CDP, not by selecting a word with System
Dictionary switched on, to avoid changing a synced setting on the test
device. Not tried on a vivo device or with the light theme. HyperOS asks
"Allow Readest to open Eudic?" on the first direct launch; that prompt
is the OS's.

Fuzzy matching for imported dictionaries, also asked for in #4937, is
not part of this change.

Reported by Zephyros-X on GitHub.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* fix(dictionary): label the unset lookup app Default and revert a failed save

Address CodeRabbit's review on #7272:
- "Ask Every Time" promised more than it did. Without a browser, Android's
  own chooser offers "Always", and with a browser Readest's chooser
  remembers the pick. The option now reads "Default", which reuses the
  existing translated key. Forcing a chooser on every lookup would undo
  #4559's remember-the-pick behaviour, so that is left to the maintainer.
- setLookupApp now resolves whether the native save happened, and the
  picker puts the previous selection back when it didn't.

Tests that fail without the change: "puts the picker back when the choice
cannot be saved", plus the setLookupApp result tests ("expected undefined
to be true / false"), and the options list ("expected [ 'Ask Every Time',
... ] to deeply equal [ 'Default', ... ]").

Verified: pnpm test --run 14963 passed, 16 skipped; pnpm lint and
pnpm format:check passed. Release APK on the Xiaomi 13 (HyperOS 3):
the picker shows Default, Eudic, Read aloud, Baidu Search and Baidu
Translate. Picking Eudic sent "riddle" straight to Eudic, and Default
brought back the system chooser. The failed-save revert is covered by
the unit test only, since the bridge doesn't fail on the device.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-02 20:20:05 +01:00
Huang Xin
62272df36c
feat(reader): show background textures in footnote popups (#7268)
* feat(reader): show background textures in footnote popups

Reuse the reader texture beneath footnote content in an isolated stacking
context, preserving backgrounds authored by the book. Cover EPUB and
synthesized data-attribute notes without changing other popup surfaces.

Verification:
- New browser regression cases fail without the change: expected 'none'
  to contain '/images/paper-texture.png' (5 failures).
- Related Chromium browser suites: 21 tests passed. Final theme-identifier
  check: all 10 layout/background tests passed.
- Full unit suite: 14,924 passed, 16 skipped (1,228 files passed).
- pnpm lint, changed-file formatting, and git diff --check passed.
- Linux Tauri/CEF: imported a sample EPUB, selected Paper in settings,
  opened plain, colored, and patterned notes, and inspected screenshots.
  Plain notes show texture; authored fills and gradients paint above it.
- Not exercised on physical e-ink, Android, iOS, macOS, or Windows devices.

Closes #6841.
Reported by noideaforeal on GitHub.

Co-Authored-By: Claude Code <noreply@anthropic.com>

* fix(reader): retain footnote textures when scrolling and in e-ink mode

Scroll the note inside the stationary texture surface. Omit only the app's
e-ink body fill for textured footnote documents, preserving authored body
backgrounds and the main reader's existing fill.

Verification:
- Before the fix, browser regressions fail in both e-ink cases (opaque
  body instead of transparent) and on long-note scrolling (content
  scrollTop 0 instead of greater than its viewport height).
- Related Chromium browser suites: 24 passed.
- Related unit suites: 28 passed.
- pnpm lint, changed-file formatting, and git diff --check passed.
- Linux Tauri/CEF with E-Ink Mode enabled: plain, blue, and patterned
  EPUB notes retain layering; a synthesized note scrolled 5309px while
  the texture surface stayed at scrollTop 0. Screenshots inspected.
- Not exercised on physical e-ink, Android, iOS, macOS, or Windows.

Reported by noideaforeal on GitHub.

Co-Authored-By: Claude Code <noreply@anthropic.com>

* fix(reader): texture footnote arrows (owner: consistent color)

Apply the popup texture to its inner arrow with the same opacity, size and
blend mode, clipping it for all four directions. Other popup arrows retain
their existing appearance, including the e-ink border and resting lifecycle.

Keep authored body foregrounds paired with their backgrounds in textured
notes. Allow Foliate to paint its extracted body background on the note's
view surface; Override Book Color still clears the fill for the texture.

Verification:
- New arrow browser cases fail without the change: 16 failures, background
  image none instead of the popup texture. The unrelated-popup case passes.
- Body color regressions fail without the change: dark text replaces white
  authored text, or a black fill remains under overridden dark text.
- Related Chromium suites: 47 passed (directions, light/dark, e-ink, texture
  removal, other popup surfaces, footnote layout, overflow and stacking).
- Related popup/footnote/texture unit suites: 28 passed.
- pnpm lint and git diff --check passed. Formatting checked on changed files.
- Linux Tauri/CEF: inspected textured arrow screenshot; verified authored
  white-on-black view surface with Override Book Color off and transparent
  surface with dark text when on, with E-Ink Mode enabled.
- Not exercised on physical e-ink, Android, iOS, macOS, or Windows devices.

Reported by noideaforeal on GitHub.

Co-Authored-By: Claude Code <noreply@anthropic.com>

* fix(reader): keep textured footnote pbg fills transparent

Exclude textured footnotes with Override Book Color enabled from the
later dark-mode body.pbg fill. Preserve other pbg behavior.

Add real Foliate paginator coverage that inspects its extracted view
surface for light/dark override states and authored opaque backgrounds.

Verification: the real-renderer dark override regression fails before the
fix with an opaque fill instead of rgba(0, 0, 0, 0). All 53 related browser
tests, pnpm lint, formatting and git diff --check pass. This edge case was
verified in Chromium with the real renderer; no additional native/device
launch was run for this one-line guard.

Reported by noideaforeal on GitHub.

Co-Authored-By: Claude Code <noreply@anthropic.com>

* fix(reader): preserve authored pbg fills in textured footnotes

Exclude textured footnotes from the forced dark-mode pbg fill in both
color-override states. Run the real renderer tests with pbg in both states.

Verification: before the change, the dark non-override real-renderer test
fails with rgb(255, 255, 255) instead of the authored rgb(0, 0, 0).
All 53 related Chromium browser tests, pnpm lint, formatting and git diff
--check pass. No additional native/device launch was run for this guard.

Reported by noideaforeal on GitHub.

Co-Authored-By: Claude Code <noreply@anthropic.com>

---------

Co-authored-by: Claude Code <noreply@anthropic.com>
2026-11-02 19:55:46 +01:00
Huang Xin
ab8025cb4c
feat(reader): make white image backgrounds transparent (#7270)
* feat(reader): make white image backgrounds transparent

Add an opt-in image transparency setting to Theme settings and View Options.
Remove pixels with all RGB channels at least 245 while preserving other
colors and existing alpha. Apply it before optional dark-mode inversion,
cover SVG-wrapped bitmaps and fixed-layout images, and preserve the filter
in the image viewer. Leave PDF page canvases unchanged.

Verified on origin/main at 179603780:
- Full unit suite: 1229 files passed, 14934 tests passed, 16 skipped.
- Final targeted suites: 46 tests passed.
- Browser rendering: 4 tests passed, including exact RGBA pixels and
  reflowable/fixed-layout selector behavior.
- pnpm lint and git diff --check passed.
- Synthetic EPUB exercised in the web reader and Linux CEF, including sepia;
  inspected dark mode and phone-width RTL/e-ink presentation in the browser.
- WebKit could not launch: missing libicudata.so.74. Physical devices were
  not tested.

Before implementation, image-background.test.ts failed five assertions:
undefined default instead of false, absent transparency filters in reflowable
and fixed-layout styles, and absent ordering before inversion. The tests pass
with the change.

Reported by noideaforeal on GitHub (#7045).

Co-Authored-By: Claude Code <noreply@anthropic.com>

* fix(reader): announce image transparency toggle state

Use MenuItem's existing toggled prop so the image transparency row exposes
its ON/OFF state to screen readers while retaining its checkmark.

Verification: the updated ViewMenu test failed before the fix because the
accessible name lacked OFF; all 17 ViewMenu tests pass with the fix and
assert the accessible name changes to ON after activation. TypeScript,
Biome lint, formatting, and git diff --check passed.

Reported by coderabbitai[bot] on GitHub.

Co-Authored-By: Claude Code <noreply@anthropic.com>

* fix(reader): preserve image behavior when transparency is off

Limit SVG bitmap style capture to the new transparency filter so disabling
the option keeps the image viewer's previous behavior. Add regression
coverage for SVG capture before and after activation and browser coverage
for restoring image styles in reflowable and fixed-layout books.

Verification: the SVG regression failed before the fix, receiving an
inversion style instead of the previous null result. With the fix, all 47
focused unit tests and 6 browser tests pass. Lint, formatting, and whitespace
checks pass. A temporary baseline harness compared pre-feature CSS against
the disabled path across 288 reflowable and 1,728 fixed-layout combinations;
all declarations match after whitespace normalization, including after
turning the option on and off for fixed layout.

Co-Authored-By: Claude Code <noreply@anthropic.com>

---------

Co-authored-by: Claude Code <noreply@anthropic.com>
2026-11-02 19:00:22 +01:00
Huang Xin
d5d5cbdb03
fix(library): ignore leading English articles in title sorting (#7271)
Skip a leading A, An or The when comparing book titles, including primary
and secondary sorting, grouped shelves, previews, widgets and search.
Preserve displayed titles, numeric collation and group-name sorting.

Reported by Hyzian on GitHub (#7057).
The default behavior was requested explicitly during implementation.

Verification:
- New title-articles and library/search integration tests failed before the
  change: A Tale sorted before Dune instead of after The Great Gatsby.
- Full unit suite: 1224 files passed, 4 skipped; 14868 tests passed, 16 skipped.
- Related suites: 417 tests passed; final focused verification: 176 passed.
- pnpm lint, changed-file Biome formatting and git diff --check passed.
- Chromium: imported EPUBs, default and descending sort, reload persistence,
  search, and desktop/phone menu without an article toggle; no page errors.
- Native Tauri and mobile builds were not exercised.

Co-authored-by: Claude Code <noreply@anthropic.com>
2026-11-02 18:44:24 +01:00
Huang Xin
74e770e0c4
feat(ios): add fullscreen system dictionary setting (#7269)
* feat(ios): add fullscreen system dictionary setting

Add System Dictionary > Fullscreen on native iOS, retaining the compact
default. Persist the preference, preserve edits during asynchronous
dictionary hydration, and forward the option through the mobile bridge.
Use an opaque UIKit container so fullscreen definitions remain readable
under the app's light and dark appearances.

Regression evidence: the pending-load store tests failed before the
hydration fix with "expected false to be true" and "expected true to be
false". Both now pass, alongside save/reload and iOS-only dispatch tests. The
loading-guard UI test also failed with "expected false to be true" before
disabling the switch until hydration completes.

Verified on origin/main ee1a95503 plus this change:
- pnpm test --run: 14933 passed, 16 skipped.
- pnpm lint and pnpm format:check: passed; lint reports one existing
  informational finding in nativePageTurn.ts.
- pnpm fmt:check, pnpm clippy:check and pnpm test:rust: passed;
  203 Rust tests passed, with warnings from existing dependencies/macros.
- cargo fmt -p tauri-plugin-native-bridge --check and lookup_models
  integration tests: passed (2 tests).
- pnpm build: passed.
- iOS release build and real iPadOS 27 reader lookup verified before the
  final main update and startup guard: compact/fullscreen, light/dark,
  rotation, persistence
  for both switch values after relaunch, and settings in RTL/e-ink mode.
- Native dictionary close action: isolated iPad simulator test passed.

Not exercised on a physical iPhone or older iOS. Physical XCTest automation
was blocked by device authorization timeouts; native close was tested in
an isolated simulator. Web/browser and other native platform end-to-end
suites were not run locally for this iOS presentation change.

Closes #7101.
Reported by arssher on GitHub.

Co-Authored-By: Claude Code <noreply@anthropic.com>

* fix(ios): keep dictionary fullscreen disabled after failed loading

Return an explicit success result from dictionary hydration and enable the
fullscreen preference only after successful loading. Preserve the replica
hydration callback's existing void return contract.

The regression cases use the real dictionary loader and save implementation.
Before this fix, both service-initialization and file-check failures allowed
a click to replace persisted dictionary metadata with an empty list:
"expected [] to deeply equal [ { id: 'saved-dictionary', ... } ]".
Both cases now preserve the saved dictionary and preferences.

Verification:
- pnpm test --run: 14935 passed, 16 skipped across 1232 files.
- Focused dictionary and replica tests: 103 passed across four files.
- pnpm lint: passed, with one existing informational Biome finding.
- pnpm format:check and git diff --check: passed.
- pnpm build: passed.

This follow-up changes TypeScript only. Native device verification and Rust
checks are recorded on the original feature commit and PR; they were not
repeated for this failed-load guard.

Reported by arssher on GitHub (#7101).

Co-Authored-By: Claude Code <noreply@anthropic.com>

---------

Co-authored-by: Claude Code <noreply@anthropic.com>
2026-11-02 18:40:56 +01:00
Huang Xin
1796037808
test(reader): handle cancelled paginator previews in browser tests (#7267)
Race paused capture readiness against preview completion and retry completed
pre-capture cancellations within a bounded wait. Reuse the helper in the
three interruption tests and release paused snapshots during cleanup.

Add Chromium regressions for an immediate null preview and a render during
the initial preview paint frames. Both failed before the fix with:
"cancelled preview must not leave capture readiness pending: expected null
not to be null". Both pass with the fix.

Verified: unit suite 14,911 passed / 16 skipped; browser suite 875 passed /
1 skipped; paginator browser file 35 passed; pnpm lint; Biome formatting;
git diff --check. This is a test-only change with no app UI behavior change.

Reported by chrox on GitHub (#7266).

Co-authored-by: Claude Code <noreply@anthropic.com>
2026-11-02 17:50:41 +01:00
Huang Xin
ee1a955039
fix(ios): decode imported file URL basenames once (#7263)
Keep file URLs encoded through both Open With entrypoints. In openFile,
reuse the URL basename helper to decode the iOS filename once and use that
same name for the temporary copy. Preserve the original URL for native copying.

This keeps reserved characters and literal percent sequences intact in
originalFilename and prevents URI malformed errors for percent filenames.
Android provider and desktop filename handling are unchanged.

Verified: ten regressions failed before the fix across cold-start intent
parsing, live URL ingress and native file opening. Failures included encoded
# and ? in File.name, literal % throwing URIError, and a second decode changing
the temporary basename. All 180 related tests pass, including import metadata,
PDF title/provenance, conversion and filename checksum cases. TypeScript,
Biome lint, formatting and whitespace checks pass; full suite runs in pre-push.
Not run on iOS: this Linux host has no Xcode, simulator or attached iOS runtime.
Development servers remain stopped after host memory pressure.
Found during review of #7253; tracked in #7257.

Co-authored-by: Claude Code <noreply@anthropic.com>
2026-11-02 17:09:03 +01:00
Huang Xin
0c4b602108
fix(account): require explicit confirmation before deleting account (#7258)
* fix(account): require explicit confirmation before deleting account

Show the signed-in email and current plan in the account deletion dialog,
warn about paid plans and purchases (including customization-only unlocks),
and require exact DELETE entry before enabling permanent deletion. Clear
confirmation when the dialog closes or the account changes, and keep the
Delete All Books flow independent.

Verification: nine account-actions regression tests pass. With the original
component restored, the account identity assertion fails because the email
is absent and the typed-confirmation assertion fails because deletion is
enabled immediately. Restoring the fix makes all nine tests pass.

Full unit suite: 1,224 files and 14,866 tests passed; four files and 16 tests
skipped. pnpm lint and changed-file Biome formatting checks passed.
Exercised the actual web app and Linux CEF runtime with synthetic sessions
and intercepted deletion requests. Checked narrow and short viewports,
long email addresses, dark mode, RTL and e-ink. Native Android and iOS not
exercised.

Reported by noideaforeal on GitHub (#7251).

Co-Authored-By: Claude Code <noreply@anthropic.com>

* fix(account): contain keyboard focus in deletion confirmation

Focus the first dialog control on mount, wrap Tab and Shift+Tab around
enabled controls, redirect outside focus into the dialog, and restore the
previous focus on close.

Verification: the two new focus-entry and Tab-wrapping regression tests
fail without the change. All 12 account-actions tests pass with it.
pnpm lint passed. Actual browser keyboard navigation passed across six
scenarios covering desktop, narrow and short viewports, long email,
dark mode, RTL and e-ink, using intercepted deletion requests. Native
Android and iOS not exercised. Full suite runs in the pre-push hook.

Addresses CodeRabbit review on #7258. Original report by noideaforeal
on GitHub (#7251).

Co-Authored-By: Claude Code <noreply@anthropic.com>

* fix(account): refresh entitlements after restoring purchases

Refresh the auth session after purchase verification so the account deletion
confirmation includes benefits restored during the current session.

Verification: the new profile-page regression fails without the change
(expected refresh once, got zero), then passes with it. All 13 confirmation
tests and pnpm lint pass. The native Android/iOS store-restore flow was not
exercised. The pre-push hook runs formatting, lint and the full unit suite.

Reported by noideaforeal on GitHub (#7251). Addresses the follow-up review
on #7258.

Co-Authored-By: Claude Code <noreply@anthropic.com>

* fix(account): report session refresh failure after restore

Return a success flag from auth refresh and use the existing restore error
message when verified entitlements cannot be refreshed. Existing callers
that ignore the refresh result retain their behavior.

Verification: five new outcome assertions fail without this change (refresh
returns undefined and restore incorrectly reports success), then pass with
it. All 21 related auth and account confirmation tests and pnpm lint pass.
Native Android/iOS purchase restoration was not exercised. The pre-push
hook runs formatting, lint and the full unit suite.

Reported by noideaforeal on GitHub (#7251). Addresses review on #7258.

Co-Authored-By: Claude Code <noreply@anthropic.com>

---------

Co-authored-by: Claude Code <noreply@anthropic.com>
2026-11-02 16:59:06 +01:00
Huang Xin
f004fa39fe
feat(library): add searchable history dropdown (#7261)
* feat(library): add searchable history dropdown

Show recent book and full-text searches below the library search field,
with per-item removal and Clear All. Reuse BoxedList styling, preserve
legacy full-text history, and translate the new labels in all locales.
Apply selections immediately, including reselecting a query while its
clear action is still waiting for the debounced URL update.

Verification:
- pnpm test --run: 1224 files passed, 4 skipped; 14863 tests passed,
  16 skipped. Final related run: 4 files and 13 tests passed.
- Library header Chromium tests: 18 passed across phone, tablet,
  desktop, RTL and e-ink layouts.
- Playwright search-history test passed with an imported Alice EPUB,
  covering book/full-text reuse and persisted deletion.
- pnpm lint passed; git diff --check passed.
- Running web app and isolated Linux CEF app exercised; screenshots
  inspected in light, dark, e-ink and RTL layouts.
- Before implementation, dropdown tests failed to find the Dune entry.
  Before the immediate-apply fix, the e2e test expected Alice but got
  an empty input after clear and reselect; it passes with the fix.
- Not tested on physical Android or iOS devices. Production builds
  were not run; no dependencies or Rust code changed.

Reported by d3m3vilurr on GitHub (#7126).

Co-Authored-By: Claude Code <noreply@anthropic.com>

* fix(library): preserve search history deletion during pending writes

Apply pending book input before deleting history and invalidate running
full-text history writes when their query is removed or all history is
cleared. A later scan can save the same query again. Also record the query
when switching from text search to book search.

Verification:
- New full-text tests failed before the fix: deleted queries returned on
  completion (expected false, received true).
- New book deletion tests failed before the fix: pending search was not
  applied before removal. Mode-switch e2e failed with missing book history.
- All 15 focused unit tests, 18 header browser tests, and four app e2e
  tests pass. Typecheck, Biome lint and patch whitespace checks pass.
- Full unit suite runs again in the pre-push hook.
- Original CI's paginator browser timeout is tracked separately in #7266.
- Physical mobile devices and production builds were not run.

Co-Authored-By: Claude Code <noreply@anthropic.com>

* fix(library): save explicitly applied book searches

Record Enter and history selections even when the query already matches
the URL. Keep pre-delete application separate so deletion stays effective.

Verification:
- New unit regression failed before the change: expected ['Dune'], got [].
- New app regression failed before the change: book history was null
  after Enter on the current query.
- 16 focused unit tests and five app e2e tests pass, including deletion
  regressions. Full format, lint and unit checks run in the pre-push hook.
- Physical mobile devices and production builds were not run locally.

Co-Authored-By: Claude Code <noreply@anthropic.com>

---------

Co-authored-by: Claude Code <noreply@anthropic.com>
2026-11-02 16:57:09 +01:00
Huang Xin
a70e326d07
feat(kosync): support original filename checksums (#7253)
* feat(kosync): support original filename checksums

Offer File Name in KOReader Sync settings and use MD5 of the saved original
basename, including its extension, matching KOReader's getFileNameDigest.
Keep the existing content digest when the original name is unavailable and
explain that fallback in settings. Content matching remains the default.

Verified: new tests first failed on the missing File Name option and on
filename-mode GET/digest assertions returning the content hash. All 35
related tests pass, including exact Unicode/literal names, changed bytes,
legacy and ABS fallback, GET/PUT consistency, and settings persistence.
Full suite: 1,223 files passed (4 skipped), 14,836 tests passed (16 skipped).
TypeScript, Biome lint, formatting and whitespace checks pass.

Real web app: selected File Name, reloaded, imported sample-alice.epub,
and observed progress GET under its independently calculated filename MD5.
Desktop light, phone dark/RTL and tablet e-ink screenshots were checked.
Browser progress upload was inconclusive; GET/PUT identity is unit-tested.
No physical XTEINK/KOReader device or native app was exercised. Development
servers were stopped by the harness under memory pressure after testing.
Reported by kigrup on GitHub (#7118).

Co-Authored-By: Claude Code <noreply@anthropic.com>

* fix(kosync): pull again after switching checksum method

Reset pull and conflict-resolution state when checksum method changes so
filename-keyed progress is checked before automatic uploads resume. Reject
queued pushes captured under the previous method. Unrelated settings edits
retain the previous pull state.

Verified: two hook regressions first failed because changing checksum method
made no new GET. Resetting the pull alone also exposed a stale queued upload;
the old-method guard fixes that assertion. All 51 related hook/client/settings
tests pass, as do TypeScript and Biome lint. Full suite runs in pre-push.

Also executed KOReader's actual getFileNameDigest and splitFilePathName source
functions with its ffi/sha2.lua under its bundled Linux LuaJIT. All four vectors
match Readest: My Book.epub, a Unicode/percent/uppercase-extension basename,
a literal-backslash POSIX basename, and sample-alice.epub. KOReader source
revision: 51db00155ce4ff5a1cd7aded0e95efd9102da588.
Native/device UI was not exercised; development servers remain stopped.
Reported by kigrup on GitHub (#7118).

Co-Authored-By: Claude Code <noreply@anthropic.com>

* fix(kosync): discard pending work after checksum changes

Invalidate pending pulls, conflict previews, position conversions and uploads
when the checksum method changes. Clear the previous conflict immediately;
old continuations cannot navigate or release automatic uploads for the new
identity. Unrelated settings changes retain the existing sync state.

Verified: delayed-response regressions first failed because an old empty GET
changed conflict to synced, an old preview replaced the new conflict, and an
old conversion navigated the reader. A delayed upload conversion also failed
before its guard. All 56 related hook/client/settings/provider tests pass.
TypeScript, Biome lint, formatting and whitespace checks pass. The complete
suite runs in the required pre-push hook. Native/device UI was not exercised;
development servers remain stopped after host memory pressure.
Reported by kigrup on GitHub (#7118).

Co-Authored-By: Claude Code <noreply@anthropic.com>

* fix(kosync): discard stale converted position before caching

Capture the checksum generation before converting a position and reject a
stale result before it writes the fallback XPointer cache.

Verified: the pending upload conversion test first failed because the cache
changed from empty to the old XPointer after a checksum-method switch. It now
passes with all 56 related hook/client/settings/provider tests. TypeScript,
Biome lint, formatting and whitespace checks pass. Full suite runs in the
required pre-push hook. Native/device UI was not exercised; development
servers remain stopped after host memory pressure.
Reported by kigrup on GitHub (#7118).

Co-Authored-By: Claude Code <noreply@anthropic.com>

* fix(kosync): use title filename fallback (owner: use a {title}.{ext} as the filename)

When File Name is selected, hash the saved original filename or synthesize
{title}.{ext} from the current title and lowercase format extension. Update
the settings explanation. File Content retains its existing digest behavior.

Verified: four checks failed before the change: two legacy filename digest
cases, the progress GET digest and the settings explanation. All 57 related
hook/client/settings/provider tests now pass, covering GET/PUT consistency,
Unicode titles, original filename precedence and File Content ABS behavior.
TypeScript, Biome lint, formatting and whitespace checks pass. Full suite runs
in the required pre-push hook. Native/device UI was not exercised; development
servers remain stopped after host memory pressure.
Reported by kigrup on GitHub (#7118).

Co-Authored-By: Claude Code <noreply@anthropic.com>

* fix(kosync): order pulls after pending progress uploads

Serialize progress uploads and wait for pending writes before pulling a new
checksum identity. Recheck generation before starting a queued upload or pull,
so a checksum switch discards queued work from the previous method. This
preserves request ordering for servers that alias document hashes.

Verified: two hook regressions failed before implementation because a new
pull overtook an active upload and two uploads ran concurrently. All 59
related hook/client/settings/provider tests pass after the fix. TypeScript,
Biome lint, formatting and whitespace checks pass. Full suite runs in the
required pre-push hook. CrossPoint's writeDeviceProgress and progress GET
source confirm canonical document mapping; no live server/device was tested.
Development servers remain stopped after host memory pressure.
Reported by kigrup on GitHub (#7118).

Co-Authored-By: Claude Code <noreply@anthropic.com>

* fix(kosync): shorten filename tip (owner: Remove the last sentence.)

Keep only the sentence describing the original filename and extension.
The title-and-extension fallback behavior is unchanged.

Verified: the component test first failed to find the shortened tip, then
both settings tests passed after the text change. Full checks run through
the required pre-push hook. The app was not relaunched after development
servers were stopped for host memory pressure.
Reported by kigrup on GitHub (#7118).

Co-Authored-By: Claude Code <noreply@anthropic.com>

* fix(kosync): reset sync when a title fallback digest changes

Subscribe to the current book and track its effective document digest. Reset
pull and conflict state when that digest changes, including legacy-book title
edits in filename mode. Discard pending work and queued pushes from the prior
digest. Stable digests do not repull after a title edit.

Verified: two title-edit regressions failed before implementation because no
new GET was made and the new identity remained checking. All 63 related
hook/client/settings/provider tests pass, including binary/original-filename
stable-identity controls. TypeScript, Biome lint, formatting and whitespace
checks pass. Full suite runs in the required pre-push hook. Native/device UI
was not exercised; development servers remain stopped for host memory pressure.
The separate iOS filename decoding defect is tracked in #7257.
Reported by kigrup on GitHub (#7118).

Co-Authored-By: Claude Code <noreply@anthropic.com>

---------

Co-authored-by: Claude Code <noreply@anthropic.com>
2026-11-02 15:40:43 +01:00
Huang Xin
4b8da3715f
feat(reader): add dialogue highlighting weight options (#7256)
Add independent Normal, Slightly heavier and Bold dialogue weights. A thin
current-color stroke provides subtle emphasis for fonts with regular/bold
faces. Weight alone enables marking, and Bold reaches explicitly regular
text inside dialogue. Persist and reset through the existing settings paths
and translate the new labels in all supported non-English locales.

Test-first: the new picker, default, marking and CSS assertions failed
before implementation. The descendant regression failed with expected bold
but received 400 before the Bold-only descendant rule.

Verified: 78 focused tests; full suite 14,835 passed, 16 skipped across
1,223 passing files (4 skipped); pnpm lint; source/locale formatting; JSON
validity; git diff --check. Android x86_64 debug APK build passed.
Real app checks passed on web, Linux CEF and Android 15 / WebView 124,
including weight-only styling, nested text, persistence and reset. Web
screenshots covered phone/tablet, dark mode, e-ink and RTL. iOS not run.

Reported by lambda3141 on GitHub (#7250).

Co-authored-by: Claude Code <noreply@anthropic.com>
2026-11-02 14:33:40 +01:00
Huang Xin
5dfe48e553
fix(reader): highlight long punctuated single-quoted dialogue (#7255)
* fix(reader): highlight long punctuated single-quoted dialogue

Allow punctuation-terminated single quotes within one paragraph to use the
existing 2048-character quote limit. Keep the 300-character loose fallback
and continued-paragraph limits unchanged.

Regression: before the fix, the 600- and 2048-character cases returned no
highlight spans, and a long speech with word-final apostrophes stopped at
‘We’re goin’. All seven new regression cases pass with the fix.

Verified:
- Dialogue utility and settings suites: 77 tests passed.
- Full unit suite with --maxWorkers=1: 1223 files / 14834 tests passed,
  16 tests skipped. Initial four-worker run failed with an XPointer oracle
  timeout and eight worker errors; the five affected files passed separately
  with one worker. The failed run remains recorded.
- pnpm lint, Biome checks on changed files, and git diff --check passed.
- Repro EPUB in web and Linux Tauri/CEF: all 580 speech characters highlighted;
  narration, long fallback quotes, and paragraph boundaries remain correct.
- Web checks included desktop/phone/tablet, light/dark, e-ink, RTL content,
  and both book-layout settings. 20000 short-quote inputs matched identically.

Not verified: Android and physical-device safe areas. The reused CEF binary
exited 139 when the isolated windows were closed after successful checks;
its shutdown failure was not investigated in this change.

Reported by lambda3141 on GitHub (#7249).

Co-Authored-By: Claude Code <noreply@anthropic.com>

* fix(reader): preserve short quotes before oversized dialogue

Retry the existing short single-quote fallback at an opening mark when
its punctuation-terminated match exceeds the 2048-character limit.
Otherwise a distant closer suppresses a valid short quote.

Regression: the new oversized-match fallback test failed before this
change with expected ['‘Hello’'] but received []. It now passes. Added
304 characters as the first changed plain-punctuated boundary.

Verified: 79 dialogue and settings tests passed; pnpm lint and diff
whitespace check passed. Web EPUB import confirmed the recovered short
quote, full 580-character speech, paragraph limits, both layout modes,
and e-ink across desktop, phone and tablet viewports. Android and native
app were not rerun for this follow-up. Full suite runs in pre-push.

Reported by lambda3141 on GitHub (#7249).

Co-Authored-By: Claude Code <noreply@anthropic.com>

---------

Co-authored-by: Claude Code <noreply@anthropic.com>
2026-11-02 14:33:01 +01:00
Huang Xin
763242049a
fix(reader): release volume keys while reader controls are open (#7254)
Return volume keys to system volume control while toolbars, menus or
Settings are open. Check current visibility for forwarded native events,
and restore page-turn interception once controls close and TTS is idle.
Reuse the existing reader overlay detection and shared document observer.

Verified on current origin/main d5e10369b:
- Regression tests failed before the fix: interception remained true with
  controls open, and forwarded volume-down called view.next().
- Volume-key tests: 28 passed, including menu state changes, paragraph
  navigation, TTS overlap and parallel-reader interception cleanup.
- Full unit suite: 1223 files passed, 4 skipped; 14840 tests passed,
  16 skipped. pnpm lint and changed-file Biome checks passed.
- Android x86_64 debug APK built and verified on the API 35 emulator with
  an EPUB. Before: volume-down paged under View Options. After: volume
  changed 4 -> 5 -> 4 with toolbars/menu/Settings open and page unchanged;
  hiding controls restored paging with volume unchanged.
- Independent code review found no correctness or regression issues.
- Not run on iOS or a physical Android device.

Closes #7246
Reported by lambda3141 on GitHub

Co-authored-by: Claude Code <noreply@anthropic.com>
2026-11-02 14:31:34 +01:00
Huang Xin
d5e10369b4
fix(library): preserve original filenames and use PDF filename titles (#7237)
Some checks are pending
CodeQL Advanced / Analyze (actions) (push) Waiting to run
CodeQL Advanced / Analyze (javascript-typescript) (push) Waiting to run
CodeQL Advanced / Analyze (rust) (push) Waiting to run
Publish Docker image / build (linux/amd64, ubuntu-latest) (push) Waiting to run
Publish Docker image / build (linux/arm64, ubuntu-24.04-arm) (push) Waiting to run
Publish Docker image / merge (push) Blocked by required conditions
Build with Nix / tests (push) Waiting to run
PR checks / koplugin_rust_lint (push) Waiting to run
PR checks / build_web_app (push) Waiting to run
PR checks / nix_flake_check (push) Waiting to run
PR checks / rust_lint (push) Waiting to run
PR checks / test_web_app (1) (push) Waiting to run
PR checks / test_web_app (2) (push) Waiting to run
PR checks / test_web_browser (push) Waiting to run
PR checks / test_extensions (push) Waiting to run
PR checks / build_tauri_app (push) Waiting to run
Scorecard supply-chain security / Scorecard analysis (push) Waiting to run
Deploy to vercel on merge / build_and_deploy (push) Waiting to run
* fix(library): preserve import filenames and use PDF filename titles

Save each imported file's original basename, including its extension, on
the local Book record. Use the filename stem as the PDF display title while
preserving embedded metadata and the sourceTitle used to locate managed
files. Retain the original filename when re-importing a managed copy.

Regression evidence: before the fix, import-metahash and
import-docx-conversion had 13 assertion failures for missing
originalFilename fields and PDF titles still reading PowerPoint
Presentation. Both suites pass with the change.

Verified:
- Full unit suite: 1220 files passed, 4 skipped; 14648 tests passed,
  16 skipped (before updating to origin/main a2dd013a4).
- On origin/main a2dd013a4: six import suites plus useProgressSync,
  7 files / 124 tests passed.
- pnpm lint passed; formatting and git diff --check passed.
- Real web app: imported Device_Manual_V2.1.pdf with embedded title
  PowerPoint Presentation; filename title and originalFilename persisted
  after reload.
- Windows desktop not tested. Linux CEF verification was incomplete:
  the reused binary rendered a blank frontend in the isolated harness.

Reported by xiongshaowei on GitHub.
Refs #7230.

Co-Authored-By: Claude Code <noreply@anthropic.com>

* fix(library): preserve question marks in import basenames

Derive local basenames without the URL helper's query stripping. For local
path imports use the supplied path, since NativeFile.name may already have
been shortened by that helper. Remote and provider imports retain their
resolved file names and URL fallback behavior.

The new File and path regression cases fail before this change with
originalFilename/title 'manual' instead of 'manual?rev1.pdf'/'manual?rev1'.
They now pass and verify two revisions remain separate library records.
A URL query fallback test also passes. Six import suites: 82 tests passed.
pnpm lint and formatting passed. The pre-push hook reruns the full suite.

Co-Authored-By: Claude Code <noreply@anthropic.com>

* fix(library): retain filename provenance across import and sync

Keep literal POSIX backslashes in import basenames and PDF identity, while
recognizing explicit Windows paths. Strip queries only from web URL fallback
names and preserve explicitly resolved filenames.

When a cloud-restored PDF lacks its original filename, reimporting its exact
managed path preserves the stored title and metadata hash. File sync fills
missing original filenames without changing titles, storage paths, or clocks.

Verification: four importer regressions failed first (URL fallback, two
backslash input forms, and cloud-restored managed copy). Three sync assertions
failed first for missing provenance and repair detection. All 232 tests across
11 affected suites pass with the fixes. pnpm lint, Biome formatting, and git
diff --check pass. Real web imports and reload retain three distinct filename
titles, original basenames, and embedded metadata. Windows desktop was not
tested; the earlier isolated Linux CEF harness remained blank. The full suite
runs again in the pre-push hook.

Reported by xiongshaowei on GitHub.

Co-Authored-By: Claude Code <noreply@anthropic.com>

* fix(library): exclude URL fragments from import fallback names

Remove the fragment before deriving the fallback name for a remote file,
while keeping explicitly resolved filenames unchanged.

Verification: the new fragment regression failed first because originalFilename
was manual.pdf#page=2 instead of manual.pdf. All 94 tests across the importer
metadata and web service suites pass, including query-plus-fragment and explicit
question-mark/hash filename cases. pnpm lint, formatting, and git diff --check
pass. Full unit tests run in the pre-push hook. Native device verification was
not repeated for this web URL fallback change.

Reported by xiongshaowei on GitHub.

Co-Authored-By: Claude Code <noreply@anthropic.com>

* fix(library): decode remote basenames after parsing the URL path

Derive a web remote file's fallback name from its final pathname segment before
decoding. This excludes queries and fragments, decodes reserved characters, and
preserves encoded backslashes as filename characters. Keep the encoded spelling
when pathname bytes cannot be decoded as UTF-8. Explicit filenames bypass this.

Verification: six new URL cases failed before the fix, covering C++, a slash
inside the query, malformed query/path bytes, and two encoded backslash names.
All 100 tests in the importer metadata and web service suites now pass. pnpm
lint, Biome formatting, and git diff --check pass. The full suite runs in the
pre-push hook. Native device verification was not repeated for this web fallback.

Reported by xiongshaowei on GitHub.

Co-Authored-By: Claude Code <noreply@anthropic.com>

* test(library): cover Android provider display names on import

Verify opaque Android content URIs resolve the provider display name through
Tauri basename, for both external-storage and staged-provider file paths.
Verify importBook uses that resolved File.name for originalFilename, PDF title,
and salted identity instead of parsing the document identifier.

Verification: all 114 tests across the import metadata, web service, and native
service suites pass, as do pnpm lint, formatting, and git diff --check. This is
coverage of the existing basename flow, so no production behavior changed.
Android native basename was inspected and queries OpenableColumns.DISPLAY_NAME.
UI verification could not run against the available emulator because its
existing development WebView shows an unavailable URL. The full unit suite runs
in the pre-push hook.

Reported by xiongshaowei on GitHub.

Co-Authored-By: Claude Code <noreply@anthropic.com>

* fix(library): preserve resolved filenames as atomic basenames

Do not split a resolved File.name again during original filename capture.
Local path basenames were already extracted, while a decoded URL segment may
contain a slash that belongs to its filename identity.

Verification: the two-file URL regression failed first with one/part.pdf reduced
to part.pdf and a different salted hash. It now passes and verifies two live
records with distinct filename titles and metadata hashes. All 138 tests across
eight import/native suites pass. pnpm lint, formatting, and git diff --check
pass. The full suite runs in the pre-push hook. Device UI checks were not
repeated for this filename capture change.

Reported by xiongshaowei on GitHub.

Co-Authored-By: Claude Code <noreply@anthropic.com>

* refactor(library): simplify import filename handling (owner: refactor and simplify it)

Replace nested filename selection with explicit URI and local-path branches.
Resolve the managed-copy title/hash exception in one block instead of spreading
it across a boolean and three ternaries. Use the resolved title directly and
avoid PDF stem processing for non-PDF imports.

Verification: this is a control-flow refactor with no intended behavior change.
All 138 tests across eight import/native suites pass both before and after.
pnpm lint, Biome formatting, and git diff --check pass. Existing regressions
cover provider names, local special characters, Windows paths, decoded URLs,
conversion, and managed-copy identity. Full tests run again in the pre-push
hook. Device UI checks were not repeated for this refactor.

Reported by xiongshaowei on GitHub.

Co-Authored-By: Claude Code <noreply@anthropic.com>

* fix(library): share URL filename parsing across native and web imports

Reuse the URL pathname basename decoder in native and web filesystems. Native
URL fallbacks now exclude fragments and query separators and preserve decoded
filename characters, while explicit names remain unchanged. Use the existing
platform-aware path normalizer for managed-copy comparisons.

Verification: the new native URL and case-variant managed-copy regressions
failed before the fixes. All 146 tests across eight affected import/native
suites pass. pnpm lint, formatting, and git diff --check pass. Full tests run
in the pre-push hook. Device UI checks were not repeated; prior platform
verification limitations remain recorded on the PR.

Reported by xiongshaowei on GitHub.

Co-Authored-By: Claude Code <noreply@anthropic.com>

* fix(library): keep extensionless PDF downloads distinct

Use the existing file hash as the PDF identity salt when a remote URL does
not provide a .pdf filename. Keep the query-free title and original filename.
This prevents distinct query-selected downloads with identical metadata from
replacing one another's managed files.

Verified: the new extensionless-download regression failed before the fix
(expected two live books, received one), then all 147 affected tests passed.
pnpm lint passed with one unrelated informational notice; diff check passed.
Reported by xiongshaowei on GitHub (#7230).

Co-Authored-By: Claude Code <noreply@anthropic.com>

* fix(library): retain extensionless PDF identity on reimport

Select the PDF identity salt from the preserved original filename rather than
the current input URL. Extensionless imports keep content-based identity when
the same files are reopened from local managed paths.

Verified: the extended two-download regression first failed because both
metadata hashes changed to the shared download stem. The correction preserves
both hashes, original names and live records without removing managed files.
Reported by xiongshaowei on GitHub (#7230).

Co-Authored-By: Claude Code <noreply@anthropic.com>

* fix(library): persist import provenance through cloud sync (owner: Can we simplify it?)

Add nullable books.original_filename, database mappings and blank-fill sync
merging so imported provenance survives cloud restoration and old clients.
Migration 031 must be applied before deploying the updated server.

Simplify PDF title/identity selection into three direct cases and normalize
the name once. Keep fallback metadata stable on managed-copy reimport and
refresh stale batch metadata keys after successful imports.

Verified: new regressions failed first for stale index keys, sanitized PDF
fallback titles, transform round trips and cloud filename merging. All 242
related tests pass, as do TypeScript, Biome lint and formatting checks. Actual
web imports, local reimports and reload preserve names and separate identities.
Migration applied twice successfully in isolated PostgreSQL, preserving null
legacy rows and round-tripping a Unicode filename. No live database changed.
Reported by xiongshaowei on GitHub (#7230).

Co-Authored-By: Claude Code <noreply@anthropic.com>

* refactor(library): resolve import filenames in openFile (owner: hide the filename parsing in openFile)

Have native and web filesystem openFile return a File whose name is the resolved
basename. Keep URL and Android provider resolution at that boundary and share
literal local-path basename parsing between the filesystem implementations.
The importer now reads fileobj.name without parsing the source path again.

Verified: eight new filesystem assertions failed before the changes for full
web paths, literal POSIX backslashes, question marks and percent-encoded-looking
local or supplied names. All 252 affected tests pass, as do TypeScript and Biome
lint. Existing importer mocks now provide resolved basenames; the obsolete
empty-name filesystem fallback test was removed.
Reported by xiongshaowei on GitHub (#7230).

Co-Authored-By: Claude Code <noreply@anthropic.com>

* fix(library): resolve relative Windows import basenames

Normalize native Windows separators before extracting a local basename, so
relative and drive-relative paths satisfy the openFile name contract while
POSIX backslashes remain literal.

Verified: relative and root-relative Windows regression cases failed first
with directory components in File.name. The same POSIX relative name remains
literal. All 139 filesystem/importer tests and TypeScript/Biome lint pass.
Windows UI was not exercised on this Linux host.
Reported by xiongshaowei on GitHub (#7230).

Co-Authored-By: Claude Code <noreply@anthropic.com>

* fix(library): preserve PDF identity and edited titles (owner: just use the origin filename as the default title)

Use the filename stem only as the initial PDF display title. Preserve stored
PDF titles and metadata hashes on exact-file reimport, and leave existing
books without filename provenance as they are. Keep the original content
hash and new-import metadata-hash calculations, removing content-salt and
managed-copy identity migration branches and their index maintenance.

Verified: two new regressions failed first because reimport replaced edited
or legacy titles and metadata hashes. All 81 importer tests now pass; lint
and whitespace checks pass. In the real web app, importing a PDF, editing
its title through Book Details, reloading, reimporting, and reloading again
preserved the edited bookshelf title, original filename, and both hashes.
Native UI was not repeated for this title-only simplification.
Reported by xiongshaowei on GitHub (#7230).

Co-Authored-By: Claude Code <noreply@anthropic.com>

* refactor(library): clarify native filename branches (owner: Why the change is so ugly?)

Resolve URL and provider names within their early-return branches, then
select the local filename. Remove the overwritten mutable filename and
nested platform/path ternary while preserving existing naming behavior.

Verified with 141 passing native/web filesystem and importer tests, plus
TypeScript, Biome lint, and git diff --check. This is a control-flow cleanup;
no behavior change or new regression test is introduced. Native UI was not
repeated for this refactor.

Co-Authored-By: Claude Code <noreply@anthropic.com>

---------

Co-authored-by: Claude Code <noreply@anthropic.com>
2026-11-02 11:52:20 +01:00
Huang Xin
4f9395859c
fix(security): remediate Dependabot dependency alerts (#7248)
* fix(security): upgrade direct ZIP readers to 9.0.5

Upgrade the app, native narration reader and Windows thumbnail provider;
adapt fallible filenames and optional data offsets. Update both app
lockfiles and the thumbnail lock while preserving unrelated pins.

Verified: 201 app Rust tests, 24 native TTS tests, 6 thumbnail tests under
Wine (1 existing ignored), strict app clippy, formatting and locked CEF
Linux dependency graph. Thumbnail strict clippy reproduces 3 existing
lints on the original source; it passes with those CLI lint allowances.
CEF compilation and native Windows device testing were not run.

This is a dependency/API migration covered by existing archive tests;
no new application behavior is intended. The Windows updater retains
ZIP 4 because its patched release requires an incompatible Tauri family.

Co-Authored-By: Claude Code <noreply@anthropic.com>

* fix(security): update vulnerable JavaScript dependencies

Raise patched dependency floors, scope the modern minimatch upgrade to
v10 consumers, and patch deepmerge prototype writes in both merge loops.
Upgrade the SVG renderer and keep its font shaper external so Node can
load its WASM asset when generating PNGs.

Regression tests fail before the fixes: deepmerge inherits attacker
properties; minimatch expands 256 patterns instead of 64 and performs
500500 comparisons instead of zero. The unpatched image upgrade fails
with a dynamic require of fs / missing hb.wasm. All 31 new tests pass
with the fixes, including actual translation and PDF vendor consumers.

Verified: full unit suite 14714 passed/16 skipped; final focused tests
31 passed; lint, formatting, frozen install, web build and Tauri frontend
build passed. Final web build was repeated after the renderer patch.
Nix hashes still need CI regeneration; CEF compilation was not run.
Version-based audits still flag patched deepmerge and legacy minimatch
3/5, which lack this advisory's vulnerable optimizer.

Co-Authored-By: Claude Code <noreply@anthropic.com>

* build(nix): request fresh security dependency hashes

Invalidate the pnpm and Cargo fixed-output hashes so the PR dependency
check computes the updated stores instead of substituting old cached
stores. Replace both values with the CI-reported hashes before merge.

Verified the diff changes only the two affected hash fields; local Nix
is unavailable. CI verification is pending on this commit.

Co-Authored-By: Claude Code <noreply@anthropic.com>

* build(nix): pin regenerated security dependency hashes

Use the pnpm and Cargo hashes calculated by the PR dependency check
(run 41428540045). Both fetchers completed and reported their actual
fixed-output hashes. Replace the temporary empty values.

Verified against the CI log's pnpm-deps and vendor-staging got values;
git diff --check passes. The final hash-check rerun is pending.

Co-Authored-By: Claude Code <noreply@anthropic.com>

---------

Co-authored-by: Claude Code <noreply@anthropic.com>
2026-11-02 11:50:57 +01:00
Huang Xin
1714c2d8a8
feat(dictionary): customize context prompts and response limits (#7244)
Let readers choose a saved translator prompt or dictionary-specific
instructions in Manage Dictionaries and set a dictionary-only output limit.
Render custom responses as sanitized Markdown, retain the built-in entry
format by default, and persist and sync the new dictionary preferences.

Verified with the full Vitest suite (1220 files, 14723 tests passed), the
final focused dictionary/settings/sync suites (150 tests passed), pnpm
lint, Biome formatting, and git diff --check. New tests failed before the
implementation: the Prompt control was absent and custom prose replies
were rejected as invalid JSON. Dismissal tests also failed with no saved
instructions or token limit; both now persist without needing to blur.
The same tests pass with the change.

Exercised a live DeepSeek lookup of a word selected in an EPUB, verified
custom instructions and max_tokens on the request, and checked settings
persistence after reload. Inspected browser layouts at phone, tablet and
desktop sizes in light, dark, e-ink and RTL modes, plus settings in Linux
CEF. Physical Android and iOS devices were not tested.

Reported by noideaforeal on GitHub (#7198).

Co-authored-by: Claude Code <noreply@anthropic.com>
2026-11-02 11:12:37 +01:00