feat: add csharp win helper probe
This commit is contained in:
88
native/ISphereWinHelper/Program.cs
Normal file
88
native/ISphereWinHelper/Program.cs
Normal file
@@ -0,0 +1,88 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
|
||||
namespace ISphereWinHelper
|
||||
{
|
||||
internal static class Program
|
||||
{
|
||||
[STAThread]
|
||||
private static int Main(string[] args)
|
||||
{
|
||||
string requestText = Console.In.ReadToEnd();
|
||||
Dictionary<string, object> request;
|
||||
string requestId = "";
|
||||
string op = "";
|
||||
|
||||
if (!HelperProtocol.TryParseRequest(requestText, out request, out requestId, out op))
|
||||
{
|
||||
Console.WriteLine(HelperProtocol.ToJson(HelperProtocol.Failure(requestId, op, "INVALID_REQUEST", "request must be valid JSON object")));
|
||||
return 0;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
Dictionary<string, object> opArgs = HelperProtocol.GetObject(request, "args");
|
||||
Dictionary<string, object> response;
|
||||
|
||||
switch (op)
|
||||
{
|
||||
case "version":
|
||||
response = HelperProtocol.Success(requestId, op, VersionData());
|
||||
break;
|
||||
case "self_check":
|
||||
response = HelperProtocol.Success(requestId, op, SelfCheckData());
|
||||
break;
|
||||
case "scan_windows":
|
||||
response = HelperProtocol.Success(requestId, op, WindowScanner.Scan(opArgs));
|
||||
break;
|
||||
case "dump_uia":
|
||||
response = UiaDumper.Dump(requestId, op, opArgs);
|
||||
break;
|
||||
default:
|
||||
response = HelperProtocol.Failure(requestId, op, "UNSUPPORTED_OP", "unsupported op: " + op);
|
||||
break;
|
||||
}
|
||||
|
||||
Console.WriteLine(HelperProtocol.ToJson(response));
|
||||
return 0;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Console.Error.WriteLine(ex.ToString());
|
||||
Console.WriteLine(HelperProtocol.ToJson(HelperProtocol.Failure(requestId, op, "HELPER_FAILED", ex.Message)));
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
private static Dictionary<string, object> VersionData()
|
||||
{
|
||||
return new Dictionary<string, object>
|
||||
{
|
||||
{ "helper_name", "ISphereWinHelper" },
|
||||
{ "helper_version", "0.1.0" },
|
||||
{ "protocol", HelperProtocol.Protocol },
|
||||
{ "runtime", ".NET Framework " + Environment.Version }
|
||||
};
|
||||
}
|
||||
|
||||
private static Dictionary<string, object> SelfCheckData()
|
||||
{
|
||||
bool uiaAvailable;
|
||||
try
|
||||
{
|
||||
uiaAvailable = System.Windows.Automation.AutomationElement.RootElement != null;
|
||||
}
|
||||
catch
|
||||
{
|
||||
uiaAvailable = false;
|
||||
}
|
||||
|
||||
return new Dictionary<string, object>
|
||||
{
|
||||
{ "desktop_access", Environment.UserInteractive },
|
||||
{ "uia_available", uiaAvailable }
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user