feat: 支持腾讯应用宝5.10.56.xx+#540
Conversation
There was a problem hiding this comment.
Hey - 我发现了 1 个问题,并给出了一些整体性的反馈:
get_androws_adb_path中对 Windows 注册表的处理可以更健壮一些:比如同时接受REG_EXPAND_SZ类型的值(安装路径常见为该类型),并将HKEY句柄封装进一个小的 RAII 帮助器中,以保证在所有提前返回路径上都调用RegCloseKey,而不是在多处手动关闭。- 在
AndrowsApp::open中,start_if_needed标志被忽略了;建议要么在 Androws 未运行时使用这个标志尝试启动它,要么明确记录日志说明该标志是被有意忽略的,以免调用方误解其行为。
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- `get_androws_adb_path` 中对 Windows 注册表的处理可以更健壮一些:比如同时接受 `REG_EXPAND_SZ` 类型的值(安装路径常见为该类型),并将 `HKEY` 句柄封装进一个小的 RAII 帮助器中,以保证在所有提前返回路径上都调用 `RegCloseKey`,而不是在多处手动关闭。
- 在 `AndrowsApp::open` 中,`start_if_needed` 标志被忽略了;建议要么在 Androws 未运行时使用这个标志尝试启动它,要么明确记录日志说明该标志是被有意忽略的,以免调用方误解其行为。
## Individual Comments
### Comment 1
<location path="crates/maa-cli/src/config/asst.rs" line_range="324-326" />
<code_context>
+ }
+
+ /// Open a registry subkey under HKLM with KEY_READ access.
+ unsafe fn open_hklm_key(subkey: &str) -> Option<HKEY> {
+ let subkey_wide: Vec<u16> = subkey.encode_utf16().chain(std::iter::once(0)).collect();
+ let mut hkey: HKEY = std::ptr::null_mut();
+ let rc = unsafe {
+ RegOpenKeyExW(
</code_context>
<issue_to_address>
**issue (bug_risk):** `windows-sys` 中的 HKEY 不是指针类型;使用 `null_mut()` 初始化很可能会导致类型错误。
在 `windows-sys` 中,`HKEY` 是一个整数句柄(`isize`),因此将 `std::ptr::null_mut()` 赋值给它是类型错误,也与 API 不匹配。应将其初始化为整数,例如 `let mut hkey: HKEY = 0;` 或 `HKEY::default()`,并继续将 `&mut hkey` 传给 `RegOpenKeyExW`。
</issue_to_address>帮我变得更有用!请在每条评论上点击 👍 或 👎,我会根据反馈改进后续的评审。
Original comment in English
Hey - I've found 1 issue, and left some high level feedback:
- The Windows registry handling in
get_androws_adb_pathcould be made more robust by also acceptingREG_EXPAND_SZvalues (common for install paths) and by wrapping theHKEYhandle in a small RAII helper to guaranteeRegCloseKeyon all early-return paths rather than manually closing in multiple places. - In
AndrowsApp::open, thestart_if_neededflag is ignored; consider either using it to attempt to launch Androws when it's not running or logging explicitly that the flag is intentionally ignored so callers are not misled about the behavior.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- The Windows registry handling in `get_androws_adb_path` could be made more robust by also accepting `REG_EXPAND_SZ` values (common for install paths) and by wrapping the `HKEY` handle in a small RAII helper to guarantee `RegCloseKey` on all early-return paths rather than manually closing in multiple places.
- In `AndrowsApp::open`, the `start_if_needed` flag is ignored; consider either using it to attempt to launch Androws when it's not running or logging explicitly that the flag is intentionally ignored so callers are not misled about the behavior.
## Individual Comments
### Comment 1
<location path="crates/maa-cli/src/config/asst.rs" line_range="324-326" />
<code_context>
+ }
+
+ /// Open a registry subkey under HKLM with KEY_READ access.
+ unsafe fn open_hklm_key(subkey: &str) -> Option<HKEY> {
+ let subkey_wide: Vec<u16> = subkey.encode_utf16().chain(std::iter::once(0)).collect();
+ let mut hkey: HKEY = std::ptr::null_mut();
+ let rc = unsafe {
+ RegOpenKeyExW(
</code_context>
<issue_to_address>
**issue (bug_risk):** HKEY is not a pointer type in `windows-sys`; initializing it with `null_mut()` is likely a type error.
`HKEY` in `windows-sys` is an integer handle (`isize`), so assigning `std::ptr::null_mut()` is a type error and doesn’t match the API. Initialize it as an integer instead, e.g. `let mut hkey: HKEY = 0;` or `HKEY::default()`, and continue passing `&mut hkey` to `RegOpenKeyExW`.
</issue_to_address>Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
|
@wangl-cc 麻烦看看 |
|
感谢贡献!不好意思,我最近一段时间都比较忙,我今天晚点看一下。 |
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #540 +/- ##
==========================================
+ Coverage 71.86% 72.25% +0.38%
==========================================
Files 69 72 +3
Lines 6412 6656 +244
Branches 6412 6656 +244
==========================================
+ Hits 4608 4809 +201
- Misses 1477 1505 +28
- Partials 327 342 +15 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
|
@wangl-cc 修了下build错误 |
|
感谢贡献,我终于有时间看了一下。我看到加了一个 InstanceOption,这是 MaaCore 最近新加的 API 吗? |
|
我把 clippy 在 main 里面修了一下,可能你需要 rebase 一下。 |
rebase并修了cargo fmt,MaaCore的client_type提交为 MaaAssistantArknights/MaaAssistantArknights#16292 |
|
@sourcery-ai review |
There was a problem hiding this comment.
Hey - 我发现了 1 个问题,并给出了一些整体性的反馈:
- 在仅适用于 Windows 的测试
build_androws_adb_path_existing中,建议使用tempfile::TempDir(或类似的、按测试用的临时目录),而不是在std::env::temp_dir()下使用固定子目录,以避免并发测试运行时的潜在冲突,并确保即使测试发生 panic 也能完成清理。 - 由于 Androws 预设只在 Windows 上有意义,你可能希望通过
cfg(windows)来对Preset::Androws以及对应的asst_config_template选项做条件编译,这样在非 Windows 平台上就不会提供一个实际上无法使用的预设。
供 AI Agents 使用的提示词
Please address the comments from this code review:
## Overall Comments
- 在仅适用于 Windows 的测试 `build_androws_adb_path_existing` 中,建议使用 `tempfile::TempDir`(或类似的、按测试用的临时目录),而不是在 `std::env::temp_dir()` 下使用固定子目录,以避免并发测试运行时的潜在冲突,并确保即使测试发生 panic 也能完成清理。
- 由于 Androws 预设只在 Windows 上有意义,你可能希望通过 `cfg(windows)` 来对 `Preset::Androws` 以及对应的 `asst_config_template` 选项做条件编译,这样在非 Windows 平台上就不会提供一个实际上无法使用的预设。
## Individual Comments
### Comment 1
<location path="crates/maa-cli/src/config/asst.rs" line_range="290-299" />
<code_context>
+/// - `HKLM\SOFTWARE\Tencent\Androws\Androws` → `Version` (e.g. `1.2.3.4`)
+/// - adb path: `{InstallPath}\Application\{Version}\adb.exe`
+#[cfg(windows)]
+fn get_androws_adb_path() -> Option<String> {
+ let hklm = winreg::HKLM;
+
+ let install_key = hklm.open_subkey(r"SOFTWARE\Tencent\Androws").ok()?;
+ let install_path: String = install_key.get_value("InstallPath").ok()?;
+
+ let app_key = hklm.open_subkey(r"SOFTWARE\Tencent\Androws\Androws").ok()?;
+ let version: String = app_key.get_value("Version").ok()?;
+
+ build_androws_adb_path(&install_path, &version)
+}
+
</code_context>
<issue_to_address>
**issue (bug_risk):** 使用 `winreg::HKLM` 可能会在某些 crate 版本下无法编译;`RegKey::predef(HKEY_LOCAL_MACHINE)` 是更常见的用法。
这段代码依赖 `winreg::HKLM` 是一个带有 `open_subkey` 的 `RegKey`,但在很多 crate 版本中并非如此,会导致编译错误。请核实当前使用的 `winreg` API,并改用类似如下的方式:
```rust
use winreg::{enums::HKEY_LOCAL_MACHINE, RegKey};
let hklm = RegKey::predef(HKEY_LOCAL_MACHINE);
let install_key = hklm.open_subkey(r"SOFTWARE\\Tencent\\Androws")?;
```
以避免类型不匹配,并使意图更加明确。
</issue_to_address>帮我变得更有用!请在每条评论上点 👍 或 👎,我会根据反馈改进之后的审查建议。
Original comment in English
Hey - I've found 1 issue, and left some high level feedback:
- In the Windows-only test
build_androws_adb_path_existing, consider usingtempfile::TempDir(or a similar per-test temporary directory) instead of a fixed subdirectory understd::env::temp_dir()to avoid potential collisions between concurrent test runs and to ensure cleanup even if the test panics. - Since the Androws preset is only meaningful on Windows, you may want to gate
Preset::Androwsand the correspondingasst_config_templateoption behindcfg(windows)so that non-Windows platforms are not offered a preset they cannot actually use.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- In the Windows-only test `build_androws_adb_path_existing`, consider using `tempfile::TempDir` (or a similar per-test temporary directory) instead of a fixed subdirectory under `std::env::temp_dir()` to avoid potential collisions between concurrent test runs and to ensure cleanup even if the test panics.
- Since the Androws preset is only meaningful on Windows, you may want to gate `Preset::Androws` and the corresponding `asst_config_template` option behind `cfg(windows)` so that non-Windows platforms are not offered a preset they cannot actually use.
## Individual Comments
### Comment 1
<location path="crates/maa-cli/src/config/asst.rs" line_range="290-299" />
<code_context>
+/// - `HKLM\SOFTWARE\Tencent\Androws\Androws` → `Version` (e.g. `1.2.3.4`)
+/// - adb path: `{InstallPath}\Application\{Version}\adb.exe`
+#[cfg(windows)]
+fn get_androws_adb_path() -> Option<String> {
+ let hklm = winreg::HKLM;
+
+ let install_key = hklm.open_subkey(r"SOFTWARE\Tencent\Androws").ok()?;
+ let install_path: String = install_key.get_value("InstallPath").ok()?;
+
+ let app_key = hklm.open_subkey(r"SOFTWARE\Tencent\Androws\Androws").ok()?;
+ let version: String = app_key.get_value("Version").ok()?;
+
+ build_androws_adb_path(&install_path, &version)
+}
+
</code_context>
<issue_to_address>
**issue (bug_risk):** Using `winreg::HKLM` may not compile depending on the crate version; `RegKey::predef(HKEY_LOCAL_MACHINE)` is the more typical pattern.
This code relies on `winreg::HKLM` being a `RegKey` with `open_subkey`, which is not true in many crate versions and will cause a compile error. Verify the actual `winreg` API in use and switch to something like:
```rust
use winreg::{enums::HKEY_LOCAL_MACHINE, RegKey};
let hklm = RegKey::predef(HKEY_LOCAL_MACHINE);
let install_key = hklm.open_subkey(r"SOFTWARE\\Tencent\\Androws")?;
```
to avoid the type mismatch and make the intent explicit.
</issue_to_address>Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
| fn get_androws_adb_path() -> Option<String> { | ||
| let hklm = winreg::HKLM; | ||
|
|
||
| let install_key = hklm.open_subkey(r"SOFTWARE\Tencent\Androws").ok()?; | ||
| let install_path: String = install_key.get_value("InstallPath").ok()?; | ||
|
|
||
| let app_key = hklm.open_subkey(r"SOFTWARE\Tencent\Androws\Androws").ok()?; | ||
| let version: String = app_key.get_value("Version").ok()?; | ||
|
|
||
| build_androws_adb_path(&install_path, &version) |
There was a problem hiding this comment.
issue (bug_risk): 使用 winreg::HKLM 可能会在某些 crate 版本下无法编译;RegKey::predef(HKEY_LOCAL_MACHINE) 是更常见的用法。
这段代码依赖 winreg::HKLM 是一个带有 open_subkey 的 RegKey,但在很多 crate 版本中并非如此,会导致编译错误。请核实当前使用的 winreg API,并改用类似如下的方式:
use winreg::{enums::HKEY_LOCAL_MACHINE, RegKey};
let hklm = RegKey::predef(HKEY_LOCAL_MACHINE);
let install_key = hklm.open_subkey(r"SOFTWARE\\Tencent\\Androws")?;以避免类型不匹配,并使意图更加明确。
Original comment in English
issue (bug_risk): Using winreg::HKLM may not compile depending on the crate version; RegKey::predef(HKEY_LOCAL_MACHINE) is the more typical pattern.
This code relies on winreg::HKLM being a RegKey with open_subkey, which is not true in many crate versions and will cause a compile error. Verify the actual winreg API in use and switch to something like:
use winreg::{enums::HKEY_LOCAL_MACHINE, RegKey};
let hklm = RegKey::predef(HKEY_LOCAL_MACHINE);
let install_key = hklm.open_subkey(r"SOFTWARE\\Tencent\\Androws")?;to avoid the type mismatch and make the intent explicit.
|
@wangl-cc winreg::HKLM 确认是官方用法,cargo fmt已修复。覆盖率那个显示%0的secret.rs应该是误报,补丁只修了windows的测试问题。 |
|
LGTM,感谢贡献!! |
Summary by Sourcery
为 Tencent Androws 模拟器预设添加支持,包括在 Windows 上自动发现 ADB,以及在连接时选择客户端类型。
New Features:
Enhancements:
Build:
winreg依赖项,用于从注册表中读取 Androws 安装数据并解析 ADB 路径。Tests:
Original summary in English
Summary by Sourcery
Add support for the Tencent Androws emulator preset, including automatic ADB discovery on Windows and client type selection during connection.
New Features:
Enhancements:
Build:
Tests:
新功能:
ClientType实例选项,用于在连接时选择游戏渠道。增强:
Cow使用“自有或借用”的 adb 路径值,以更好地支持基于预设的路径计算。Assistant实例上设置客户端类型,并改进与客户端配置相关的调试日志。构建:
windows-sys,用于支持通过注册表访问来检测 Androws 的 adb 路径。测试:
Original summary in English
Summary by Sourcery
为 Tencent Androws 模拟器预设添加支持,包括在 Windows 上自动发现 ADB,以及在连接时选择客户端类型。
New Features:
Enhancements:
Build:
winreg依赖项,用于从注册表中读取 Androws 安装数据并解析 ADB 路径。Tests:
Original summary in English
Summary by Sourcery
Add support for the Tencent Androws emulator preset, including automatic ADB discovery on Windows and client type selection during connection.
New Features:
Enhancements:
Build:
Tests: