Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion docs/articles/overview-of-wrapper-and-api.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@
| AdbInputMethods | `MaaAdbInputMethod` |
| Win32ScreencapMethod | `MaaWin32ScreencapMethod` |
| Win32InputMethod | `MaaWin32InputMethod` |
| DbgControllerType | `MaaDbgControllerType` |
| MacOSScreencapMethod | `MaaMacOSScreencapMethod` |
| MacOSInputMethod | `MaaMacOSInputMethod` |
| MacOSPermission | `MaaMacOSPermissionEnum` |
| GamepadType | `MaaGamepadType` |
| GamepadButton | `MaaGamepadButton` |
| GamepadTouch | `MaaGamepadTouch` |
Expand Down Expand Up @@ -87,8 +89,12 @@ IMaaDisposable Derived:
| --- | --- |
| MaaAdbController.ctor() | `MaaAdbControllerCreate` <br> `MaaControllerAddSink` |
| MaaWin32Controller.ctor() | `MaaWin32ControllerCreate` <br> `MaaControllerAddSink` |
| MaaMacOSController.ctor() | `MaaMacOSControllerCreate` <br> `MaaControllerAddSink` |
| MaaAndroidNativeController.ctor() | `MaaAndroidNativeControllerCreate` <br> `MaaControllerAddSink` |
| MaaCustomController.ctor() | `MaaCustomControllerCreate` <br> `MaaControllerAddSink` |
| MaaDbgController.ctor() | `MaaDbgControllerCreate` <br> `MaaControllerAddSink` |
| MaaReplayController.ctor() | `MaaReplayControllerCreate` <br> `MaaControllerAddSink` |
| MaaRecordController.ctor() | `MaaRecordControllerCreate` <br> `MaaControllerAddSink` |
| MaaPlayCoverController.ctor() | `MaaPlayCoverControllerCreate` <br> `MaaControllerAddSink` |
| MaaGamepadController.ctor() | `MaaGamepadControllerCreate` <br> `MaaControllerAddSink` |
| MaaWlRootsController.ctor() | `MaaWlRootsControllerCreate` <br> `MaaControllerAddSink` |
Expand All @@ -104,6 +110,7 @@ IMaaDisposable Derived:
| IMaaController.TouchDown() | `MaaControllerPostTouchDown` |
| IMaaController.TouchMove() | `MaaControllerPostTouchMove` |
| IMaaController.TouchUp() | `MaaControllerPostTouchUp` |
| IMaaController.RelativeMove() | `MaaControllerPostRelativeMove` |
| IMaaController.Screencap() | `MaaControllerPostScreencap` |
| IMaaController.Scroll() | `MaaControllerPostScroll` |
| IMaaController.Inactive() | `MaaControllerPostInactive` |
Expand Down Expand Up @@ -312,6 +319,9 @@ IMaaDisposable Derived:
| MaaToolkit.ctor() <br> IMaaToolkit.Config.InitOption() | `MaaToolkitConfigInitOption` |
| IMaaToolkit.AdbDevice.Find() <br> IMaaToolkit.AdbDevice.FindAsync() | `MaaToolkitAdbDeviceFind` <br> `MaaToolkitAdbDeviceFindSpecified` |
| IMaaToolkit.Desktop.Window.Find() | `MaaToolkitDesktopWindowFindAll` |
| IMaaToolkit.MacOS.CheckPermission() | `MaaToolkitMacOSCheckPermission` |
| IMaaToolkit.MacOS.RequestPermission() | `MaaToolkitMacOSRequestPermission` |
| IMaaToolkit.MacOS.RevealPermissionSettings() | `MaaToolkitMacOSRevealPermissionSettings` |

## Buffers.AdbDeviceListBuffer : Buffers.MaaListBuffer : Buffers.IMaaListBuffer

Expand Down
109 changes: 79 additions & 30 deletions src/MaaFramework.Binding.Extensions/Notification/NotificationDetail.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,53 +3,71 @@

namespace MaaFramework.Binding.Notification;

/// <inheritdoc cref="MaaMsg.Resource.Loading.Prefix"/>
#pragma warning disable CS1591 // 缺少对公共可见类型或成员的 XML 注释

/// <inheritdoc cref="MaaMsg.Resource.Loading"/>
public enum ResourcePathType
{
Bundle,
OcrModel,
Pipeline,
Image,

Unknown = -1
}

/// <inheritdoc cref="MaaMsg.Resource.Loading"/>
public record ResourceLoadingDetail(
[property: JsonPropertyName("res_id")] int ResourceId,
[property: JsonPropertyName("res_id")] long ResourceId,
[property: JsonPropertyName("path")] string Path,
[property: JsonPropertyName("type")] string Type,
[property: JsonPropertyName("hash")] string Hash
);
)
{
// 1. .NET 7 没有支持 aot 的 JsonStringEnumConverter<TEnum>
// 2. Unknown 向前兼容,使用 JsonStringEnumConverter 还需要设置 option 并且将 Unknown 设置为默认值 0
[JsonIgnore] public ResourcePathType ParsedType => Enum.TryParse<ResourcePathType>(Type, true, out var result) ? result : ResourcePathType.Unknown;
};

/// <inheritdoc cref="MaaMsg.Controller.Action.Prefix"/>
/// <inheritdoc cref="MaaMsg.Controller.Action"/>
public record ControllerActionDetail(
[property: JsonPropertyName("ctrl_id")] int ControllerId,
[property: JsonPropertyName("ctrl_id")] long ControllerId,
[property: JsonPropertyName("uuid")] string Uuid,
[property: JsonPropertyName("action")] string Action,
[property: JsonPropertyName("param")] JsonElement Param,
[property: JsonPropertyName("info")] JsonElement Info
);

/// <inheritdoc cref="MaaMsg.Tasker.Task.Prefix"/>
/// <inheritdoc cref="MaaMsg.Tasker.Task"/>
public record TaskerTaskDetail(
[property: JsonPropertyName("task_id")] int TaskId,
[property: JsonPropertyName("task_id")] long TaskId,
[property: JsonPropertyName("entry")] string Entry,
[property: JsonPropertyName("uuid")] string Uuid,
[property: JsonPropertyName("hash")] string Hash
);

/// <inheritdoc cref="MaaMsg.Node.PipelineNode.Prefix"/>
/// <inheritdoc cref="MaaMsg.Node.PipelineNode"/>
public record PipelineNodeDetail(
[property: JsonPropertyName("task_id")] int TaskId,
[property: JsonPropertyName("node_id")] int NodeId,
[property: JsonPropertyName("task_id")] long TaskId,
[property: JsonPropertyName("node_id")] long NodeId,
[property: JsonPropertyName("name")] string Name,
[property: JsonPropertyName("focus")] JsonElement? Focus
[property: JsonPropertyName("focus")] JsonElement Focus
);

/// <inheritdoc cref="MaaMsg.Node.RecognitionNode.Prefix"/>
/// <inheritdoc cref="MaaMsg.Node.RecognitionNode"/>
public record RecognitionNodeDetail(
[property: JsonPropertyName("task_id")] int TaskId,
[property: JsonPropertyName("node_id")] int NodeId,
[property: JsonPropertyName("task_id")] long TaskId,
[property: JsonPropertyName("node_id")] long NodeId,
[property: JsonPropertyName("name")] string Name,
[property: JsonPropertyName("focus")] JsonElement? Focus
[property: JsonPropertyName("focus")] JsonElement Focus
);

/// <inheritdoc cref="MaaMsg.Node.ActionNode.Prefix"/>
/// <inheritdoc cref="MaaMsg.Node.ActionNode"/>
public record ActionNodeDetail(
[property: JsonPropertyName("task_id")] int TaskId,
[property: JsonPropertyName("node_id")] int NodeId,
[property: JsonPropertyName("task_id")] long TaskId,
[property: JsonPropertyName("node_id")] long NodeId,
[property: JsonPropertyName("name")] string Name,
[property: JsonPropertyName("focus")] JsonElement? Focus
[property: JsonPropertyName("focus")] JsonElement Focus
);

/// <summary>
Expand All @@ -61,26 +79,57 @@ public record NodeAttr(
[property: JsonPropertyName("anchor")] bool Anchor
);

/// <inheritdoc cref="MaaMsg.Node.NextList.Prefix"/>
/// <inheritdoc cref="MaaMsg.Node.NextList"/>
public record NodeNextListDetail(
[property: JsonPropertyName("task_id")] int TaskId,
[property: JsonPropertyName("task_id")] long TaskId,
[property: JsonPropertyName("name")] string Name,
[property: JsonPropertyName("list")] IReadOnlyList<NodeAttr> NextList,
[property: JsonPropertyName("focus")] JsonElement? Focus
[property: JsonPropertyName("focus")] JsonElement Focus
);

/// <inheritdoc cref="MaaMsg.Node.Recognition.Prefix"/>
/// <inheritdoc cref="MaaMsg.Node.Recognition"/>
public record NodeRecognitionDetail(
[property: JsonPropertyName("task_id")] int TaskId,
[property: JsonPropertyName("reco_id")] int RecognitionId,
[property: JsonPropertyName("task_id")] long TaskId,
[property: JsonPropertyName("reco_id")] long RecognitionId,
[property: JsonPropertyName("name")] string Name,
[property: JsonPropertyName("focus")] JsonElement? Focus
[property: JsonPropertyName("focus")] JsonElement Focus,
[property: JsonPropertyName("anchor")] string? Anchor
);

/// <inheritdoc cref="MaaMsg.Node.Action.Prefix"/>
/// <inheritdoc cref="MaaMsg.Node.Action"/>
public record NodeActionDetail(
[property: JsonPropertyName("task_id")] int TaskId,
[property: JsonPropertyName("action_id")] int ActionId,
[property: JsonPropertyName("task_id")] long TaskId,
[property: JsonPropertyName("action_id")] long ActionId,
[property: JsonPropertyName("name")] string Name,
[property: JsonPropertyName("focus")] JsonElement? Focus
[property: JsonPropertyName("focus")] JsonElement Focus
);

public record WaitFreezesParam(
[property: JsonPropertyName("time")] long MillisecondsTime,
[property: JsonPropertyName("threshold")] double Threshold,
[property: JsonPropertyName("method")] int Method,
[property: JsonPropertyName("rate_limit")] long MillisecondsRateLimit,
[property: JsonPropertyName("timeout")] long MillisecondsTimeout
)
{
[JsonIgnore] public TimeSpan Time => TimeSpan.FromMilliseconds(MillisecondsTime);
[JsonIgnore] public TimeSpan RateLimit => TimeSpan.FromMilliseconds(MillisecondsRateLimit);
[JsonIgnore] public TimeSpan Timeout => TimeSpan.FromMilliseconds(MillisecondsTimeout);
}

/// <inheritdoc cref="MaaMsg.Node.WaitFreezes"/>
public record NodeWaitFreezesDetail(
[property: JsonPropertyName("task_id")] long TaskId,
[property: JsonPropertyName("wf_id")] long WaitFreezesId,
[property: JsonPropertyName("name")] string Name,
[property: JsonPropertyName("phase")] string Phase,
[property: JsonPropertyName("roi")] IReadOnlyList<int> Roi,
[property: JsonPropertyName("param")] WaitFreezesParam Param,
[property: JsonPropertyName("reco_ids")] IReadOnlyList<long>? RecognitionIds,
[property: JsonPropertyName("elapsed")] long? MillisecondsElapsed,
[property: JsonPropertyName("focus")] JsonElement Focus
// https://github.com/MaaXYZ/MaaFramework/blob/v5.10.5/source/MaaFramework/Task/Component/ActionHelper.cpp#L46
)
{
[JsonIgnore] public TimeSpan? Elapsed => MillisecondsElapsed.HasValue ? TimeSpan.FromMilliseconds(MillisecondsElapsed.Value) : null;
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,9 @@ namespace MaaFramework.Binding.Notification;
[JsonSerializable(typeof(PipelineNodeDetail))]
[JsonSerializable(typeof(RecognitionNodeDetail))]
[JsonSerializable(typeof(ActionNodeDetail))]
[JsonSerializable(typeof(NodeAttr))]
[JsonSerializable(typeof(NodeNextListDetail))]
[JsonSerializable(typeof(NodeRecognitionDetail))]
[JsonSerializable(typeof(NodeActionDetail))]
[JsonSerializable(typeof(NodeWaitFreezesDetail))]
[JsonSerializable(typeof(string))]
public partial class NotificationDetailContext : JsonSerializerContext;
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,18 @@ public static EventHandler<MaaCallbackEventArgs> ToCallback<TContext>(this Notif
public static EventHandler<MaaCallbackEventArgs> ToCallback<TContext>(this NotificationHandler<TaskerTaskDetail, TContext> notify) where TContext : IMaaTasker
=> notify.ToCallback(MaaMsg.Tasker.Task.Prefix);

/// <inheritdoc cref="ToCallback{TDetail, TContext}"/>
public static EventHandler<MaaCallbackEventArgs> ToCallback<TContext>(this NotificationHandler<PipelineNodeDetail, TContext> notify) where TContext : IMaaContext
=> notify.ToCallback(MaaMsg.Node.PipelineNode.Prefix);

/// <inheritdoc cref="ToCallback{TDetail, TContext}"/>
public static EventHandler<MaaCallbackEventArgs> ToCallback<TContext>(this NotificationHandler<RecognitionNodeDetail, TContext> notify) where TContext : IMaaContext
=> notify.ToCallback(MaaMsg.Node.RecognitionNode.Prefix);

/// <inheritdoc cref="ToCallback{TDetail, TContext}"/>
public static EventHandler<MaaCallbackEventArgs> ToCallback<TContext>(this NotificationHandler<ActionNodeDetail, TContext> notify) where TContext : IMaaContext
=> notify.ToCallback(MaaMsg.Node.ActionNode.Prefix);

/// <inheritdoc cref="ToCallback{TDetail, TContext}"/>
public static EventHandler<MaaCallbackEventArgs> ToCallback<TContext>(this NotificationHandler<NodeNextListDetail, TContext> notify) where TContext : IMaaContext
=> notify.ToCallback(MaaMsg.Node.NextList.Prefix);
Expand All @@ -113,15 +125,7 @@ public static EventHandler<MaaCallbackEventArgs> ToCallback<TContext>(this Notif
=> notify.ToCallback(MaaMsg.Node.Action.Prefix);

/// <inheritdoc cref="ToCallback{TDetail, TContext}"/>
public static EventHandler<MaaCallbackEventArgs> ToCallback<TContext>(this NotificationHandler<PipelineNodeDetail, TContext> notify) where TContext : IMaaContext
=> notify.ToCallback(MaaMsg.Node.PipelineNode.Prefix);

/// <inheritdoc cref="ToCallback{TDetail, TContext}"/>
public static EventHandler<MaaCallbackEventArgs> ToCallback<TContext>(this NotificationHandler<RecognitionNodeDetail, TContext> notify) where TContext : IMaaContext
=> notify.ToCallback(MaaMsg.Node.RecognitionNode.Prefix);

/// <inheritdoc cref="ToCallback{TDetail, TContext}"/>
public static EventHandler<MaaCallbackEventArgs> ToCallback<TContext>(this NotificationHandler<ActionNodeDetail, TContext> notify) where TContext : IMaaContext
=> notify.ToCallback(MaaMsg.Node.ActionNode.Prefix);
public static EventHandler<MaaCallbackEventArgs> ToCallback<TContext>(this NotificationHandler<NodeWaitFreezesDetail, TContext> notify) where TContext : IMaaContext
=> notify.ToCallback(MaaMsg.Node.WaitFreezes.Prefix);
}

Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,20 @@ internal void OnFailed(object? sender, string details) => Failed?.Invoke(sender,
NotificationDetailContext.Default.NodeActionDetail) ?? throw new InvalidCastException());
}

public WaitFreezesRegistry WaitFreezes { get; } = new();
public sealed class WaitFreezesRegistry
{
public event EventHandler<NodeWaitFreezesDetail>? Starting;
internal void OnStarting(object? sender, string details) => Starting?.Invoke(sender, JsonSerializer.Deserialize(details,
NotificationDetailContext.Default.NodeWaitFreezesDetail) ?? throw new InvalidCastException());
public event EventHandler<NodeWaitFreezesDetail>? Succeeded;
internal void OnSucceeded(object? sender, string details) => Succeeded?.Invoke(sender, JsonSerializer.Deserialize(details,
NotificationDetailContext.Default.NodeWaitFreezesDetail) ?? throw new InvalidCastException());
public event EventHandler<NodeWaitFreezesDetail>? Failed;
internal void OnFailed(object? sender, string details) => Failed?.Invoke(sender, JsonSerializer.Deserialize(details,
NotificationDetailContext.Default.NodeWaitFreezesDetail) ?? throw new InvalidCastException());
}

}

}
}
6 changes: 5 additions & 1 deletion src/MaaFramework.Binding.Extensions/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,13 @@ Supported TDetail types:
- ResourceLoadingDetail
- ControllerActionDetail
- TaskerTaskDetail
- PipelineNodeDetail
- RecognitionNodeDetail
- ActionNodeDetail
- NodeNextListDetail
- NodeRecognitionDetail
- NodeActionDetail
- NodeWaitFreezesDetail
- string

Usage example:
Expand All @@ -82,4 +86,4 @@ NotificationHandler<ResourceLoadingDetail> OnResourceLoading = (type, detail) =>
}
};
maa.Callback += OnResourceLoading.ToCallback();
```
```
4 changes: 4 additions & 0 deletions src/MaaFramework.Binding.Extensions/README.zh_cn.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,13 @@ TDetail 为以下类型:
- ResourceLoadingDetail
- ControllerActionDetail
- TaskerTaskDetail
- PipelineNodeDetail
- RecognitionNodeDetail
- ActionNodeDetail
- NodeNextListDetail
- NodeRecognitionDetail
- NodeActionDetail
- NodeWaitFreezesDetail
- string

使用示例:
Expand Down
Loading
Loading