$ show johnfactotum/foliate
Foliate is a desktop e-book reader for GNOME/Linux, built with GTK4, Libadwaita, and GJS (GNOME JavaScript). It supports EPUB, Mobipocket, Kindle, FB2, CBZ, and PDF formats, using WebKitGTK to render book content via a custom JavaScript rendering engine (foliate-js). The application provides a full-featured reading experience with paginated and scrolled modes, customizable fonts and themes, annotations (highlights, notes, bookmarks), text-to-speech via Speech Dispatcher, OPDS catalog browsing, and dictionary/Wikipedia lookups. Architecture: The main entry point is src/main.js, which initializes the GJS application and loads the GResource-bundled source files. The core UI is defined in src/app.js (window creation, file handling) and src/book-viewer.js (reading view with sidebar, search, navbar, TTS). The library view (src/library.js) manages book collections and OPDS integration. Reading state (annotations, bookmarks, progress) is persisted per-book as JSON files in the user's data directory. The rendering pipeline lives in the WebView: src/reader/reader.js handles content display, CSS injection, and footnotes, while the foliate-js submodule parses e-book formats into a pageable model. External dependencies: GNOME platform (GTK 4.12, Libadwaita 1.8, WebKitGTK 6.0, GJS 1.82), Speech Dispatcher for TTS, Tracker (optional) for file indexing, and third-party APIs (Wiktionary, Wikipedia, Google Translate) for lookup tools. The build system uses Meson, with Flatpak and Snap packaging provided. Internationalization across 30+ languages is maintained via gettext PO files. Data flows: User opens a file → book is parsed by foliate-js into a structured document model → rendered in WebView → user interactions (scroll, search, annotate, bookmark) are communicated back to GJS via the WebView's async RPC pattern (exec/iter/provide) → state is persisted as JSON files. OPDS catalogs are fetched via HTTP and rendered in a separate WebView frontend (src/opds/main.html).
The LLM identified 3 files worth highlighting for reuse:
Provides JSONStorage for persistent file-backed JSON with debounced saves and external modification detection, makeDataClass for creating GObject data classes with properties and serialization, and utility functions for signal connection management, debouncing, and memoization. This module is self-contained and could be reused in any GJS application for structured data persistence and reactive data models.
Implements an async bidirectional RPC pattern between GJS (GTK) and WebKit JavaScript using evaluate_javascript and custom URI scheme handling. Provides exec(), iter(), and provide() methods that abstract away the complexity of WebKit message passing, enabling clean separation of concerns between native UI and web rendering. Can be extracted as a reusable communication layer for any GJS + WebKit application.
Defines a set of color themes (Default, Sepia, Dark, Solarized, Gruvbox, Nord, etc.) as light/dark pair objects and provides functions to generate CSS strings from these themes. The module is self-contained and can be reused in any application that needs configurable color themes with CSS injection, not just e-book readers.