Skip to content

fix: 修复 MuMu 多屏环境下的游戏启动与重启 - #574

Open
cwlm wants to merge 1 commit into
OpenWSGR:mainfrom
cwlm:fix/mumu-display-startup
Open

cwlm wants to merge 1 commit into
OpenWSGR:mainfrom
cwlm:fix/mumu-display-startup

Conversation

@cwlm

@cwlm cwlm commented Oct 23, 2026

Copy link
Copy Markdown
Contributor

修复新版 MuMu 将游戏运行在独立显示屏时,脚本仍截取默认桌面而导致启动超时的问题。

  • 自动定位游戏显示屏,换屏时同步重建截图与触控连接。
  • 启动应用前关闭旧镜像,避免重启时游戏被启动到临时镜像屏。
  • 修正启动页与游戏内页面的等待逻辑,加载和登录共用启动超时预算。
  • 完善连接清理,补充回归测试及文档。

@codecov

codecov Bot commented Oct 23, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 94.14634% with 12 lines in your changes missing coverage. Please review.
✅ All tests successful. No failed tests found.

Files with missing lines Patch % Lines
autowsgr/emulator/controller/scrcpy.py 91.12% 11 Missing ⚠️
autowsgr/emulator/controller/display.py 97.05% 1 Missing ⚠️

📢 Thoughts on this report? Let us know!

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review from [deepseek-v4-flash]:
- Total changes: 10
- Filtered: 10
- Reviewed: 10
- Found issues: 2

Comment thread autowsgr/ops/startup.py
go_main_page(ctx, dismiss_overlays=dismiss_overlays)
_log.info('[Startup] 游戏就绪')
if dismiss_overlays:
handle_daily_overlays(ctx)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

代码整体方向合理,但当前实现存在几个需要处理的问题/风险:

  1. 恢复流程可能被 _enter_from_start_screen 的 TimeoutError 中断
    recover_to_main_or_restart 的 while 循环只捕获了 NavigationError,但 _enter_from_start_screen 在点击启动页后如果等待游戏页超时,会直接抛 TimeoutError。这会导致“恢复失败后强制重启”的兜底逻辑失效。建议把 TimeoutError 也纳入捕获,或统一转为恢复失败继续走重启分支。

  2. 恢复流程中没有限制 _enter_from_start_screen 的等待预算
    _enter_from_start_screen(ctrl) 默认使用 _STARTUP_TIMEOUT 作为等待超时。如果 _STARTUP_TIMEOUT 大于 _RECOVERY_TO_MAIN_TIMEOUT,在恢复路径中点击启动页后可能长时间阻塞,绕过 recover_to_main_or_restart 自身的 deadline。建议改为传入剩余恢复预算,例如:

    remaining = deadline - time.monotonic()
    _enter_from_start_screen(ctrl, timeout=remaining)
  3. go_main_page 强制 force=True 会绕过每日浮层去重
    之前 handle_daily_overlays 用 daily_overlay_date 做了当天去重,只有每天第一次需要真正检测和消除。现在 go_main_page 里只要 dismiss_overlays=True 就传 force=True,会让每次回到主页面都执行完整浮层检测和 wait_for_page。如果 go_main_page 被任务循环频繁调用,会产生不必要的截图和等待开销。建议仅在启动/恢复场景使用 force=True,普通回主页仍按日去重。

  4. ensure_game_ready 和 recover_to_main_or_restart 可能重复执行 go_main_page
    recover_to_main_or_restart 的成功路径(无论是启动页分支、识别页面分支,还是 while 循环恢复成功)内部都已经调用 go_main_page;ensure_game_ready 随后又调用一次 go_main_page,会造成重复导航和重复浮层处理。建议让 recover_to_main_or_restart 只负责“恢复到主页面”,或让 ensure_game_ready 只在冷启动后负责 go_main_page,避免重复。

  5. go_main_page 中 wait_for_page(...) 的返回值没有检查
    需要确认 wait_for_page 在超时时的行为:

    • 如果它超时抛出异常,则当前逻辑能感知失败;
    • 如果它只是返回 False,当前代码会忽略失败,导致 go_main_page 静默认为主页面已就绪。
      建议显式判断返回值或依赖其抛异常语义,避免静默失败。
  6. start_game 的总超时预算可能让点击启动页后的等待时间过短
    现在 startup_timeout 同时覆盖“等待启动页出现”和“点击启动页后等待游戏页”。如果游戏在接近超时才出现启动页,_enter_from_start_screen 的剩余时间可能为 0,点击后几乎立刻超时。虽然这是预算语义的调整,但建议至少保留一个最小等待窗口,或在剩余时间不足时给出更明确的日志/错误信息。

  7. 小建议:handle_daily_overlays 的“先标记再执行”改为“清理成功后再标记”
    这本身更合理,因为失败后可以重试;但要注意在 force=True 下每次都会执行完整检测。如果某个浮层无法被现有逻辑关闭,且 go_main_page 频繁调用,可能造成持续高开销。建议确认 _OVERLAY_DISMISS_MAX 和 wait_for_page 的超时机制足以防止此类情况。

Comment thread docs/architecture/ops.md

### 页面导航

**文件**: `autowsgr/ops/navigate.py`

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

以下是对该代码变更片段的审核意见:

  1. 文档占位符不清晰
    wait_for_game_ui(ctrl, timeout=..., allow_start_screen=True) 中的 timeout=... 不是有效的默认值表达方式。建议明确写出具体的默认数值(例如 timeout=120)或改为 timeout: float = 120 的形式,避免使用省略号造成误解。

  2. 参数命名一致性不足
    表格中 start_game(ctrl, package) 和 restart_game(ctrl, package) 使用 package,而 ensure_game_ready(ctx, app) 仍使用 app。建议统一参数名称,或在文档中补充说明 app 与 package 的关系(例如 app 是由 package 推导出的对象),以免调用者混淆。

  3. 文档描述与代码行为需保持一致
    变更中特别提到了“点击进入后使用 allow_start_screen=False,防止尚未离开启动页便报告成功”,但表格中未体现该默认值在 start_game 或 restart_game 内部是如何传递的。建议在文档中补充说明 start_game 内部调用了 wait_for_game_ui(..., allow_start_screen=False),以便使用者理解该函数的实际等待逻辑。

  4. 缺少异常/边界行为说明
    新增段落详细说明了“冷启动与恢复流程共用相同的进入检查”,但没有说明当超时或多次检查失败时会发生什么(例如是否抛异常、重试策略、返回何种状态)。建议补充一句失败时的行为约定,便于调用方正确处理错误。

整体改动方向合理,提升了文档对实际逻辑的描述准确度,但上述细节可进一步完善。

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.

1 participant