add stGen which gets bumped for every worker thread spawned by
loadBook
every thread captures stGen when it spawns and before actually loading
the book in the main thread, and in the worker thread it checks if
myGen == stGen
this throws away stale requests, meaning if you try and load another
book while one is still loading, it will ignore the one still loading
and start loading the latest request
ctxRender changed to a TVar to allow mutability of the render
make loadBook reset stCache and stIndex
write render TVar right before handing off to main thread
remove everything from the sidebar ListBox before populating it again
Rework the reader around a clean BookInfo interface and lazy chapter loading.
Types/parser:
- BookInfo now splits into loadStructure (cheap: spine refs + TOC tree) and renderChapter (one chapter on demand). EpubEnv carries the parsed archive.
- resolveZipPath collapses ./.. and strips #fragments (normalise does not), so relative hrefs like ../Images/x.jpg resolve; used for chapters and images.
- decodeEntry tolerates encodings: UTF-8/UTF-16 BOMs, Latin-1 fallback instead of throwing on invalid bytes.
- Skip spine items with no manifest entry instead of throwing an error.
- Scan the zip for a .opf if container.xml is missing.
- Image inlining rewrites the src URL string, not the whole <img> tag (scalpel
re-serialises tags, so a whole-tag replace silently missed self-closing imgs).
Navigation:
- Hierarchical TOC: ncxToc (EPUB 2), navToc (EPUB 3), guideToc (<guide> fallback). Nested scrapers use atDepth 1 to take only direct children.
UI:
- Streaming: render the opened chapter on demand, cache it, preload neighbours so arrow paging is instant with a placeholder that covers uncached jumps.
- Sidebar shows the TOC tree with CSS styling. Clicks scroll to #fragments.
- wrapHtml wraps each body in a full HTML document for reliable WebKit render.
Test: 'svitak-test <book> <idx>' dumps one rendered chapter. cabal test stanza fixed to list all needed modules/deps.
The dev shell (guix shell -D) has the full toolchain and network, so the build happens there.
The isolated 'guix shell -C -N' container only runs the already-compiled binary, which needs just the GTK/WebKit C libraries via LD_LIBRARY_PATH.
Also export WEBKIT_DISABLE_COMPOSITING_MODE and WEBKIT_DISABLE_DMABUF_RENDERER, without which WebKit renders a blank surface inside the sandbox.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>