Skip to content

Add missing C# bindings to match MaaFramework C API#27

Draft
Copilot wants to merge 1 commit intomainfrom
copilot/fix-cs-binding-issues
Draft

Add missing C# bindings to match MaaFramework C API#27
Copilot wants to merge 1 commit intomainfrom
copilot/fix-cs-binding-issues

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Apr 13, 2026

Audit of MaaFramework/include headers against the C# binding, filling all gaps.

New controller types

  • MaaMacOSController — wraps MaaMacOSControllerCreate(window_id, screencap_method, input_method)
  • MaaAndroidNativeController — wraps MaaAndroidNativeControllerCreate(config_json)
  • MaaReplayController — wraps MaaReplayControllerCreate(recording_path)
  • MaaRecordController — wraps MaaRecordControllerCreate(inner, recording_path)

Updated MaaDbgController

MaaDbgControllerCreate signature changed upstream from 4 params (readPath, writePath, type, config) to 1 param (readPath). Updated P/Invoke and wrapper accordingly.

New controller action

  • MaaControllerPostRelativeMove(ctrl, dx, dy) exposed as IMaaController.RelativeMove(int dx, int dy)

New tasker query

  • MaaTaskerGetWaitFreezesDetail exposed as IMaaTasker.GetWaitFreezesDetail(...) with the same two-pass size-query pattern used by GetTaskDetail

macOS toolkit

  • P/Invoke for MaaToolkitMacOSCheckPermission, MaaToolkitMacOSRequestPermission, MaaToolkitMacOSRevealPermissionSettings
  • IMaaToolkitMacOS interface + implementation on MaaToolkit.MacOS

New enums & type aliases

  • MacOSScreencapMethod, MacOSInputMethod, MacOSPermission enums
  • MaaWfId, MaaMacOSScreencapMethod, MaaMacOSInputMethod, MaaMacOSPermission global using aliases

New MaaMsg entries

  • MaaMsg.Node.WaitFreezes.{Starting,Prefix,Succeeded,Failed}

Usage example

// macOS controller
using var ctrl = new MaaMacOSController(
    windowId: 0,
    screencapMethod: MacOSScreencapMethod.ScreenCaptureKit,
    inputMethod: MacOSInputMethod.GlobalEvent);

// Record + replay
using var record = new MaaRecordController(innerCtrl, "recording.jsonl");
using var replay = new MaaReplayController("recording.jsonl");

// Relative move
ctrl.RelativeMove(dx: 10, dy: -5);

// macOS permissions
bool granted = tasker.Toolkit.MacOS.CheckPermission(MacOSPermission.ScreenCapture);

Summary by Sourcery

通过添加缺失的控制器类型、任务器查询、macOS 工具包绑定以及相关枚举/消息,使 C# 绑定与最新的 MaaFramework C API 保持一致。

新功能:

  • 通过新的 C# 包装类和互操作绑定,暴露调试、macOS、Android 原生、录制和回放控制器。
  • IMaaController 中添加 RelativeMove 控制器动作,以相对偏移量移动指针。
  • IMaaTasker 中引入 GetWaitFreezesDetail,通过原生 MaaTaskerGetWaitFreezesDetail API 获取等待冻结(wait-freeze)诊断信息。
  • 通过 IMaaToolkit.MacOS 和原生 MaaToolkitMacOS P/Invoke 绑定,暴露 macOS 工具包权限辅助方法。
  • 添加 macOS 特定的屏幕捕获方式、输入方式和权限相关枚举,并在托管绑定中增加对 MaaWfId 的支持。
  • 扩展 MaaMsg,增加 Node.WaitFreezes 消息常量,用于等待冻结生命周期事件。

增强:

  • 更新 MaaDbgController 以匹配简化后的原生 MaaDbgControllerCreate 函数签名,并精简其托管包装实现。
Original summary in English

Summary by Sourcery

Align C# bindings with the latest MaaFramework C API by adding missing controller types, tasker queries, macOS toolkit bindings, and associated enums/messages.

New Features:

  • Expose debug, macOS, Android native, record, and replay controllers via new C# wrapper classes and interop bindings.
  • Add a RelativeMove controller action to move the pointer by relative offsets through IMaaController.
  • Introduce GetWaitFreezesDetail on IMaaTasker to retrieve wait-freeze diagnostics using the native MaaTaskerGetWaitFreezesDetail API.
  • Expose macOS toolkit permission helpers via IMaaToolkit.MacOS and native MaaToolkitMacOS P/Invoke bindings.
  • Add macOS-specific enums for screencap methods, input methods, and permissions, plus MaaWfId support in the managed bindings.
  • Extend MaaMsg with Node.WaitFreezes message constants for wait-freeze lifecycle events.

Enhancements:

  • Update MaaDbgController to match the simplified MaaDbgControllerCreate native signature and streamline its managed wrapper.

- Add MaaMacOSControllerCreate, MaaAndroidNativeControllerCreate,
  MaaReplayControllerCreate, MaaRecordControllerCreate P/Invoke
- Add MaaControllerPostRelativeMove P/Invoke
- Add MaaTaskerGetWaitFreezesDetail P/Invoke
- Add MaaToolkitMacOS P/Invoke (CheckPermission, RequestPermission,
  RevealPermissionSettings)
- Update MaaDbgControllerCreate to new 1-param signature
- Add MaaMacOSController, MaaAndroidNativeController,
  MaaReplayController, MaaRecordController wrapper classes
- Update MaaDbgController wrapper for new API
- Add RelativeMove to IMaaController/MaaController
- Add GetWaitFreezesDetail to IMaaTasker/MaaTasker
- Add MacOSScreencapMethod, MacOSInputMethod, MacOSPermission enums
- Add MaaWfId type alias
- Add IMaaToolkitMacOS interface and implementation
- Add Node.WaitFreezes messages to MaaMsg

Agent-Logs-Url: https://github.com/MaaXYZ/MaaFramework.Binding.CSharp/sessions/201d767e-cec0-4888-b09f-8b7a74837c9a

Co-authored-by: MistEO <18511905+MistEO@users.noreply.github.com>
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR updates the C# binding layer to close gaps with the upstream MaaFramework C API, adding new controller/toolkit bindings and extending the controller/tasker interfaces accordingly.

Changes:

  • Added new controller wrappers (macOS, Android native, record/replay) and updated MaaDbgControllerCreate to the new 1-parameter signature.
  • Exposed new controller action RelativeMove(dx, dy) and added tasker query GetWaitFreezesDetail(...) using the existing two-pass size query pattern.
  • Added macOS toolkit permission APIs (CheckPermission, RequestPermission, RevealPermissionSettings), enums/type aliases, and new MaaMsg entries for WaitFreezes notifications.

Reviewed changes

Copilot reviewed 21 out of 21 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
src/MaaFramework.Binding/MaaMsg.cs Adds MaaMsg.Node.WaitFreezes.* message constants.
src/MaaFramework.Binding/MaaDef.cs Introduces MaaWfId type alias for wait-freezes IDs.
src/MaaFramework.Binding/IMaaToolkit.cs Extends toolkit API with MacOS property and new IMaaToolkitMacOS interface.
src/MaaFramework.Binding/IMaaTasker.cs Adds GetWaitFreezesDetail to the tasker interface.
src/MaaFramework.Binding/IMaaController.cs Adds RelativeMove(dx, dy) to the controller interface.
src/MaaFramework.Binding/Enums/Controllers/MacOSScreencapMethod.cs Adds macOS screencap method enum for the new controller.
src/MaaFramework.Binding/Enums/Controllers/MacOSPermission.cs Adds macOS permission enum for toolkit permission APIs.
src/MaaFramework.Binding/Enums/Controllers/MacOSInputMethod.cs Adds macOS input method flags enum for the new controller.
src/MaaFramework.Binding.Native/MaaToolkit.cs Implements IMaaToolkit.MacOS via MacOSClass calling new toolkit P/Invokes.
src/MaaFramework.Binding.Native/MaaTasker.cs Implements GetWaitFreezesDetail wrapper over the new P/Invoke.
src/MaaFramework.Binding.Native/MaaController/MaaReplayController.cs New replay controller wrapper over MaaReplayControllerCreate.
src/MaaFramework.Binding.Native/MaaController/MaaRecordController.cs New record controller wrapper over MaaRecordControllerCreate.
src/MaaFramework.Binding.Native/MaaController/MaaMacOSController.cs New macOS controller wrapper over MaaMacOSControllerCreate.
src/MaaFramework.Binding.Native/MaaController/MaaDbgController.cs Updates managed wrapper to match new MaaDbgControllerCreate(readPath) signature.
src/MaaFramework.Binding.Native/MaaController/MaaAndroidNativeController.cs New Android native controller wrapper over MaaAndroidNativeControllerCreate.
src/MaaFramework.Binding.Native/MaaController.cs Implements IMaaController.RelativeMove via MaaControllerPostRelativeMove.
src/MaaFramework.Binding.Native/Interop/Toolkit/MacOS/MaaToolkitMacOS.cs Adds MaaToolkit macOS permission P/Invokes.
src/MaaFramework.Binding.Native/Interop/Toolkit/MaaToolkitDef.cs Adds MaaMacOSPermission interop alias.
src/MaaFramework.Binding.Native/Interop/Framework/MaaDef.cs Adds macOS controller interop aliases and MaaWfId.
src/MaaFramework.Binding.Native/Interop/Framework/Instance/MaaTasker.cs Adds MaaTaskerGetWaitFreezesDetail P/Invoke signature.
src/MaaFramework.Binding.Native/Interop/Framework/Instance/MaaController.cs Adds new controller factory P/Invokes and MaaControllerPostRelativeMove; updates dbg factory signature.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines 22 to +29
/// Gets the MaaToolkit Desktop.
/// </summary>
IMaaToolkitDesktop Desktop { get; }

/// <summary>
/// Gets the MaaToolkit macOS helper.
/// </summary>
IMaaToolkitMacOS MacOS { get; }
Copy link

Copilot AI Apr 13, 2026

Choose a reason for hiding this comment

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

Adding a new member to the public IMaaToolkit interface is a source/binary breaking change for any downstream implementations. If maintaining compatibility is a goal, consider introducing a new derived interface (e.g., IMaaToolkitV2) or using a default interface implementation for MacOS (e.g., throwing PlatformNotSupportedException) so existing implementers don’t break.

Copilot uses AI. Check for mistakes.
/// <param name="dx">The relative horizontal offset.</param>
/// <param name="dy">The relative vertical offset.</param>
/// <returns>A relative move <see cref="MaaJob"/>.</returns>
MaaJob RelativeMove(int dx, int dy);
Copy link

Copilot AI Apr 13, 2026

Choose a reason for hiding this comment

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

Adding RelativeMove to the public IMaaController interface is a breaking change for any external IMaaController implementations. If compatibility matters, consider a default interface implementation (e.g., throw NotSupportedException) or introducing a new derived interface so existing implementers continue to compile/run.

Suggested change
MaaJob RelativeMove(int dx, int dy);
MaaJob RelativeMove(int dx, int dy)
{
throw new global::System.NotSupportedException("RelativeMove is not supported by this controller implementation.");
}

Copilot uses AI. Check for mistakes.
/// <param name="recoIdList">The recognition id list.</param>
/// <param name="roi">The region of interest.</param>
/// <returns><see langword="true"/> if query was successful; otherwise, <see langword="false"/>.</returns>
bool GetWaitFreezesDetail(MaaWfId wfId, out string nodeName, out string phase, out bool isSucceeded, out ulong elapsedMs, out MaaRecoId[] recoIdList, IMaaRectBuffer? roi);
Copy link

Copilot AI Apr 13, 2026

Choose a reason for hiding this comment

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

Adding GetWaitFreezesDetail to the public IMaaTasker interface is a breaking change for any external IMaaTasker implementations. If compatibility is important, consider a default interface implementation or introducing a new derived interface (and having MaaTasker implement it) to avoid forcing downstream recompilation.

Suggested change
bool GetWaitFreezesDetail(MaaWfId wfId, out string nodeName, out string phase, out bool isSucceeded, out ulong elapsedMs, out MaaRecoId[] recoIdList, IMaaRectBuffer? roi);
bool GetWaitFreezesDetail(MaaWfId wfId, out string nodeName, out string phase, out bool isSucceeded, out ulong elapsedMs, out MaaRecoId[] recoIdList, IMaaRectBuffer? roi)
{
nodeName = string.Empty;
phase = string.Empty;
isSucceeded = false;
elapsedMs = 0;
recoIdList = System.Array.Empty<MaaRecoId>();
return false;
}

Copilot uses AI. Check for mistakes.
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.

3 participants