Skip to content

fix(启动器): 版本查询恢复后台线程异步语义 - #2716

Closed
kawayiYokami wants to merge 1 commit into
OneDragon-Anything:refactor/resource-downloadfrom
kawayiYokami:fix/launcher-version-async
Closed

fix(启动器): 版本查询恢复后台线程异步语义#2716
kawayiYokami wants to merge 1 commit into
OneDragon-Anything:refactor/resource-downloadfrom
kawayiYokami:fix/launcher-version-async

Conversation

@kawayiYokami

Copy link
Copy Markdown
Contributor

为什么改

#2715 合入的版本缓存方案里,get_launcher_version_info 仍保留同步网络查询路径(缓存未命中时主线程会触网)。原版架构是 QThread 后台查询 + 信号回传,重构时把查询写成了同步。本 PR 恢复异步语义:网络请求只在后台线程发生,主线程只读缓存。

改动要点

  • 变更:UpdateService 拆分 fetch_launcher_version_info(后台线程查询并填缓存)与 get_launcher_version_info(主线程只读缓存,无缓存返回空版本,不触网)
  • 变更:is_launcher_update_available 与 LauncherVersionChecker.run 改用 fetch 入口(两者均在后台线程)

关联

承接 #2715(已合并)

OneDragon-Anything#2715 合入的版本缓存方案在主线程读缓存前仍可能同步触网,恢复原版 QThread 异步架构:
- fetch_launcher_version_info 在后台线程查询并填缓存
- get_launcher_version_info 只读缓存不触网,主线程构造下载项安全
@coderabbitai

coderabbitai Bot commented Aug 11, 2026

Copy link
Copy Markdown
Contributor

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: 4691a8a0-935d-4146-80b3-0ffd65de1b4d

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@ShadowLemoon

Copy link
Copy Markdown
Collaborator

我从 is_launcher_update_available() 的所有调用点往上追到 GUI 入口和线程边界。TOOLBREAK直接调用搜索只命中测试;生产代码是把该方法作为回调对象注册,因此继续检查回调注册处、QThread.run() 和 GUI 上游。TOOLBREAK线程边界已经明确:GUI 路径调用到 check_updates() 后只执行 runner.start();真正的函数调用位于 _ResourceUpdateCheckRunner.run()。我再核对所有触发入口,避免漏掉其他同步路径。TOOLBREAK结论:UpdateService.is_launcher_update_available() 没有在 GUI 主线程同步执行。 GUI 主线程只同步调用到 ResourceUpdateCoordinator.check_updates(),随后通过 QThread.start() 启动后台检查;真正调用该函数的是工作线程的 run()

完整调用链:

  1. 应用创建单次 QTimer,超时后在 GUI 线程调用 _after_app_launch()
    app.py:85
    app.py:250

  2. _after_app_launch() 调用:

    self.check_resource_updates(force=True)

    app.py:254

  3. MainAppWindowBase.check_resource_updates() 同步转交协调器:

    coordinator.check_updates(force=force)

    main_app_window_base.py:214

  4. 协调器初始化时只是保存函数引用,并没有调用:

    check_update=self.ctx.update_service.is_launcher_update_available

    resource_update_coordinator.py:97

  5. check_updates() 在 GUI 线程中调用 runner.start(),随即返回:

    for check_id, runner in self._check_runners.items():
        self._checks_complete[check_id] = False
        runner.start()

    resource_update_coordinator.py:123
    resource_update_coordinator.py:135

  6. 新线程进入 _ResourceUpdateCheckRunner.run(),这里才真正调用:

    need_update = self.resource_check.check_update()

    resource_update_coordinator.py:41
    resource_update_coordinator.py:54
    resource_update_coordinator.py:58

  7. 该回调最终进入:
    update_service.py:74

    缓存未命中时,其中的 get_launcher_version_info() 会调用网络请求 git_service.get_latest_tag(),但这部分同样位于上述后台线程中:
    update_service.py:58
    update_service.py:66

  8. 检查结束后发出 checked 信号;ResourceUpdateCoordinator 属于 GUI 线程,因此 _on_check_completed() 回到 GUI 线程处理状态及弹窗:
    resource_update_coordinator.py:64
    resource_update_coordinator.py:120
    resource_update_coordinator.py:158

另外两个可能触发 check_updates() 的入口——欢迎弹窗结束、OCR 下载请求——最终也只会执行 runner.start(),不会同步运行检查函数。主页显示时的重复检查入口也走同一条异步链。

资源管理页的 LauncherDownloadCard 是另一条版本检查路径:它使用独立的 LauncherVersionChecker(QThread) 调用 get_launcher_version_info(),也不是 GUI 主线程同步检查,更没有直接调用 is_launcher_update_available()

launcher_download_card.py:23
launcher_download_card.py:40

因此当前生产代码中不存在 is_launcher_update_available() 的 GUI 主线程同步直调。测试代码会直接同步调用它,但不影响 GUI 运行路径。

@kawayiYokami
kawayiYokami deleted the fix/launcher-version-async branch August 11, 2026 15:25
@github-actions github-actions Bot locked as resolved and limited conversation to collaborators Aug 14, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants