Skip to content

fix(script):适配桌面版空闲策略关闭游戏,修复桌面版关闭游戏后无法重启的问题 - #1994

Merged
runhey merged 2 commits into
runhey:devfrom
Hurry2:dev
Oct 31, 2026
Merged

runhey merged 2 commits into
runhey:devfrom
Hurry2:dev

Conversation

@Hurry2

@Hurry2 Hurry2 commented Oct 31, 2026 •

Copy link
Copy Markdown
Contributor

最新补丁,配合前面的pr已经可以实现和模拟器一样的闲时关闭,有任务正常唤起的24h挂机

Sourcery 摘要

修复桌面客户端关闭后的恢复流程,并正确处理已存在窗口的登录状态。

错误修复:

  • 修复关闭桌面版游戏后,无法通过“重启”重新启动的问题。
  • 修复接管正在运行的桌面客户端时,错误重置登录状态的问题。

功能增强:

  • 支持桌面版根据实际登录状态管理已存在的客户端窗口,并结合空闲策略,按需关闭客户端和唤起任务。
Original summary in English

Summary by Sourcery

修复桌面版客户端关闭后的恢复流程,并正确处理已存在窗口的登录状态。

Bug Fixes:

  • 修复桌面版关闭游戏后无法通过 Restart 重新启动的问题。
  • 修复认领已运行桌面客户端时错误重置登录状态的问题。

Enhancements:

  • 支持桌面版根据实际登录状态管理已存在的客户端窗口,并配合空闲策略实现客户端按需关闭与任务唤起。

桌面版窗口不在时 Script.run 预截图必抛 GameNotRunningError,
Restart 任务永远跑不到,恢复循环空转;command=Restart 时放行预截图。

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

嘿——我发现了 1 个问题

Prompt for AI Agents
Please address the comments from this code review:

## Individual Comments

### Comment 1
<location path="module/device/method/desktop_impl.py" line_range="1332" />
<code_context>
+        else:
+            # 认领已存在的窗口:可能早已登录。已登录的客户端全系统枚举不到
+            # MPAY_LOGIN 顶层窗口(见 find_desktop_login_popup),以此区分
+            self._desktop_login_done = not self.find_desktop_login_popup()
         # 客户端已拉起,强制保持显示器常亮(线程级状态,随客户端关闭解除)
         desktop_keep_screen_on(True)
</code_context>
<issue_to_address>
**Tasks run before login**

When an existing client window is claimed before its MPay login popup appears, `desktop_bind_pid` sets `_desktop_login_done` to true based on the initial popup scan, and `app_is_running` trusts that cached flag. The scheduler skips Restart’s login flow and sends gameplay tasks to the loading or login screen.

Keep `_desktop_login_done` false for a newly claimed client until its login state is confirmed, so the login flow runs if the popup appears after the initial scan.

Also at `module/device/desktop_device.py:42`, `module/device/handle.py:187`.
</issue_to_address>

Sourcery 评估

等待批准。 请先处理 1 项发现。

阻塞性发现:module/device/method/desktop_impl.py:1332


Sourcery 对开源项目免费——如果您喜欢我们的评审,请考虑分享 ✨
Original comment in English

Hey - I've found 1 issue

Prompt for AI Agents
Please address the comments from this code review:

## Individual Comments

### Comment 1
<location path="module/device/method/desktop_impl.py" line_range="1332" />
<code_context>
+        else:
+            # 认领已存在的窗口:可能早已登录。已登录的客户端全系统枚举不到
+            # MPAY_LOGIN 顶层窗口(见 find_desktop_login_popup),以此区分
+            self._desktop_login_done = not self.find_desktop_login_popup()
         # 客户端已拉起,强制保持显示器常亮(线程级状态,随客户端关闭解除)
         desktop_keep_screen_on(True)
</code_context>
<issue_to_address>
**Tasks run before login**

When an existing client window is claimed before its MPay login popup appears, `desktop_bind_pid` sets `_desktop_login_done` to true based on the initial popup scan, and `app_is_running` trusts that cached flag. The scheduler skips Restart’s login flow and sends gameplay tasks to the loading or login screen.

Keep `_desktop_login_done` false for a newly claimed client until its login state is confirmed, so the login flow runs if the popup appears after the initial scan.

Also at `module/device/desktop_device.py:42`, `module/device/handle.py:187`.
</issue_to_address>

Sourcery assessment

Approval pending. 1 finding to address first.

Blocking findings: module/device/method/desktop_impl.py:1332


Sourcery is free for open source - if you like our reviews please consider sharing them ✨

else:
# 认领已存在的窗口:可能早已登录。已登录的客户端全系统枚举不到
# MPAY_LOGIN 顶层窗口(见 find_desktop_login_popup),以此区分
self._desktop_login_done = not self.find_desktop_login_popup()

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟡 中等 · 任务在登录前运行

如果在现有客户端窗口的 MPay 登录弹窗出现之前就认领该窗口,desktop_bind_pid 会根据初始弹窗扫描结果将 _desktop_login_done 设为 true,而 app_is_running 会信任这个缓存标志。调度器因此跳过 Restart 的登录流程,并将游戏任务发送到加载界面或登录界面。

对于新认领的客户端,在确认其登录状态之前,应保持 _desktop_login_done 为 false,这样如果弹窗在初始扫描后才出现,登录流程仍会运行。

另见 module/device/desktop_device.py:42、module/device/handle.py:187。

面向 AI 智能体的提示
在 `module/device/method/desktop_impl.py` 第 1332 行:

**任务在登录前运行**

如果在现有客户端窗口的 MPay 登录弹窗出现之前就认领该窗口,`desktop_bind_pid` 会根据初始弹窗扫描结果将 `_desktop_login_done` 设为 true,而 `app_is_running` 会信任这个缓存标志。调度器因此跳过 Restart 的登录流程,并将游戏任务发送到加载界面或登录界面。

对于新认领的客户端,在确认其登录状态之前,应保持 `_desktop_login_done` 为 false,这样如果弹窗在初始扫描后才出现,登录流程仍会运行。

另见 `module/device/desktop_device.py:42`、`module/device/handle.py:187`。
Original comment in English

🟡 Medium · Tasks run before login

When an existing client window is claimed before its MPay login popup appears, desktop_bind_pid sets _desktop_login_done to true based on the initial popup scan, and app_is_running trusts that cached flag. The scheduler skips Restart’s login flow and sends gameplay tasks to the loading or login screen.

Keep _desktop_login_done false for a newly claimed client until its login state is confirmed, so the login flow runs if the popup appears after the initial scan.

Also at module/device/desktop_device.py:42, module/device/handle.py:187.

Prompt for AI agents
In `module/device/method/desktop_impl.py` at line 1332:

**Tasks run before login**

When an existing client window is claimed before its MPay login popup appears, `desktop_bind_pid` sets `_desktop_login_done` to true based on the initial popup scan, and `app_is_running` trusts that cached flag. The scheduler skips Restart’s login flow and sends gameplay tasks to the loading or login screen.

Keep `_desktop_login_done` false for a newly claimed client until its login state is confirmed, so the login flow runs if the popup appears after the initial scan.

Also at `module/device/desktop_device.py:42`, `module/device/handle.py:187`.

@runhey
runhey merged commit 8307b20 into runhey:dev Oct 31, 2026
6 of 8 checks passed
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