feat: chapter runtime refactoring and related updates

- Refactor chapter runtime: replace window coordinator/snapshot with warmup orchestrator
- Update EPUB core: parser, reading session, JS bridge, navigator layout
- Update reader controller: data source, location resolution, persistence
- Update chapter runtime: data cache, loader, runtime store, disk cache, warmup orchestrator
- Remove deprecated navigation state machine and pagination state
- Update text rendering: book cache, HTML normalizer
- Update UI: text content view, dark image adjuster, text selection controller
- Update settings and reader configuration
- Add CODE_REVIEW.md and AUDIT_FINAL.md documentation
- Update pod dependencies (remove SSAlertSwift, SnapKit)
- Update podspec and pod configuration files

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
shenlei
2026-06-26 18:50:07 +09:00
co-authored by Claude
parent b8aa10c535
commit 22e7e44220
123 changed files with 3701 additions and 9118 deletions
@@ -21,6 +21,64 @@ public final class RDEPUBParser {
public init() {}
// MARK: - Cache Management
/// The base directory used for EPUB extraction caches.
public static var extractionCacheBaseDirectory: URL {
FileManager.default.urls(for: .cachesDirectory, in: .userDomainMask).first?
.appendingPathComponent("ssreaderview-epub", isDirectory: true)
?? FileManager.default.temporaryDirectory.appendingPathComponent("ssreaderview-epub", isDirectory: true)
}
/// Removes all EPUB extraction caches from disk.
/// Call this when the host app wants to free disk space, e.g. on didReceiveMemoryWarning
/// or during cleanup when the reader is no longer needed.
public static func cleanExtractionCache() throws {
let fileManager = FileManager.default
let baseURL = extractionCacheBaseDirectory
guard fileManager.fileExists(atPath: baseURL.path) else { return }
try fileManager.removeItem(at: baseURL)
}
/// Evicts extraction caches until total disk usage is below the given threshold,
/// removing least-recently-accessed directories first.
/// - Parameter maxBytes: Maximum total bytes for all extraction caches. Defaults to 500 MB.
public static func evictExtractionCache(maxBytes: UInt64 = 500 * 1024 * 1024) throws {
let fileManager = FileManager.default
let baseURL = extractionCacheBaseDirectory
guard fileManager.fileExists(atPath: baseURL.path) else { return }
let contents = try fileManager.contentsOfDirectory(
at: baseURL,
includingPropertiesForKeys: [.contentAccessDateKey, .isDirectoryKey],
options: .skipsHiddenFiles
)
var entries: [(url: URL, accessDate: Date, size: UInt64)] = []
var totalSize: UInt64 = 0
for directoryURL in contents {
guard let resourceValues = try? directoryURL.resourceValues(forKeys: [.isDirectoryKey, .contentAccessDateKey]),
resourceValues.isDirectory == true else {
continue
}
let directorySize = directoryURL.directorySize
let accessDate = resourceValues.contentAccessDate ?? Date.distantPast
entries.append((url: directoryURL, accessDate: accessDate, size: directorySize))
totalSize += directorySize
}
guard totalSize > maxBytes else { return }
entries.sort { $0.accessDate < $1.accessDate }
for entry in entries {
guard totalSize > maxBytes else { break }
try? fileManager.removeItem(at: entry.url)
totalSize -= entry.size
}
}
public func makePublication() -> RDEPUBPublication {
RDEPUBPublication(parser: self)
}
@@ -75,4 +133,24 @@ public final class RDEPUBParser {
public func parseNavDocument(_ navURL: URL, baseURL: URL? = nil) -> [EPUBTableOfContentsItem] {
parseNavDocumentItems(at: navURL, baseURL: baseURL ?? navURL.deletingLastPathComponent())
}
}
// MARK: - URL Directory Size Extension
private extension URL {
var directorySize: UInt64 {
let fileManager = FileManager.default
guard let enumerator = fileManager.enumerator(at: self, includingPropertiesForKeys: [.fileSizeKey], options: [.skipsHiddenFiles], errorHandler: nil) else {
return 0
}
var totalSize: UInt64 = 0
for case let fileURL as URL in enumerator {
guard let resourceValues = try? fileURL.resourceValues(forKeys: [.fileSizeKey]),
let fileSize = resourceValues.fileSize else {
continue
}
totalSize += UInt64(fileSize)
}
return totalSize
}
}