Skip to content

功能:新增 Apple 视觉、图片翻译、智能缓存与可信局域网共享,并优化阅读链路 - #811

Open
NeuronCState wants to merge 104 commits into
jiangtian616:masterfrom
NeuronCState:master
Open

NeuronCState wants to merge 104 commits into
jiangtian616:masterfrom
NeuronCState:master

Conversation

@NeuronCState

@NeuronCState NeuronCState commented Aug 7, 2026

Copy link
Copy Markdown

改动概览

本 PR 集中改进 JHenTai 的阅读体验、图片翻译、本地推理、智能缓存、下载可靠性和可信局域网共享,同时加入可选的 Apple 风格界面。

现有 Material UI、普通联网阅读和第三方翻译路径继续保留。新能力不可用或运行失败时,应用会回退到兼容路径。

主要改动

Apple 风格界面

  • 加入可选的 Apple 风格按钮、开关、输入框、滑杆、菜单和设置组件。
  • 调整 iOS 与 macOS 的侧栏、导航、标题栏、安全区域及全尺寸窗口布局。
  • 优化图库、详情页、搜索、下载、登录和阅读页面。
  • 适配深色模式、Home Indicator 与 macOS traffic lights。
  • 增加玻璃工具栏、菜单、对话框和启动 Splash 页面。
  • Material 平台继续使用原有控件与导航方式。

Reader Engine Test(可选)

  • 加入视口感知的 ReaderPipelineScheduler
  • 根据当前页面、阅读方向和页面距离安排解析与预取。
  • 支持反向滚动、跳页和双栏页码重映射。
  • 视口变化后会清理已经失去价值的排队任务。
  • ReaderPerformanceGovernor 会根据持续帧耗时调整预取范围和并发。
  • 图片预取只下载压缩字节,不提前解码完整图片。
  • Progressive Image Pipeline 会先显示缩略图,再平滑切换到完整图片。
  • 缩略图加载增加并发限制、Watchdog、有限重试和手动重试。
  • 本地缓存与 LAN 缓存命中不会占用原站请求限速额度。
  • 已完成下载的图片列表可以在闲置时释放,进入阅读页前会按需重新加载。

智能缓存与下载可靠性

  • 使用稳定的 fileindex 生成图片缓存键。
  • 兼容旧版本使用完整 URL MD5 生成的缓存,并在命中后迁移到稳定缓存键。
  • 兼容不同节点、端口、keystamp 以及 /h//om/ URL。
  • 改进断网恢复、超时、退避、429 处理和批量重试。
  • 图片、画廊元数据和归档文件先写入临时文件,校验后再原子发布。
  • 归档下载改为流式解压,并隔离失败任务。
  • 增加缓存保留时间、空间上限和淘汰策略,支持不限期保留缓存。
  • 增加缓存使用统计与 gzip 页面缓存兼容回退。
  • 修复自定义图片缓存目录未实际生效的问题。
  • 应用可见数据统一存放在 Documents/JHTData
  • 下载页面可以显示远程来源设备与状态。

图片翻译

  • 统一 OCR、翻译、背景修复和超分辨率引擎接口。
  • 支持 OCR、翻译、嵌字的完整处理流程,以及当前页或后续页面翻译。
  • 支持取消、重译、缓存、文本分组和上下文批量翻译。
  • 接入 Apple Vision Live Text OCR。
  • 支持 Apple 端侧翻译、OpenAI Compatible API、Anthropic API 和本地 GGUF 翻译。
  • 保留 PaddleOCR,并加入 PP-OCRv6 模型管理。
  • 支持 CTD 文本区域检测与可选的 MI-GAN 背景修复。
  • 处理失败时保留原图,并回退到文字覆盖显示。
  • 图库标题和评论同样可以使用已配置的翻译引擎。
  • 及其利好Apple设备

ONNX 推理与超分辨率

  • 接入统一的 ONNX Runtime。
  • OCR 与超分辨率共用任务取消、错误处理和 Session 生命周期管理。
  • 运行时读取实际可用的 Execution Provider。
  • 根据平台和设备能力选择 CoreML、NNAPI、DirectML、CUDA、OpenVINO、XNNPACK 或 CPU。
  • 硬件 Provider 失败后可以回退 CPU,并记录 Provider Canary 状态。
  • 使用输入像素预算、尺寸对齐和张量预算限制内存峰值。
  • 完成 PP-OCRv6 检测、方向分类、识别、DB 后处理和 CTC 解码。
  • 增加 Real-ESRGAN anime x4 分块处理。
  • 模型下载支持进度、取消、断点恢复、大小检查和 SHA-256 校验。

本地 GGUF 翻译

  • 使用 lib_llama_cpp 接入进程内 llama.cpp 运行时。
  • 已接入 Android、iOS、macOS、Windows 和 Linux 平台插件。
  • 支持 Qwen、Hy-MT 等 GGUF 翻译模型。
  • 增加模型目录、能力信息、安装状态和完整性检查。
  • 支持分块并行下载、断点续传、取消和失败恢复。
  • 下载前检查可用磁盘空间。
  • 本地请求采用串行协调,减少多个模型 Session 同时加载造成的内存峰值。
  • 保留 llama-server 作为桌面端 loopback 兼容方式。

阅读器操作

  • 增加翻译悬浮球与书签悬浮球。
  • 支持多页书签、缩略图书签标记,以及上一个或下一个有效书签跳转。
  • 增加阅读页翻译操作菜单,支持重新翻译、隐藏及恢复翻译结果。
  • 修复阅读页重建后翻译状态丢失的问题。
  • 将页面 Hydration 与在线图片加载状态关联。
  • 修复 Dashboard 搜索面板因父组件重建而重置的问题。

可信局域网共享

  • 增加 LAN v2 通信协议。
  • 支持设备发现、身份指纹、可信配对和自动重连。
  • 使用加密会话传输元数据、状态和缓存字节。
  • 加入序列号校验、重放保护、分片重组和能力协商。
  • 每台设备单独保存权限,不提供任意文件路径和未认证下载接口。
  • 支持已下载画廊、图片缓存、翻译结果、翻译算力、OCR 算力、登录状态和应用历史共享。
  • 应用历史同步包含画廊历史、阅读进度和书签。
  • 阅读器会在访问原站前查询可信设备缓存,未命中时回退普通联网流程。
  • 支持远程画廊列表、封面、清单和画廊下载。
  • 支持将本机缓存推送到已授权的服务器设备。
  • 设置页可以查看本次运行期间的 LAN 图片流量。

登录状态与历史同步

  • 增加统一的 LAN 状态模型。
  • 支持登录 Cookie 导入、验证和失败回滚。
  • 不同账号之间不会静默覆盖登录状态。
  • 历史、进度和书签会按更新时间与设备 ID 合并。
  • 删除记录通过 Tombstone 同步,避免旧设备重新恢复已删除内容。
  • 登录状态、历史同步与软件设置只对拥有对应权限的可信设备开放。
  • 主动广播功能使服务器发现新设备后会主动在设备弹出信任请求

默认配置

  • Apple 风格界面默认关闭。
  • LAN 共享默认开启。
  • LAN 主动广播默认关闭。
  • Server Mode 默认关闭
  • Android NNAPI 默认关闭。
  • CPU fallback 默认开启。
  • 模型文件不会直接打包进应用,需要用户下载并完成校验。

主动广播可能向同一局域网中的新设备发起配对请求。登录同步包含 Cookie,建议只在可信网络中使用。

上游同步与兼容迁移

本分支已经同步最新上游 master,并解决相关合并冲突。

  • 跟随上游完成 gallerysgallery/galleries 的目录和类型重命名。
  • 将 Fork 的下载可靠性、LAN 与缓存改动迁移到上游模块化下载服务。
  • 数据库 schema 升至 27。
  • 上游 schema 25 与 Fork schema 26 都可以幂等迁移到当前结构。
  • 迁移会补齐智能缓存统计表、阅读书签表和 originalImageUrl 字段。
  • 保留现有 iOS Bundle Identifier top.jtmonster.jhentai,避免升级后产生新的应用容器。
  • 保留旧下载设置键、缓存格式和 LAN Server 配置键的兼容读取。
  • 修复已完成下载释放图片列表后,从详情页进入阅读器只显示占位内容的问题。

平台要求

  • iOS Deployment Target 为 16.0。
  • macOS Deployment Target 为 14.0。
  • Apple Vision Live Text OCR 可以在最低部署版本支持的设备上使用。
  • Apple 端侧翻译需要 iOS 26 或 macOS 26 及以上系统。
  • 不支持 Apple Translation 的系统可以改用第三方 API 或本地 GGUF。
  • 硬件 Provider 是否可用,以目标设备运行时探测结果为准。
  • LAN 新能力要求双方设备支持相同的协议能力,旧版本设备会回退普通联网流程。

建议审查顺序

  1. 阅读器调度与图片生命周期:lib/src/pages/readlib/src/service/reader_*
  2. 图片翻译与本地推理:lib/src/service/image_translation_service.dartlib/src/service/inferencelib/src/service/engine
  3. LAN 协议、权限和状态同步:lib/src/service/lan_*lib/src/model/lan_*
  4. 下载服务、缓存与数据库迁移:lib/src/service/gallery_downloadlib/src/databaselib/src/network/eh_cache_manager.dart
  5. Apple UI 与平台工程:lib/src/widget/eh_apple_controls.dartlib/src/config/theme_config.dartiosmacos
  6. 第三方运行时改动:third_party/flutter_onnxruntimethird_party/extended_image_library

验证结果

  • Flutter 全量测试通过,共 278 项。
  • 数据库分叉迁移测试通过,覆盖上游 schema 25 和 Fork schema 26。
  • dart analyze 没有 error,仓库仍有 warning 和 info。
  • macOS Release 构建成功。
  • iOS Release 无签名构建成功。
  • 已在真实 iOS 设备上完成安装运行与核心流程测试。
  • Apple Vision Live Text 已完成真机验证。
  • Apple 端侧翻译与实际模型推理流程已经完成验证。
  • LAN 已完成多设备发现、配对、权限、缓存传输、远程下载和状态同步联调。
  • macOS 环境下已经完成应用运行和主要功能测试。

当前 PR 已同步上游,GitHub 状态为 MERGEABLECLEAN

@NeuronCState NeuronCState changed the title feat: add opt-in Apple visual style 功能:新增可选 Apple 视觉样式并优化本地处理 Aug 7, 2026
@NeuronCState
NeuronCState marked this pull request as ready for review August 7, 2026 03:23
@jiangtian616 jiangtian616 self-assigned this Aug 7, 2026
NeuronCState and others added 5 commits August 7, 2026 11:38
On macOS the window uses a hidden title bar with a full-size content view,
so the traffic-light buttons overlay the top-left of the reading page. The
AppBar forces its leading slot to leadingWidth (56px), so widen it and pad
the BackButton so it no longer sits underneath the traffic lights. Applies
on macOS only.

Co-Authored-By: Claude <noreply@anthropic.com>
…le settings

- route image/page caches into JHTData/temp/autotemp via vendored extended_image_library
- add smart cache space limit and eviction policy (added date / usage frequency)
- track cache usage stats for pages and images, direct md5 cache lookup
- dedupe read-page parse tasks, bypass rate limit on cache hits, session-level parse cache
- auto-retry failed online images once
- collapse master-switch sub-options in Apple-style settings
@NeuronCState NeuronCState changed the title 功能:新增可选 Apple 视觉样式并优化本地处理 功能:新增可选 Apple 视觉样式并特别优化本地处理 Aug 8, 2026
…I layers

- cover decode optimization setting (decode covers near display size)
- image request timeouts + retry backoff (delayFactor 500ms)
- tag refresh staleness filter; smart cache hit aggregation + atomic upsert
- global image cache budget; isolate pool for HTML/JSON parsing
- parallel startup init; download atomic writes (temp+rename)
- archive streaming unzip + temp dir; 429 backoff auto-resume
- reader scroll rebuild guards + jump prefetch; gid-scoped status fan-out
- translation dimension probe via ImageDescriptor; overlay PNG encode off UI isolate
- gzip page cache with legacy fallback (fromResponseAsync)
- thumbnail sprite decode caps; gallery tag sort memoization
@NeuronCState NeuronCState changed the title 功能:新增可选 Apple 视觉样式并特别优化本地处理 功能:新增可选 Apple 视觉样式、智能缓存与图片翻译,并优化阅读及本地处理 Aug 8, 2026
NeuronCState and others added 16 commits August 8, 2026 13:40
…batch

- cancel the in-flight translation batch when leaving the gallery so OCR/API
  work is not carried on in the background
- give online image fetches a 5s timeout and skip pages that are not loaded
  yet, so batch translation never stalls on unavailable images
- guard each page of the batch loop so a single failure does not abort the rest

Co-Authored-By: Claude <noreply@anthropic.com>
…slation menu

Download engine hardening:
- archive: null the completed downloadCompleter after success and guard
  completeError with isCompleted, so a failed move/unpack no longer throws
  StateError and permanently wedges the archive
- gallery: cap the parse->download->re-parse loop with a consecutive-network-
  failure counter that pauses the gallery after 3 instead of retrying forever
- fix _deleteImageInDisk resolving image.path relative to the visible dir
- guard _updateProgressAfterImageDownloaded against double-counting (curCount)
- contain copy/cache-step exceptions so a failure falls through to download
  instead of killing the task and leaving the image stuck
- copy cached images via temp + atomic rename; write gallery metadata
  atomically and skip corrupted metadata files on restore
- recover archives stuck in waitingIsolate across restarts
- cancel archives before dropping the task; clean up .jdtemp/.jdcopy leftovers
- guard EHExecutor rate limiter against maximum == 0 (divide by zero)

Cache reuse (downloads reuse the read cache):
- key the extended_image disk cache by the stable fileindex instead of the raw
  URL, which carries a rotating keystamp and alternates between /h/ and /om/
  formats; a gallery read before now downloads straight from cache
- count cache-copied bytes into the speed/progress display
- copy cached images directly outside the rate-limited executor queue

Read page:
- consolidate the translate/show-hide/retranslate buttons into one that opens
  a small action menu (Apple action sheet or Material bottom sheet)

Other:
- add a Material ancestor under the Apple settings card so ListTile ink
  renders and the repeated "ink splashes may be invisible" global error stops
- tests for cache-key stability, cache lookup, EHExecutor zero-rate

Co-Authored-By: Claude <noreply@anthropic.com>
…ranslate menu

- ColorScheme.fromSeed(black/white) derives pink/magenta tones for the roles
  not overridden, which leaked as pink sidebars and pink translation UI on iOS;
  override secondary/tertiary and their containers (plus inverse roles) with
  gray so the Apple style is monochrome on all platforms
- read-page translate menu: replace the sheet-based entry with an anchored
  showMenu dropdown driven by an action enum

Co-Authored-By: Claude <noreply@anthropic.com>
…Apple); gzip OCR result cache

- New autoTranslateGalleryText setting, gated to Apple Live Text + on-device translation
- translateGalleryText engine: concurrency-limited queue, in-flight dedupe, failure
  negative-cache, in-memory LRU + persistent gzip cache (reuses _compressJson/_decompressJson)
- New EHTranslatedText widget (Text/SelectableText-compatible) with stale-result race guard
- Comments translate per text run preserving HTML formatting; edit dialog shows original
- Converted all gallery-title surfaces: list/waterfall/dashboard/history cards, details
  AppBar+main+subtitle, download grid/list/search pages
- Settings toggle in Apple on-device path; i18n keys added to all 6 languages
- Tests: autoTranslateGalleryText config round-trip

Co-Authored-By: Claude <noreply@anthropic.com>
NeuronCState and others added 25 commits August 11, 2026 17:23
# Conflicts:
#	lib/src/pages/base/base_page.dart
@NeuronCState
NeuronCState marked this pull request as ready for review August 12, 2026 23:47
@NeuronCState
NeuronCState marked this pull request as draft August 13, 2026 11:57
@NeuronCState
NeuronCState marked this pull request as ready for review August 13, 2026 12:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants