* Centralize library management logic and introduce support for plain text and HTML formats

* Centralize library management logic and introduce support for plain text and HTML formats

* Expand unit test coverage for library state management, UI models, and MainViewModel features.

* Add comprehensive unit tests for PDF reader core logic, preferences, and data persistence

* Add unit tests for EPUB parsing, content loading, search functionality, and reader JavaScript bridges.

* Add unit tests for OPDS parsing and Smart Collection engine, and integrate Kover plugin

* Add comprehensive unit tests

* Centralize library snapshot serialization in the `shared` module and improve filtering and sorting logic.

* Implement text selection, highlighting, and reading state persistence for PDF and EPUB engines in desktop version

* Folder import support for desktop app

* Introduce Smart Shelves with rule-based filtering in desktop version

* Implement shared EPUB annotation serialization and highlight rendering

* Centralize file type capabilities and platform-specific support logic

* Refactor reader state management to use a central reducer

* Implement customizable reader toolbar and advanced formatting settings in shared

* Implement locator-based navigation and customizable highlight palette for desktop app

* Enhance reader customization and expand search functionality in desktop app

* Redesign reader settings and tools into a tabbed control panel in desktop app

* Enhance reader navigation and highlight precision in desktop app

* Implement bidirectional position synchronization and dynamic highlights in the desktop reader

* Implement shared state management and enhanced search for the PDF reader in desktop app

* Add vertical scroll support to the desktop PDF reader

* Implement ink, text, and eraser annotation support in desktop PDF viewer

* Implement PDF bookmarks, Table of Contents, and annotation editing in desktop app

* Implement link handling and navigation for PDF and EPUB readers in desktop app

* Implement PDF jump history for navigation in desktop app

* Enhance PDF ink rendering and annotation capabilities in desktop app

* Implement advanced PDF text annotations with inline editing and rich styling in desktop app

* Add move handle and movement logic for PDF text annotations in desktop app

* Implement local folder synchronization and metadata sidecar support in desktop app

* Implement book metadata extraction and drag-and-drop import for Desktop

* Implement dynamic and custom app theme management for desktop

* Introduce canonical PDF annotation codec and support for multi-segment highlights

* Implement rich text editing and pagination support for the PDF reader in desktop app

* Improve PDF rich text pagination, synchronization, and observability in desktop

* Hide trailing structural page breaks in rich text editor

* Implement a unified JVM book loader and expand supported formats on Desktop

* Add comic archive support for Desktop and enhance MOBI parsing

* Implement shared OPDS catalog support and UI for Android and Desktop

* Improve native WebView lifecycle and surface transition management on Desktop

* Enable Compose Swing interop blending and simplify Desktop WebView management

* Integrate BYOK AI features and Cloud TTS for desktop

* Enhance Desktop TTS with streaming audio and improved secure storage for AI key

* Implement scoped Cloud TTS with synchronized highlighting for EPUB and PDF in desktop app

* Implement custom font management and utility screens in desktop app

* Implement PDFium-based PDF annotation export

* Remove PdfBox dependency and standardize PDF export via Pdfium

* Implement local audio caching and playback controls for Gemini Cloud TTS in desktop app

* Implement reader themes and custom texture support in desktop app

* Redesign non-reader UI with responsive navigation and enhanced library management in desktop app

* Introduce ReaderWorkspaceShell to unify EPUB and PDF reader layouts in desktop app

* Exclude manual-only files from automated sync and import

* Implement customizable Text-to-Speech (TTS) word replacements

* Optimize reader performance with persistent layout caching and decoupled theme rendering

* Improve position restoration during reader reconfiguration in epub pagination

* Use independent thickness for eraser tool and stylus override
This commit is contained in:
Aryan 2026-05-10 10:07:37 +05:30 committed by GitHub
parent 88c7fa7b5c
commit 8366d76dcd
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
214 changed files with 53372 additions and 4702 deletions

View file

@ -26,6 +26,9 @@ import timber.log.Timber
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.withContext
import kotlinx.serialization.Serializable
import kotlinx.serialization.decodeFromString
import kotlinx.serialization.encodeToString
import kotlinx.serialization.json.Json
import org.jsoup.Jsoup
import org.w3c.dom.Element
import org.w3c.dom.Node
@ -42,6 +45,8 @@ import kotlinx.coroutines.sync.Semaphore
import kotlinx.coroutines.sync.withPermit
class EpubParser(private val context: Context) {
private val jsonSerializer = Json { ignoreUnknownKeys = true; encodeDefaults = true }
data class EpubDocument(
val metadata: Node, val manifest: Node, val spine: Node, val opfFilePath: String
)
@ -67,6 +72,15 @@ class EpubParser(private val context: Context) {
val depth: Int
)
@Serializable
private data class EpubExtractionCacheManifest(
val bookId: String,
val originalBookNameHint: String,
val parserVersion: Int,
val parseContent: Boolean,
val shouldUseToc: Boolean
)
// EpubFile can still represent in-memory file data during initial parsing before extraction
data class EpubFile(val absPath: String, val data: ByteArray) {
override fun equals(other: Any?): Boolean {
@ -92,6 +106,9 @@ class EpubParser(private val context: Context) {
companion object {
const val TAG = "EpubParser"
private const val BOOK_METADATA_FILE = "book_metadata.json"
private const val CACHE_MANIFEST_FILE = "epub_cache_manifest.json"
private const val EPUB_EXTRACTION_CACHE_VERSION = 1
}
internal val String.decodedURL: String
@ -173,8 +190,24 @@ class EpubParser(private val context: Context) {
return withContext(Dispatchers.IO) {
Timber.d("Parsing EPUB input stream for bookId: $bookId")
val extractionDir = extractionDirOverride?.let(ImportedFileCache::prepareDirectory)
?: ImportedFileCache.prepareActiveBookDir(context, bookId)
val shouldDeleteExtractionDir = !parseContent && extractionDirOverride == null
val extractionDir = if (extractionDirOverride != null) {
ImportedFileCache.prepareDirectory(extractionDirOverride)
} else if (!parseContent) {
ImportedFileCache.createTemporaryBookDir(context, bookId, "metadata")
} else {
val activeDir = ImportedFileCache.ensureActiveBookDir(context, bookId)
readCachedEpubBook(
extractionDir = activeDir,
bookId = bookId,
originalBookNameHint = originalBookNameHint,
shouldUseToc = shouldUseToc
)?.let { cachedBook ->
Timber.tag("FileOpenPerf").d("[EPUB] Loaded extracted book from cache | bookId=$bookId")
return@withContext cachedBook
}
ImportedFileCache.resetActiveBookDir(context, bookId)
}
val tempFile = File.createTempFile("epub_stream", ".epub", context.cacheDir)
val filesMap: Map<String, EpubFile>
@ -190,10 +223,80 @@ class EpubParser(private val context: Context) {
val document = createEpubDocument(filesMap)
val book = parseAndCreateEbook(filesMap, document, shouldUseToc, extractionDir.absolutePath,
originalBookNameHint, parseContent)
if (parseContent && extractionDirOverride == null) {
writeCachedEpubBook(
extractionDir = extractionDir,
bookId = bookId,
originalBookNameHint = originalBookNameHint,
shouldUseToc = shouldUseToc,
book = book
)
}
if (shouldDeleteExtractionDir) {
extractionDir.deleteRecursively()
}
return@withContext book
}
}
private fun readCachedEpubBook(
extractionDir: File,
bookId: String,
originalBookNameHint: String,
shouldUseToc: Boolean
): EpubBook? {
val metadataFile = File(extractionDir, BOOK_METADATA_FILE)
val manifestFile = File(extractionDir, CACHE_MANIFEST_FILE)
if (!metadataFile.isFile || !manifestFile.isFile) return null
return try {
val manifest = jsonSerializer.decodeFromString<EpubExtractionCacheManifest>(manifestFile.readText())
val isCompatible = manifest.bookId == bookId &&
manifest.originalBookNameHint == originalBookNameHint &&
manifest.parserVersion == EPUB_EXTRACTION_CACHE_VERSION &&
manifest.parseContent &&
manifest.shouldUseToc == shouldUseToc
if (!isCompatible) {
Timber.d("EPUB extraction cache manifest is stale for bookId=$bookId")
return null
}
val cachedBook = jsonSerializer.decodeFromString<EpubBook>(metadataFile.readText())
.copy(extractionBasePath = extractionDir.absolutePath)
cachedBook.takeIf { it.hasReadableExtractedContent() }
} catch (e: Exception) {
Timber.e(e, "Failed to read EPUB extraction cache for bookId=$bookId")
null
}
}
private fun writeCachedEpubBook(
extractionDir: File,
bookId: String,
originalBookNameHint: String,
shouldUseToc: Boolean,
book: EpubBook
) {
try {
File(extractionDir, BOOK_METADATA_FILE).writeText(jsonSerializer.encodeToString(book))
File(extractionDir, CACHE_MANIFEST_FILE).writeText(
jsonSerializer.encodeToString(
EpubExtractionCacheManifest(
bookId = bookId,
originalBookNameHint = originalBookNameHint,
parserVersion = EPUB_EXTRACTION_CACHE_VERSION,
parseContent = true,
shouldUseToc = shouldUseToc
)
)
)
} catch (e: Exception) {
Timber.e(e, "Failed to write EPUB extraction cache for bookId=$bookId")
}
}
private fun extractEpubContents(zipFile: ZipFile, extractionDir: File, parseContent: Boolean): Map<String, EpubFile> {
val filesMap = mutableMapOf<String, EpubFile>()
zipFile.use { zf ->