Skip to content

Conversation

@RainYangty
Copy link
Contributor

@RainYangty RainYangty commented Dec 12, 2025

Summary

This Pull Request introduces a new feature to detect Arknights game crashes on macOS using Optical Character Recognition (OCR) against the system's Problem Reporter window.

The core addition is the ProblemReporterScanner, which periodically checks the screen for the crash report window and uses OCR to confirm if the reported process is related to the game.

Alongside the detection logic, a new user preference is implemented: autoRestartGameOnCrash. When this setting is enabled and a crash is detected, the MaaToolClient logic is triggered to automatically restart the game, significantly improving the user experience during unattended operation.

This change provides a robust, platform-specific solution for high-fidelity crash detection, allowing the application to autonomously recover and continue operation, thus enhancing the overall stability and reliability of the automation tool.

Key Changes

  1. New Feature: Introduced ProblemReporterScanner for macOS-specific crash detection using OCR on the Problem Reporter window.
  2. User Preference: Added new setting autoRestartGameOnCrash to store the user's preference for automatic game restart upon crash detection.
  3. UI Integration: Added a corresponding option to the user settings interface.
  4. Logic Integration:
    • Updated MaaToolClient to incorporate the new crash detection logic and initiate the game restart process when the setting is enabled.
    • Updated MAAViewModel to handle the new setting storage, retrieval, and UI state synchronization. -----

摘要

本次拉取请求(PR)引入了一项新功能,通过对系统**“问题报告”**窗口执行光学字符识别(OCR),来检测 macOS 上的 《明日方舟》 游戏崩溃。

核心新增部分是 ProblemReporterScanner,它会周期性地检查屏幕上的崩溃报告窗口,并利用 OCR 确认报告的进程是否与游戏相关。

与检测逻辑同时,我们实现了一个新的用户偏好设置:autoRestartGameOnCrash。当此设置启用且检测到崩溃时,将触发 MaaToolClient 逻辑来自动重启游戏,从而显著改善无人值守操作期间的用户体验。

本次更改提供了一个健壮的、针对特定平台的解决方案,用于高精度的崩溃检测。它允许应用程序在检测到崩溃后自动恢复并继续运行,从而增强了自动化工具的整体稳定性和可靠性。

主要更改

  1. 新功能: 引入 ProblemReporterScanner,使用 OCR 技术对“问题报告”窗口进行扫描,实现 macOS 特有的崩溃检测。
  2. 用户偏好设置: 新增 autoRestartGameOnCrash 设置项,用于存储用户关于检测到崩溃时是否自动重启游戏的偏好。
  3. 界面集成: 在用户设置界面中添加了相应选项。
  4. 逻辑集成:
    • 更新 MaaToolClient,纳入新的崩溃检测逻辑,并在设置启用时启动游戏重启流程。
    • 更新 MAAViewModel,处理新设置的存储、检索和 UI 状态同步。

Summary by Sourcery

为 Arknights 添加 macOS 特定的崩溃检测功能,并在设置中启用时自动重启游戏。

新功能:

  • 引入 ProblemReporterScanner 工具,通过对 macOS “问题报告”窗口进行 OCR 来检测 Arknights 的崩溃。
  • 新增用户可配置选项,在检测到异常退出时允许自动重启游戏。

增强内容:

  • 将崩溃检测和可选的自动重启集成到 MaaToolClient 的连接处理以及游戏启动/停止流程中。
  • 使用 AppStorageMAAViewModel 中持久化新的“崩溃自动重启”偏好设置,并通过连接设置界面对其进行暴露;在启用时请求屏幕录制权限。
Original summary in English

Summary by Sourcery

Add macOS-specific crash detection for Arknights and automatically restart the game when enabled in settings.

New Features:

  • Introduce a ProblemReporterScanner utility that uses OCR on the macOS Problem Reporter window to detect Arknights crashes.
  • Add a user-configurable option to allow automatically restarting the game when an unexpected exit is detected.

Enhancements:

  • Integrate crash detection and optional auto-restart into MaaToolClient connection handling and the game start/stop flow.
  • Persist the new crash auto-restart preference in MAAViewModel using AppStorage and expose it via the connection settings UI, requesting screen recording access when enabled.

## **Summary**

This Pull Request introduces a new feature to detect **`Arknights`** game crashes on macOS using Optical Character Recognition (OCR) against the system's Problem Reporter window.

The core addition is the **`ProblemReporterScanner`**, which periodically checks the screen for the crash report window and uses OCR to confirm if the reported process is related to the game.

Alongside the detection logic, a new user preference is implemented: **`autoRestartGameOnCrash`**. When this setting is enabled and a crash is detected, the `MaaToolClient` logic is triggered to automatically restart the game, significantly improving the user experience during unattended operation.

This change provides a robust, platform-specific solution for high-fidelity crash detection, allowing the application to autonomously recover and continue operation, thus enhancing the overall stability and reliability of the automation tool.

### **Key Changes**

1.  **New Feature:** Introduced **`ProblemReporterScanner`** for macOS-specific crash detection using OCR on the Problem Reporter window.
2.  **User Preference:** Added new setting `autoRestartGameOnCrash` to store the user's preference for automatic game restart upon crash detection.
3.  **UI Integration:** Added a corresponding option to the user settings interface.
4.  **Logic Integration:**
    * Updated **`MaaToolClient`** to incorporate the new crash detection logic and initiate the game restart process when the setting is enabled.
    * Updated **`MAAViewModel`** to handle the new setting storage, retrieval, and UI state synchronization.
-----

-----

## **摘要**

本次拉取请求(PR)引入了一项新功能,通过对系统**“问题报告”**窗口执行光学字符识别(OCR),来检测 macOS 上的 **《明日方舟》** 游戏崩溃。

核心新增部分是 **`ProblemReporterScanner`**,它会周期性地检查屏幕上的崩溃报告窗口,并利用 OCR 确认报告的进程是否与游戏相关。

与检测逻辑同时,我们实现了一个新的用户偏好设置:**`autoRestartGameOnCrash`**。当此设置启用且检测到崩溃时,将触发 `MaaToolClient` 逻辑来自动重启游戏,从而显著改善无人值守操作期间的用户体验。

本次更改提供了一个健壮的、针对特定平台的解决方案,用于高精度的崩溃检测。它允许应用程序在检测到崩溃后自动恢复并继续运行,从而增强了自动化工具的整体稳定性和可靠性。

### **主要更改**

1.  **新功能:** 引入 **`ProblemReporterScanner`**,使用 OCR 技术对“问题报告”窗口进行扫描,实现 macOS 特有的崩溃检测。
2.  **用户偏好设置:** 新增 `autoRestartGameOnCrash` 设置项,用于存储用户关于检测到崩溃时是否自动重启游戏的偏好。
3.  **界面集成:** 在用户设置界面中添加了相应选项。
4.  **逻辑集成:**
    * 更新 **`MaaToolClient`**,纳入新的崩溃检测逻辑,并在设置启用时启动游戏重启流程。
    * 更新 **`MAAViewModel`**,处理新设置的存储、检索和 UI 状态同步。
@sourcery-ai
Copy link

sourcery-ai bot commented Dec 12, 2025

Reviewer's Guide

通过扫描系统“问题报告程序”窗口并进行 OCR,实现了 Arknights 在 macOS 上的崩溃检测与自动重启路径,将其接入 MaaToolClient 的连接处理流程,并在 MAAViewModel 中持久化为可由用户切换的设置,同时在连接设置 UI 中展示该选项。

File-Level Changes

Change Details Files
将崩溃检测/自动重启行为接入 MaaToolClient 的连接生命周期及其调用方。
  • 扩展 MaaToolClient 的初始化方法,新增 allowscanreporter 和 appBundle 参数,并在 MAAViewModel.startGame/stopGame 中更新调用点以传递这些参数
  • 修改 MaaToolClient 连接循环中的 .waiting 状态处理逻辑,可选地调用 ProblemReporterScanner.checkArknights 并重新打开 app bundle,而不是仅仅重启连接
  • 在禁用崩溃检测时,将连接重启的调度切回主 actor
MeoAsstMac/Core/MaaToolClient.swift
MeoAsstMac/Model/MAAViewModel.swift
持久化并暴露一个用户偏好设置,用于允许扫描 macOS 问题报告程序以自动重启游戏,包括 UI 和权限处理。
  • 在 MAAViewModel 中添加由 @AppStorage 支持的 Boolean 类型 allowscanreporter 用于持久化该偏好
  • 在 ConnectionSettingsView 中新增一个绑定到 allowscanreporter 的开关,并提供说明文案
  • 在启用该开关时,通过 CGRequestScreenCaptureAccess() 请求屏幕录制权限
MeoAsstMac/Model/MAAViewModel.swift
MeoAsstMac/Settings/ConnectionSettingsView.swift
Resources/Localizable.xcstrings
引入 ProblemReporterScanner 工具,用于查找 macOS 的问题报告程序窗口并对其进行 OCR,识别是否存在 “Arknights” 进程名称。
  • 实现一个静态的异步入口 checkArknights(),在分离的、user-initiated 的 Task 中执行截图和 OCR 工作
  • 使用 CGWindowListCopyWindowInfo 枚举屏幕上的窗口以定位所有者为“问题报告程序”的窗口,过滤掉很小的辅助窗口,并将其内容捕获为 CGImage
  • 使用 Vision VNRecognizeTextRequest 对捕获图像执行 OCR,并在识别出的字符串中进行不区分大小写的 “Arknights” 匹配
MeoAsstMac/Utils/ProblemReporterScanner.swift
MeoAsstMac.xcodeproj/project.pbxproj

Possibly linked issues

  • #游戏启动失败再次尝试打开逻辑: PR 实现了 ProblemReporterScanner 和相关开关,在检测到问题报告中 Arknights 崩溃时自动重启,与该 issue 的需求完全吻合。

Tips and commands

Interacting with Sourcery

  • Trigger a new review: 在 Pull Request 中评论 @sourcery-ai review 以触发新的代码审查。
  • Continue discussions: 直接回复 Sourcery 的审查评论以继续讨论。
  • Generate a GitHub issue from a review comment: 通过回复某条审查评论,要求 Sourcery 基于该评论创建一个 issue。你也可以回复该评论并写上 @sourcery-ai issue 来从中创建 issue。
  • Generate a pull request title: 在 Pull Request 标题中任意位置写上 @sourcery-ai,即可随时生成标题。你也可以在 Pull Request 中评论 @sourcery-ai title 来(重新)生成标题。
  • Generate a pull request summary: 在 Pull Request 正文任意位置写上 @sourcery-ai summary,即可在对应位置生成 PR 摘要。你也可以在 Pull Request 中评论 @sourcery-ai summary 来(重新)生成摘要。
  • Generate reviewer's guide: 在 Pull Request 中评论 @sourcery-ai guide,即可随时(重新)生成 Reviewer's Guide。
  • Resolve all Sourcery comments: 在 Pull Request 中评论 @sourcery-ai resolve,即可一次性标记已解决所有 Sourcery 评论。如果你已经处理了所有评论且不想再看到它们,这会很有用。
  • Dismiss all Sourcery reviews: 在 Pull Request 中评论 @sourcery-ai dismiss,即可关闭所有现有的 Sourcery 审查,尤其适合你想从头开始新的审查时 —— 记得再评论一次 @sourcery-ai review 来触发新审查!

Customizing Your Experience

访问你的 dashboard 以:

  • 启用或禁用诸如 Sourcery 生成的 Pull Request 摘要、Reviewer's Guide 等审查功能。
  • 更改审查语言。
  • 添加、移除或编辑自定义审查说明。
  • 调整其他审查相关设置。

Getting Help

Original review guide in English

Reviewer's Guide

Adds a macOS-specific crash detection and auto-restart path for Arknights by scanning the system Problem Reporter window via OCR, wiring it into MaaToolClient connection handling and exposing a user-toggleable setting persisted in MAAViewModel and surfaced in the connection settings UI.

File-Level Changes

Change Details Files
Wire crash-detection/auto-restart behavior into MaaToolClient connection lifecycle and its callers.
  • Extend MaaToolClient initializer to accept allowscanreporter and appBundle parameters and update call sites in MAAViewModel.startGame/stopGame to pass them through
  • Modify the .waiting state handling in MaaToolClient connection loop to optionally invoke ProblemReporterScanner.checkArknights and reopen the app bundle instead of simply restarting the connection
  • Dispatch connection restart back to the main actor when crash detection is disabled
MeoAsstMac/Core/MaaToolClient.swift
MeoAsstMac/Model/MAAViewModel.swift
Persist and expose a user preference to allow scanning the macOS Problem Reporter for auto-restarting the game, including UI and permissions.
  • Add an @AppStorage-backed allowscanreporter Boolean in MAAViewModel for persisting the preference
  • Add a new toggle in ConnectionSettingsView bound to allowscanreporter with explanatory copy
  • Request screen-capture access via CGRequestScreenCaptureAccess() when the toggle is enabled
MeoAsstMac/Model/MAAViewModel.swift
MeoAsstMac/Settings/ConnectionSettingsView.swift
Resources/Localizable.xcstrings
Introduce ProblemReporterScanner utility to find the macOS Problem Reporter window and OCR it for the "Arknights" process name.
  • Implement a static async checkArknights() entry point that runs capture and OCR work on a detached, user-initiated Task
  • Enumerate on-screen windows with CGWindowListCopyWindowInfo to locate the "问题报告程序" owner window, filter out tiny helper windows, and capture its contents as a CGImage
  • Use Vision VNRecognizeTextRequest to perform OCR on the captured image and check recognized strings for a case-insensitive match on "Arknights"
MeoAsstMac/Utils/ProblemReporterScanner.swift
MeoAsstMac.xcodeproj/project.pbxproj

Possibly linked issues

  • #游戏启动失败再次尝试打开逻辑: PR实现ProblemReporterScanner和开关,在检测到问题报告中Arknights崩溃时自动重启,正符合issue需求。

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

Copy link

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

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

你好,我已经审阅了你的改动,这里是一些反馈:

  • MaaToolClient.stateUpdateHandler 中,当 allowscanreporter 为 true 且 ProblemReporterScanner.checkArknights() 返回 false 时,不会调用 connection.restart(),因此客户端可能一直卡在 .waiting 状态;建议在未检测到崩溃窗口时,确保会重启连接。
  • .waiting 分支里的 Task { ... } 打破了现有的结构化流程,并将 actor 隔离与 MainActor.run 混合使用;你很可能可以把这段逻辑保留在 actor 上下文内(不再创建非结构化任务),直接 await 扫描器,然后按条件选择重启或重新拉起。
  • stopGame() 中,MaaToolClient 使用 allowscanreporter: allowscanreporter 和一个任意的 appBundle URL 进行初始化;如果这里只是为了终止游戏,建议传递 allowscanreporter: false,或者将终止逻辑与“崩溃后重启”的路径解耦,以避免误用无效的 bundle URL。
面向 AI Agent 的提示词
Please address the comments from this code review:

## Overall Comments
-`MaaToolClient.stateUpdateHandler` 中,当 `allowscanreporter` 为 true 且 `ProblemReporterScanner.checkArknights()` 返回 false 时,不会调用 `connection.restart()`,因此客户端可能一直卡在 `.waiting` 状态;建议在未检测到崩溃窗口时,确保会重启连接。
- `.waiting` 分支里的 `Task { ... }` 打破了现有的结构化流程,并将 actor 隔离与 `MainActor.run` 混合使用;你很可能可以把这段逻辑保留在 actor 上下文内(不再创建非结构化任务),直接 `await` 扫描器,然后按条件选择重启或重新拉起。
-`stopGame()` 中,`MaaToolClient` 使用 `allowscanreporter: allowscanreporter` 和一个任意的 `appBundle` URL 进行初始化;如果这里只是为了终止游戏,建议传递 `allowscanreporter: false`,或者将终止逻辑与“崩溃后重启”的路径解耦,以避免误用无效的 bundle URL。

## Individual Comments

### Comment 1
<location> `MeoAsstMac/Core/MaaToolClient.swift:54-63` </location>
<code_context>
                 try? await Task.sleep(for: .seconds(0.5))
-                connection.restart()
+                // 开启一个新的异步任务
+                Task {
+                    if allowscanreporter {
+                        let isFound = await ProblemReporterScanner.checkArknights()
+                        
+                        if isFound {
+                            print("成功!在【问题报告程序】中发现了 'Arknights'")
+                            try await NSWorkspace.shared.openApplication(at: appBundle, configuration: .init())
+                        }
+                    } else {
+                        await MainActor.run {
+                            self.connection.restart()
+                        }
</code_context>

<issue_to_address>
**issue (bug_risk):**`allowscanreporter` 为 true 且未检测到 `Arknights` 时,连接不会被重启。

在之前的逻辑中,`.waiting` 始终会导致调用 `connection.restart()`。现在,当 `allowscanreporter``true``checkArknights()` 返回 `false` 时,不会调用 `connection.restart()`,因此连接可能会无限期地停留在 `.waiting` 状态。请确保在 `allowscanreporter == true` 的路径中,当未找到 reporter 窗口或 OCR 不匹配时也会重启连接(例如,在 `!isFound` 分支中调用 `connection.restart()`)。
</issue_to_address>

### Comment 2
<location> `MeoAsstMac/Core/MaaToolClient.swift:63-64` </location>
<code_context>
+                            try await NSWorkspace.shared.openApplication(at: appBundle, configuration: .init())
+                        }
+                    } else {
+                        await MainActor.run {
+                            self.connection.restart()
+                        }
+                    }
</code_context>

<issue_to_address>
**issue (bug_risk):**`MainActor` 中重启 `NWConnection``MaaToolClient` 的 actor 隔离状态相冲突。

在 `Task {}` 内,你切换到 `MainActor` 去调用 `self.connection.restart()`,但 `connection` 是隔离在 `MaaToolClient` actor 内的。这样会破坏 actor 隔离,并带来并发问题风险。相反,应当直接在 actor 中调用 `await self.connection.restart()`,只在需要与 `restart()` 分离的 UI/主线程工作时才使用 `MainActor`。
</issue_to_address>

### Comment 3
<location> `MeoAsstMac/Model/MAAViewModel.swift:699` </location>
<code_context>

     func stopGame() async throws {
-        guard let client = await MaaToolClient(address: connectionAddress) else { return }
+        guard let client = await MaaToolClient(address: connectionAddress, allowscanreporter: allowscanreporter, appBundle: URL(fileURLWithPath: "/Users")) else { return }
         try await client.terminate()
     }
</code_context>

<issue_to_address>
**issue (bug_risk):** 在停止游戏时传入 `/Users` 作为 `appBundle` 不一致且可能导致意外的启动行为。

`startGame()` 会将真实的 `appBundle` 传给 `MaaToolClient`,但 `stopGame()` 现在使用的是 `URL(fileURLWithPath: "/Users")`。如果 `allowscanreporter` 为 true 且连接进入 `.waiting` 状态,客户端可能会使用这个无效的 bundle 调用 `openApplication(at: appBundle)`,从而引发错误或异常行为。对于停止逻辑,要么在两个路径中一致地传递正确的 bundle,要么在此路径中禁用 reporter 行为(例如使用 `allowscanreporter: false`)。
</issue_to_address>

Sourcery 对开源项目是免费的——如果你喜欢这次的代码审查,欢迎帮我们分享 ✨
帮我变得更有用!请在每条评论上点 👍 或 👎,我会根据你的反馈持续改进审查质量。
Original comment in English

Hey there - I've reviewed your changes - here's some feedback:

  • In MaaToolClient.stateUpdateHandler, when allowscanreporter is true and ProblemReporterScanner.checkArknights() returns false, connection.restart() is never called, so the client can remain stuck in the .waiting state; consider ensuring the connection is restarted when no crash window is detected.
  • The Task { ... } inside the .waiting case breaks the existing structured flow and mixes actor isolation with MainActor.run; you can likely keep this logic within the actor context (without spawning an unstructured task) by directly await-ing the scanner and then conditionally restarting or relaunching.
  • In stopGame(), MaaToolClient is initialized with allowscanreporter: allowscanreporter and an arbitrary appBundle URL; if the intent is only to terminate the game, consider passing allowscanreporter: false or otherwise decoupling termination logic from the restart-on-crash path to avoid accidentally using a bogus bundle URL.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- In `MaaToolClient.stateUpdateHandler`, when `allowscanreporter` is true and `ProblemReporterScanner.checkArknights()` returns false, `connection.restart()` is never called, so the client can remain stuck in the `.waiting` state; consider ensuring the connection is restarted when no crash window is detected.
- The `Task { ... }` inside the `.waiting` case breaks the existing structured flow and mixes actor isolation with `MainActor.run`; you can likely keep this logic within the actor context (without spawning an unstructured task) by directly `await`-ing the scanner and then conditionally restarting or relaunching.
- In `stopGame()`, `MaaToolClient` is initialized with `allowscanreporter: allowscanreporter` and an arbitrary `appBundle` URL; if the intent is only to terminate the game, consider passing `allowscanreporter: false` or otherwise decoupling termination logic from the restart-on-crash path to avoid accidentally using a bogus bundle URL.

## Individual Comments

### Comment 1
<location> `MeoAsstMac/Core/MaaToolClient.swift:54-63` </location>
<code_context>
                 try? await Task.sleep(for: .seconds(0.5))
-                connection.restart()
+                // 开启一个新的异步任务
+                Task {
+                    if allowscanreporter {
+                        let isFound = await ProblemReporterScanner.checkArknights()
+                        
+                        if isFound {
+                            print("成功!在【问题报告程序】中发现了 'Arknights'")
+                            try await NSWorkspace.shared.openApplication(at: appBundle, configuration: .init())
+                        }
+                    } else {
+                        await MainActor.run {
+                            self.connection.restart()
+                        }
</code_context>

<issue_to_address>
**issue (bug_risk):** When `allowscanreporter` is true and `Arknights` is not detected, the connection is never restarted.

In the previous logic, `.waiting` always led to `connection.restart()`. Now, when `allowscanreporter` is `true` and `checkArknights()` returns `false`, `connection.restart()` is never called, so the connection can remain in `.waiting` indefinitely. Please ensure the `allowscanreporter == true` path also restarts the connection when the reporter window is not found or OCR does not match (e.g., call `connection.restart()` in the `!isFound` case).
</issue_to_address>

### Comment 2
<location> `MeoAsstMac/Core/MaaToolClient.swift:63-64` </location>
<code_context>
+                            try await NSWorkspace.shared.openApplication(at: appBundle, configuration: .init())
+                        }
+                    } else {
+                        await MainActor.run {
+                            self.connection.restart()
+                        }
+                    }
</code_context>

<issue_to_address>
**issue (bug_risk):** Restarting the `NWConnection` from `MainActor` conflicts with the actor-isolated `MaaToolClient` state.

Inside `Task {}` you switch to `MainActor` to call `self.connection.restart()`, but `connection` is isolated to the `MaaToolClient` actor. This violates actor isolation and risks concurrency issues. Instead, call `await self.connection.restart()` directly from the actor, and only use `MainActor` for UI/main-thread work that must be separate from `restart()`.
</issue_to_address>

### Comment 3
<location> `MeoAsstMac/Model/MAAViewModel.swift:699` </location>
<code_context>

     func stopGame() async throws {
-        guard let client = await MaaToolClient(address: connectionAddress) else { return }
+        guard let client = await MaaToolClient(address: connectionAddress, allowscanreporter: allowscanreporter, appBundle: URL(fileURLWithPath: "/Users")) else { return }
         try await client.terminate()
     }
</code_context>

<issue_to_address>
**issue (bug_risk):** Passing `/Users` as the `appBundle` when stopping the game is inconsistent and may cause unintended launches.

`startGame()` passes the real `appBundle` to `MaaToolClient`, but `stopGame()` now uses `URL(fileURLWithPath: "/Users")`. If `allowscanreporter` is true and the connection enters `.waiting`, the client may call `openApplication(at: appBundle)` with this invalid bundle, causing an error or unintended behavior. For stopping, either pass the correct bundle consistently or disable the reporter behavior in this path (e.g. `allowscanreporter: false`).
</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.

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