Files
daluandou/.codely.packages/cn.tuanjie.codely.bridge@1.0.85-47f31100/Editor/Bridge/Tools/ManageDialog.cs
T
huadexuan 13d0c80335 ```
chore(bridge): 删除桥接包的提交记录和Git属性配置

删除了 .codely-bridge-commit 文件中存储的提交哈希值
移除了 .gitattributes 文件中的行结束符配置规则
```
2026-09-24 21:41:14 +08:00

51 lines
2.2 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
using System;
using System.Collections.Generic;
using Codely.Newtonsoft.Json.Linq;
using UnityTcp.Editor.Helpers;
namespace UnityTcp.Editor.Tools
{
/// <summary>
/// <c>manage_dialog</c>: clicks a button on a native modal editor dialog.
///
/// Single action:
/// click – Params: button (regex over button labels), optional title (regex over dialog
/// titles). Clicks the first open modal dialog whose title/button match.
///
/// The command runs on the <see cref="BackgroundCommandPump"/> worker thread, which is the
/// point: a native modal dialog holds the editor main thread captive inside its message
/// pump, so this is the only way a client can answer one. The click itself is thread-safe
/// on Windows (Win32 cross-thread post); on macOS <see cref="DialogWatcher"/> marshals
/// it onto the common-modes run-loop probe, which keeps firing on the main thread even
/// during a modal session.
///
/// When such a dialog is detected, <see cref="DialogWatcher"/> detaches every
/// in-flight job with a reason that names the dialog and its buttons and points at this
/// command — the client picks a button, clicks it here, and then collects the detached
/// jobs' results via <c>manage_job.status</c>.
/// </summary>
public static class ManageDialog
{
private static readonly Dictionary<string, Func<JObject, object>> ActionHandlers =
new Dictionary<string, Func<JObject, object>>
{
{ "click", Click },
};
public static object HandleCommand(JObject @params)
=> ActionRouter.Route(@params, ActionHandlers);
private static object Click(JObject @params)
{
string button = @params["button"]?.ToString();
string title = @params["title"]?.ToString();
string failure = DialogWatcher.ClickOpenDialog(title, button,
out string clickedTitle, out string clickedButton);
return failure != null
? Response.Error(failure)
: Response.Success($"Clicked '{clickedButton}' on dialog '{clickedTitle}'.");
}
}
}