feat: 添加强制激活游戏窗口设置 - #2502
Conversation
📝 Walkthrough新增
变更
Walkthrough新增 Changes强制激活游戏窗口
Estimated code review effort: 3 (Moderate) | ~25 minutes Sequence Diagram(s)sequenceDiagram
participant SettingEnvInterface
participant EnvConfig
participant ZContext
participant ZPcController
participant PcControllerBase
participant PcGameWindow
SettingEnvInterface->>EnvConfig: 保存 force_active_window
ZContext->>ZPcController: 传递 force_active_window
ZPcController->>PcControllerBase: 转发配置
PcControllerBase->>PcGameWindow: 检查并激活游戏窗口
PcGameWindow-->>PcControllerBase: 返回激活结果
PcControllerBase->>PcGameWindow: 激活成功后继续截图
Suggested reviewers: 🚥 Pre-merge checks | ✅ 3 | ❌ 2❌ Failed checks (2 warnings)
✅ Passed checks (3 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
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. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (1)
src/one_dragon_qt/view/setting/setting_env_interface.py (1)
77-83: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win为新增成员补充类型注解
src/**/*.py要求所有类成员变量都显式声明类型;请将该成员改为:- self.force_active_window_switch = SwitchSettingCard( + self.force_active_window_switch: SwitchSettingCard = SwitchSettingCard(依据项目规范,类成员变量必须使用类型注解。
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@src/one_dragon_qt/view/setting/setting_env_interface.py` around lines 77 - 83, 为 SettingEnvInterface 中新增的 force_active_window_switch 成员添加显式类型注解,使用其实际创建的 SwitchSettingCard 类型;保持现有初始化、信号连接和 basic_group.addSettingCard 调用不变。Sources: Coding guidelines, Path instructions
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@src/one_dragon/base/controller/pc_game_window.py`:
- Around line 154-192:
将_minimize_other_windows和_focus_window中的win32gui.SendMessage调用替换为win32gui.PostMessage,保持现有消息参数、等待逻辑、窗口状态检查及异常处理不变。
---
Nitpick comments:
In `@src/one_dragon_qt/view/setting/setting_env_interface.py`:
- Around line 77-83: 为 SettingEnvInterface 中新增的 force_active_window_switch
成员添加显式类型注解,使用其实际创建的 SwitchSettingCard 类型;保持现有初始化、信号连接和
basic_group.addSettingCard 调用不变。
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: e9158549-3cb5-4972-b574-b45c25685eff
📒 Files selected for processing (3)
src/one_dragon/base/controller/pc_controller_base.pysrc/one_dragon/base/controller/pc_game_window.pysrc/one_dragon_qt/view/setting/setting_env_interface.py
There was a problem hiding this comment.
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
src/one_dragon/base/controller/pc_game_window.py (1)
113-144: 🩺 Stability & Availability | 🟠 Major | ⚡ Quick win为强制激活设置最大重试次数或截止时间。
当窗口始终有效但 Windows 持续拒绝前台切换时,当前循环永不返回,导致 Line 158 的失败处理无法执行,并可能再次让日常任务挂起数小时。请在多次重试后返回
False,由调用方安全停止本轮操作。建议修复
attempt = 0 - while self.is_win_valid: + max_attempts = 30 if retry_until_active else 1 + while self.is_win_valid and attempt < max_attempts: ... attempt += 1 time.sleep(1) + if self.is_win_valid: + log.error('多次尝试后仍无法激活游戏窗口') + return False log.error('游戏窗口已失效,无法恢复前台焦点') return False🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@src/one_dragon/base/controller/pc_game_window.py` around lines 113 - 144, 为 active 方法增加强制激活的最大重试次数或截止时间,确保 retry_until_active 为 true 且 Windows 持续拒绝前台切换时最终退出循环并返回 False。保留成功激活时的立即返回及窗口失效处理,并让现有重试流程在达到限制后执行失败日志和安全返回。
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Outside diff comments:
In `@src/one_dragon/base/controller/pc_game_window.py`:
- Around line 113-144: 为 active 方法增加强制激活的最大重试次数或截止时间,确保 retry_until_active 为
true 且 Windows 持续拒绝前台切换时最终退出循环并返回
False。保留成功激活时的立即返回及窗口失效处理,并让现有重试流程在达到限制后执行失败日志和安全返回。
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: b42ffec7-0ac3-4b35-ac69-5534654e6449
📒 Files selected for processing (4)
deploy/module_manifest.pysrc/one_dragon/base/controller/pc_controller_base.pysrc/one_dragon/base/controller/pc_game_window.pysrc/one_dragon_qt/view/setting/setting_env_interface.py
💤 Files with no reviewable changes (1)
- deploy/module_manifest.py
🚧 Files skipped from review as they are similar to previous changes (1)
- src/one_dragon_qt/view/setting/setting_env_interface.py
|
这种橙色的感觉一般是启动的时候就没到前台过;按我的经验,到过前台的游戏切换到前台不会失败 |
正常情况下,可以直接激活曾经处于过前台,但是不小心切到后台的窗口 但如果,打开一条龙并配置好游戏路径时,按下F9,趁绝区零游戏窗口还没有打开,立即疯狂点击切换到其他不相关的应用窗口,绝区零的窗口不会在前台出现, |
|
所以实际上这是两个问题 |
|
BetterGI 明确区分: |
091d3ee to
e279ff2
Compare
There was a problem hiding this comment.
Actionable comments posted: 2
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@src/one_dragon_qt/view/setting/setting_env_interface.py`:
- Around line 77-80: 为 SettingEnvInterface 中的实例成员变量
self.force_active_window_switch 添加明确的 SwitchSettingCard 类型注解,并保留现有的初始化逻辑和配置内容不变。
In `@src/one_dragon/base/controller/pc_game_window.py`:
- Line 17: 为类成员变量 MAX_ACTIVE_ATTEMPTS 添加 int 类型注解,保持其现有值 30 和其他行为不变。
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: b9101565-29a1-45d8-a681-a2ae4a04abb4
📒 Files selected for processing (4)
docs/develop/one_dragon/background_mode_design.mdsrc/one_dragon/base/controller/pc_controller_base.pysrc/one_dragon/base/controller/pc_game_window.pysrc/one_dragon_qt/view/setting/setting_env_interface.py
🚧 Files skipped from review as they are similar to previous changes (2)
- src/one_dragon/base/controller/pc_controller_base.py
- docs/develop/one_dragon/background_mode_design.md
✅ Action performedReviews resumed. |
1 similar comment
✅ Action performedReviews resumed. |
There was a problem hiding this comment.
Actionable comments posted: 1
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
src/one_dragon_qt/view/setting/setting_env_interface.py (1)
95-95: 📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick win为修改的设置卡成员补充类型注解。
self.repository_url_opt、self.cpython_source_opt和self.pip_source_opt是类成员,但当前声明没有类型注解。请分别声明为ComboBoxSettingCard。建议的修复
- self.repository_url_opt = ComboBoxSettingCard( + self.repository_url_opt: ComboBoxSettingCard = ComboBoxSettingCard( - self.cpython_source_opt = ComboBoxSettingCard( + self.cpython_source_opt: ComboBoxSettingCard = ComboBoxSettingCard( - self.pip_source_opt = ComboBoxSettingCard( + self.pip_source_opt: ComboBoxSettingCard = ComboBoxSettingCard(As per coding guidelines,
src/**/*.py要求“所有函数签名和类成员变量必须有类型注解”。Also applies to: 121-121, 132-132
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@src/one_dragon_qt/view/setting/setting_env_interface.py` at line 95, 为设置界面类中的成员变量 self.repository_url_opt、self.cpython_source_opt 和 self.pip_source_opt 补充 ComboBoxSettingCard 类型注解,保持现有初始化逻辑不变。Source: Coding guidelines
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@docs/develop/one_dragon/background_mode_design.md`:
- Around line 319-323: Remove the unresolved Git conflict markers around the
control_method entry and keep one description consistent with the actual
GameConfig.get_action_keys(control_method) signature, including whether the
argument is explicitly required. Verify the documentation build succeeds after
resolving the section.
---
Outside diff comments:
In `@src/one_dragon_qt/view/setting/setting_env_interface.py`:
- Line 95: 为设置界面类中的成员变量 self.repository_url_opt、self.cpython_source_opt 和
self.pip_source_opt 补充 ComboBoxSettingCard 类型注解,保持现有初始化逻辑不变。
🪄 Autofix
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro Plus
Run ID: 5d6e1e99-a325-4559-a2e0-05e97d9ce718
📒 Files selected for processing (5)
deploy/module_manifest.pydocs/develop/one_dragon/background_mode_design.mdsrc/one_dragon/base/controller/pc_controller_base.pysrc/one_dragon/envs/env_config.pysrc/one_dragon_qt/view/setting/setting_env_interface.py
🚧 Files skipped from review as they are similar to previous changes (2)
- deploy/module_manifest.py
- src/one_dragon/base/controller/pc_controller_base.py
cbe206e to
7f9078b
Compare
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@docs/develop/one_dragon/background_mode_design.md`:
- Around line 204-205: 更新文档中 enable_background_mode() 在架构说明及对应描述处,将仅支持 Xbox
改为支持所选手柄(Xbox/DS4),以与 get_gamepad_action_keys('ds4') 及现有动作映射保持一致;同时检查
btn_controller 列表是否为完整控制器列表,若是则加入 ds4_controller。
🪄 Autofix
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro Plus
Run ID: ad33028c-adb4-4fe9-8cf4-933549ba2be6
📒 Files selected for processing (1)
docs/develop/one_dragon/background_mode_design.md
close #2490