Skip to content

feat: 支持腾讯应用宝5.10.56.xx+#540

Merged
wangl-cc merged 5 commits into
MaaAssistantArknights:mainfrom
srdr0p:main
May 25, 2026
Merged

feat: 支持腾讯应用宝5.10.56.xx+#540
wangl-cc merged 5 commits into
MaaAssistantArknights:mainfrom
srdr0p:main

Conversation

@srdr0p

@srdr0p srdr0p commented May 1, 2026

Copy link
Copy Markdown
Contributor

Summary by Sourcery

为 Tencent Androws 模拟器预设添加支持,包括在 Windows 上自动发现 ADB,以及在连接时选择客户端类型。

New Features:

  • 引入 Androws 连接预设,提供默认的 ADB 路径、地址和配置值。
  • 允许在连接期间在 Assistant 实例上配置客户端类型(游戏渠道)。

Enhancements:

  • 优化连接参数处理逻辑,根据需要使用拥有或借用的 ADB 路径,以便更好地基于预设解析路径。
  • 改进与客户端类型和连接配置处理相关的日志输出。

Build:

  • 在 Windows 上新增 winreg 依赖项,用于从注册表中读取 Androws 安装数据并解析 ADB 路径。

Tests:

  • 扩展预设反序列化和连接参数测试,以覆盖 Androws 预设及其默认值。
  • 添加 Windows 特定的 Androws ADB 路径解析测试,并调整基于命令的机密测试以具备平台感知能力。
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:

  • Introduce an Androws connection preset with default ADB path, address, and config values.
  • Allow configuring the client type (game channel) on the Assistant instance during connection.

Enhancements:

  • Refine connection argument handling to use owned or borrowed ADB paths for better preset-based path resolution.
  • Improve logging around client type and connection configuration handling.

Build:

  • Add the winreg dependency on Windows to read Androws installation data from the registry and resolve the ADB path.

Tests:

  • Extend preset deserialization and connection argument tests to cover the Androws preset and its defaults.
  • Add Windows-specific tests for Androws ADB path resolution and adjust command-based secret tests to be platform-aware.

新功能:

  • 引入新的 Androws 连接预设,包含默认 adb 路径、地址以及配置解析,并支持通过 Windows 注册表自动发现 adb。
  • 在 Windows 上新增 Androws 外部应用集成,在连接前会验证模拟器是否已运行。
  • 新增可配置的 ClientType 实例选项,用于在连接时选择游戏渠道。

增强:

  • 优化连接参数处理,通过 Cow 使用“自有或借用”的 adb 路径值,以更好地支持基于预设的路径计算。
  • 扩展助手运行流程,在 Assistant 实例上设置客户端类型,并改进与客户端配置相关的调试日志。

构建:

  • 新增仅在 Windows 下启用的依赖 windows-sys,用于支持通过注册表访问来检测 Androws 的 adb 路径。

测试:

  • 扩展预设反序列化与连接参数测试,以覆盖新的 Androws 预设及其默认值。
  • 为新的 Androws 外部应用构造函数添加单元测试。
Original summary in English

Summary by Sourcery

为 Tencent Androws 模拟器预设添加支持,包括在 Windows 上自动发现 ADB,以及在连接时选择客户端类型。

New Features:

  • 引入 Androws 连接预设,提供默认的 ADB 路径、地址和配置值。
  • 允许在连接期间在 Assistant 实例上配置客户端类型(游戏渠道)。

Enhancements:

  • 优化连接参数处理逻辑,根据需要使用拥有或借用的 ADB 路径,以便更好地基于预设解析路径。
  • 改进与客户端类型和连接配置处理相关的日志输出。

Build:

  • 在 Windows 上新增 winreg 依赖项,用于从注册表中读取 Androws 安装数据并解析 ADB 路径。

Tests:

  • 扩展预设反序列化和连接参数测试,以覆盖 Androws 预设及其默认值。
  • 添加 Windows 特定的 Androws ADB 路径解析测试,并调整基于命令的机密测试以具备平台感知能力。
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:

  • Introduce an Androws connection preset with default ADB path, address, and config values.
  • Allow configuring the client type (game channel) on the Assistant instance during connection.

Enhancements:

  • Refine connection argument handling to use owned or borrowed ADB paths for better preset-based path resolution.
  • Improve logging around client type and connection configuration handling.

Build:

  • Add the winreg dependency on Windows to read Androws installation data from the registry and resolve the ADB path.

Tests:

  • Extend preset deserialization and connection argument tests to cover the Androws preset and its defaults.
  • Add Windows-specific tests for Androws ADB path resolution and adjust command-based secret tests to be platform-aware.

@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.

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>

Sourcery 对开源项目是免费的——如果你觉得这些评审有帮助,欢迎分享 ✨
帮我变得更有用!请在每条评论上点击 👍 或 👎,我会根据反馈改进后续的评审。
Original comment in English

Hey - I've found 1 issue, and left some high level feedback:

  • 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.
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>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

Comment thread crates/maa-cli/src/config/asst.rs Outdated
@srdr0p

srdr0p commented May 11, 2026

Copy link
Copy Markdown
Contributor Author

@wangl-cc 麻烦看看

@wangl-cc

Copy link
Copy Markdown
Member

感谢贡献!不好意思,我最近一段时间都比较忙,我今天晚点看一下。

@codecov

codecov Bot commented May 11, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 67.39130% with 15 lines in your changes missing coverage. Please review.
✅ Project coverage is 72.25%. Comparing base (5d0638c) to head (a2f14a4).
⚠️ Report is 3 commits behind head on main.

Files with missing lines Patch % Lines
crates/maa-cli/src/config/asst.rs 75.67% 7 Missing and 2 partials ⚠️
crates/maa-cli/src/run/mod.rs 0.00% 6 Missing ⚠️
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.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@srdr0p

srdr0p commented May 12, 2026

Copy link
Copy Markdown
Contributor Author

@wangl-cc 修了下build错误

@wangl-cc

Copy link
Copy Markdown
Member

感谢贡献,我终于有时间看了一下。我看到加了一个 InstanceOption,这是 MaaCore 最近新加的 API 吗?

@wangl-cc

Copy link
Copy Markdown
Member

我把 clippy 在 main 里面修了一下,可能你需要 rebase 一下。

@srdr0p

srdr0p commented May 18, 2026

Copy link
Copy Markdown
Contributor Author

我把 clippy 在 main 里面修了一下,可能你需要 rebase 一下。

rebase并修了cargo fmt,MaaCore的client_type提交为 MaaAssistantArknights/MaaAssistantArknights#16292

Comment thread crates/maa-cli/src/run/external/androws.rs Outdated
Comment thread crates/maa-cli/src/config/asst.rs Outdated
@wangl-cc

Copy link
Copy Markdown
Member

@sourcery-ai review

@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.

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>

Sourcery 对开源项目免费——如果你喜欢我们的代码审查,请考虑帮忙分享 ✨
帮我变得更有用!请在每条评论上点 👍 或 👎,我会根据反馈改进之后的审查建议。
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 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.
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>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

Comment on lines +290 to +299
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)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

issue (bug_risk): 使用 winreg::HKLM 可能会在某些 crate 版本下无法编译;RegKey::predef(HKEY_LOCAL_MACHINE) 是更常见的用法。

这段代码依赖 winreg::HKLM 是一个带有 open_subkeyRegKey,但在很多 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.

@srdr0p

srdr0p commented May 25, 2026

Copy link
Copy Markdown
Contributor Author

@wangl-cc winreg::HKLM 确认是官方用法,cargo fmt已修复。覆盖率那个显示%0的secret.rs应该是误报,补丁只修了windows的测试问题。

@wangl-cc

Copy link
Copy Markdown
Member

LGTM,感谢贡献!!

@wangl-cc
wangl-cc merged commit fd26e21 into MaaAssistantArknights:main May 25, 2026
31 of 33 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