Convert native helper to .NET Framework
This commit is contained in:
1 parent
6229d26d77
commit
662fb47ff2
22 files changed
+434
-382
No files matched your search
@@ -1,3 +1,4 @@
|
||||
**/bin/
|
||||
**/obj/
|
||||
.build/
|
||||
**/.vs
|
||||
@@ -1,8 +1,7 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
<PropertyGroup>
|
||||
<OutputType>Exe</OutputType>
|
||||
<TargetFramework>net10.0-windows10.0.19041.0</TargetFramework>
|
||||
<EnableWindowsTargeting>true</EnableWindowsTargeting>
|
||||
<TargetFramework>net48</TargetFramework>
|
||||
<UseWPF>true</UseWPF>
|
||||
<UseWindowsForms>true</UseWindowsForms>
|
||||
<EnableDefaultCompileItems>false</EnableDefaultCompileItems>
|
||||
@@ -12,15 +11,11 @@
|
||||
<AssemblyName>dsh-cua-windows</AssemblyName>
|
||||
<ApplicationManifest>app.manifest</ApplicationManifest>
|
||||
<RestorePackagesWithLockFile>true</RestorePackagesWithLockFile>
|
||||
<RuntimeIdentifiers>win-x64;win-arm64</RuntimeIdentifiers>
|
||||
<PublishSingleFile>true</PublishSingleFile>
|
||||
<IncludeNativeLibrariesForSelfExtract>true</IncludeNativeLibrariesForSelfExtract>
|
||||
<DebugType>none</DebugType>
|
||||
<DebugSymbols>false</DebugSymbols>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="src/**/*.cs" />
|
||||
<ProjectReference Include="protocol/CuaProtocol.csproj" GlobalPropertiesToRemove="RuntimeIdentifier;SelfContained" />
|
||||
<PackageReference Include="Vortice.Direct3D11" Version="3.8.3" />
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
@@ -1,6 +1,13 @@
|
||||
<Project>
|
||||
<PropertyGroup>
|
||||
<LangVersion>14.0</LangVersion>
|
||||
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
|
||||
<BaseOutputPath>$(MSBuildThisFileDirectory).build/$(MSBuildProjectName)/bin/</BaseOutputPath>
|
||||
<BaseIntermediateOutputPath>$(MSBuildThisFileDirectory).build/$(MSBuildProjectName)/obj/</BaseIntermediateOutputPath>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.NETFramework.ReferenceAssemblies" Version="1.0.3" PrivateAssets="all" />
|
||||
<PackageReference Include="PolySharp" Version="1.15.0" PrivateAssets="all" />
|
||||
<PackageReference Include="System.Text.Json" Version="[10.0.14]" />
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
@@ -0,0 +1,12 @@
|
||||
<Solution>
|
||||
<Folder Name="/desktop-tests/">
|
||||
<Project Path="desktop-tests/DesktopFixture.csproj" />
|
||||
</Folder>
|
||||
<Folder Name="/protocol/">
|
||||
<Project Path="protocol/CuaProtocol.csproj" />
|
||||
</Folder>
|
||||
<Folder Name="/tests/">
|
||||
<Project Path="tests/Protocol.Tests.csproj" />
|
||||
</Folder>
|
||||
<Project Path="CuaWindows.csproj" />
|
||||
</Solution>
|
||||
@@ -1,13 +1,10 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
<PropertyGroup>
|
||||
<OutputType>Exe</OutputType>
|
||||
<TargetFramework>net10.0-windows</TargetFramework>
|
||||
<TargetFramework>net48</TargetFramework>
|
||||
<UseWindowsForms>true</UseWindowsForms>
|
||||
<EnableWindowsTargeting>true</EnableWindowsTargeting>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
<AssemblyName>dsh-cua-desktop-fixture</AssemblyName>
|
||||
<PublishSingleFile>true</PublishSingleFile>
|
||||
<IncludeNativeLibrariesForSelfExtract>true</IncludeNativeLibrariesForSelfExtract>
|
||||
</PropertyGroup>
|
||||
</Project>
|
||||
@@ -0,0 +1,9 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="Current" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<PropertyGroup />
|
||||
<ItemGroup>
|
||||
<Compile Update="Program.cs">
|
||||
<SubType>Form</SubType>
|
||||
</Compile>
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
@@ -1,32 +1,56 @@
|
||||
{
|
||||
"version": 1,
|
||||
"dependencies": {
|
||||
"net10.0-windows10.0.19041": {
|
||||
"Microsoft.NET.ILLink.Tasks": {
|
||||
".NETFramework,Version=v4.8": {
|
||||
"Microsoft.NETFramework.ReferenceAssemblies": {
|
||||
"type": "Direct",
|
||||
"requested": "[10.0.14, )",
|
||||
"resolved": "10.0.14",
|
||||
"contentHash": "YlTamXppEQls6DYWt7RdUuwWDb0lyw/vXCaGeQpLCpsLmfwGuCkOz/vIGgMTV7ECsJcavkCOkxZXv9s8rdAHkQ=="
|
||||
},
|
||||
"Vortice.Direct3D11": {
|
||||
"type": "Direct",
|
||||
"requested": "[3.8.3, )",
|
||||
"resolved": "3.8.3",
|
||||
"contentHash": "JgFUswu2mgrSwcd0KRF2AnfeE5VbMEgcicmxPD1g2yXyomPIHbnX3wldBNHPOzzD0URC1WJ/pO1ymfi3imZwvg==",
|
||||
"requested": "[1.0.3, )",
|
||||
"resolved": "1.0.3",
|
||||
"contentHash": "vUc9Npcs14QsyOD01tnv/m8sQUnGTGOw1BCmKcv77LBJY7OxhJ+zJF7UD/sCL3lYNFuqmQEVlkfS4Quif6FyYg==",
|
||||
"dependencies": {
|
||||
"SharpGen.Runtime": "2.4.2-beta",
|
||||
"Vortice.DXGI": "3.8.3"
|
||||
"Microsoft.NETFramework.ReferenceAssemblies.net48": "1.0.3"
|
||||
}
|
||||
},
|
||||
"PolySharp": {
|
||||
"type": "Direct",
|
||||
"requested": "[1.15.0, )",
|
||||
"resolved": "1.15.0",
|
||||
"contentHash": "FbU0El+EEjdpuIX4iDbeS7ki1uzpJPx8vbqOzEtqnl1GZeAGJfq+jCbxeJL2y0EPnUNk8dRnnqR2xnYXg9Tf+g=="
|
||||
},
|
||||
"System.Text.Json": {
|
||||
"type": "Direct",
|
||||
"requested": "[10.0.14, 10.0.14]",
|
||||
"resolved": "10.0.14",
|
||||
"contentHash": "JSSLGJTJJDvS76VnLdY1X289rFcHuYApk7QGw0hCoP5wVR1mk7BvJbOYxQLXq4x1qK/Ml9OHa/AKaAbBVCfSSQ==",
|
||||
"dependencies": {
|
||||
"Microsoft.Bcl.AsyncInterfaces": "10.0.14",
|
||||
"System.Buffers": "4.6.1",
|
||||
"System.IO.Pipelines": "10.0.14",
|
||||
"System.Memory": "4.6.3",
|
||||
"System.Runtime.CompilerServices.Unsafe": "6.1.2",
|
||||
"System.Text.Encodings.Web": "10.0.14",
|
||||
"System.Threading.Tasks.Extensions": "4.6.3",
|
||||
"System.ValueTuple": "4.6.2"
|
||||
}
|
||||
},
|
||||
"Humanizer.Core": {
|
||||
"type": "Transitive",
|
||||
"resolved": "3.0.10",
|
||||
"contentHash": "yZIhtw8sYuvsONzQbZxWpR60tMWYHXoo0DL6nyOqSFiU5POjBTSEyWFpTQtJEZuy+oqiYTXKXY/Mjx7KnqIQFw=="
|
||||
"contentHash": "yZIhtw8sYuvsONzQbZxWpR60tMWYHXoo0DL6nyOqSFiU5POjBTSEyWFpTQtJEZuy+oqiYTXKXY/Mjx7KnqIQFw==",
|
||||
"dependencies": {
|
||||
"System.Collections.Immutable": "9.0.10",
|
||||
"System.ComponentModel.Annotations": "5.0.0",
|
||||
"System.Memory": "4.6.3"
|
||||
}
|
||||
},
|
||||
"Json.More.Net": {
|
||||
"type": "Transitive",
|
||||
"resolved": "3.0.1",
|
||||
"contentHash": "fRctF2J2SILYG6wqP21drmeEODmCVkVQ/b3MndDu2fT1swfySyUgq7ePCk+aENGlDcIm05fyfjh9vcuqDEfv3w=="
|
||||
"contentHash": "fRctF2J2SILYG6wqP21drmeEODmCVkVQ/b3MndDu2fT1swfySyUgq7ePCk+aENGlDcIm05fyfjh9vcuqDEfv3w==",
|
||||
"dependencies": {
|
||||
"System.Collections.Immutable": "10.0.5",
|
||||
"System.Text.Json": "10.0.5"
|
||||
}
|
||||
},
|
||||
"JsonPointer.Net": {
|
||||
"type": "Transitive",
|
||||
@@ -45,51 +69,99 @@
|
||||
"JsonPointer.Net": "7.0.2"
|
||||
}
|
||||
},
|
||||
"SharpGen.Runtime": {
|
||||
"Microsoft.Bcl.AsyncInterfaces": {
|
||||
"type": "Transitive",
|
||||
"resolved": "2.4.2-beta",
|
||||
"contentHash": "niTtWAUov1F7wZGAlVeEvW+Tnqvg5yTmhI7rxmYu2Utoyu2TbC9tWWpUpMs0PQg5lu5svoYpCAztNjxCqMFP/w=="
|
||||
},
|
||||
"SharpGen.Runtime.COM": {
|
||||
"type": "Transitive",
|
||||
"resolved": "2.4.2-beta",
|
||||
"contentHash": "9lxDFMiepqo3lJQzMSjECCIONeCc2f3Drokgj6HtrTLZcJSftNgcLbD6/iXYj2iphkwgrZb1oLsDOZxoFZkawQ==",
|
||||
"resolved": "10.0.14",
|
||||
"contentHash": "HCu9NbiXDh9++j4eRNRHCOiKPw/7I5UEJlFIRaDM3v0+ttZaH8p8rjxSWfNgP2cGv5JAa4EZnmc/nlcUOTFlpA==",
|
||||
"dependencies": {
|
||||
"SharpGen.Runtime": "2.4.2-beta"
|
||||
"System.Threading.Tasks.Extensions": "4.6.3"
|
||||
}
|
||||
},
|
||||
"Vortice.DirectX": {
|
||||
"Microsoft.NETFramework.ReferenceAssemblies.net48": {
|
||||
"type": "Transitive",
|
||||
"resolved": "3.8.3",
|
||||
"contentHash": "nKwSavv0w5rDF7prSefqAVPDcTyqrfZxKFMVfttiXPfm62VdA/1d+b3PhCZpW4xO7jXczXDwjQdWgD1zGsvM8w==",
|
||||
"resolved": "1.0.3",
|
||||
"contentHash": "zMk4D+9zyiEWByyQ7oPImPN/Jhpj166Ky0Nlla4eXlNL8hI/BtSJsgR8Inldd4NNpIAH3oh8yym0W2DrhXdSLQ=="
|
||||
},
|
||||
"System.Buffers": {
|
||||
"type": "Transitive",
|
||||
"resolved": "4.6.1",
|
||||
"contentHash": "N8GXpmiLMtljq7gwvyS+1QvKT/W2J8sNAvx+HVg4NGmsG/H+2k/y9QI23auLJRterrzCiDH+IWAw4V/GPwsMlw=="
|
||||
},
|
||||
"System.Collections.Immutable": {
|
||||
"type": "Transitive",
|
||||
"resolved": "10.0.5",
|
||||
"contentHash": "nozrOKfEgfrvvswkCfxaumY68RA/x1F3ZYwtwRvva8ul91NCnUzb6MKpl5/P7u9v/nIagVL4OXXj8d007tucxw==",
|
||||
"dependencies": {
|
||||
"SharpGen.Runtime": "2.4.2-beta",
|
||||
"SharpGen.Runtime.COM": "2.4.2-beta",
|
||||
"Vortice.Mathematics": "2.1.0"
|
||||
"System.Memory": "4.6.3",
|
||||
"System.Runtime.CompilerServices.Unsafe": "6.1.2"
|
||||
}
|
||||
},
|
||||
"Vortice.DXGI": {
|
||||
"System.ComponentModel.Annotations": {
|
||||
"type": "Transitive",
|
||||
"resolved": "3.8.3",
|
||||
"contentHash": "MbAUnTeQ6WD99ctAdrj5CQO2I7oaax0Kt2eVdWSUj0bYP9Ed0726+s7dIHe4+tqhpmINW/dcPt0mNtc72o+E0w==",
|
||||
"resolved": "5.0.0",
|
||||
"contentHash": "dMkqfy2el8A8/I76n2Hi1oBFEbG1SfxD2l5nhwXV3XjlnOmwxJlQbYpJH4W51odnU9sARCSAgv7S3CyAFMkpYg=="
|
||||
},
|
||||
"System.IO.Pipelines": {
|
||||
"type": "Transitive",
|
||||
"resolved": "10.0.14",
|
||||
"contentHash": "pLVClkIC4XfXhcOQXNtNDJl5LYJOS4XAQAdzbqF8rj6sk2zdXO/5uikBsZqgqnAAb07z9Fmtu0sMj3TwEiBtIw==",
|
||||
"dependencies": {
|
||||
"SharpGen.Runtime": "2.4.2-beta",
|
||||
"Vortice.DirectX": "3.8.3"
|
||||
"System.Buffers": "4.6.1",
|
||||
"System.Memory": "4.6.3",
|
||||
"System.Threading.Tasks.Extensions": "4.6.3"
|
||||
}
|
||||
},
|
||||
"Vortice.Mathematics": {
|
||||
"System.Memory": {
|
||||
"type": "Transitive",
|
||||
"resolved": "2.1.0",
|
||||
"contentHash": "KK+SjNSuKdP+zbavekubi+vaeb1Jo4k87ZF6CMkVWjr6RjJwc8peVtmgzXXDIMy4ZC3ZISyk3llY3q65ISOkBQ=="
|
||||
"resolved": "4.6.3",
|
||||
"contentHash": "qdcDOgnFZY40+Q9876JUHnlHu7bosOHX8XISRoH94fwk6hgaeQGSgfZd8srWRZNt5bV9ZW2TljcegDNxsf+96A==",
|
||||
"dependencies": {
|
||||
"System.Buffers": "4.6.1",
|
||||
"System.Numerics.Vectors": "4.6.1",
|
||||
"System.Runtime.CompilerServices.Unsafe": "6.1.2"
|
||||
}
|
||||
},
|
||||
"System.Numerics.Vectors": {
|
||||
"type": "Transitive",
|
||||
"resolved": "4.6.1",
|
||||
"contentHash": "sQxefTnhagrhoq2ReR0D/6K0zJcr9Hrd6kikeXsA1I8kOCboTavcUC4r7TSfpKFeE163uMuxZcyfO1mGO3EN8Q=="
|
||||
},
|
||||
"System.Runtime.CompilerServices.Unsafe": {
|
||||
"type": "Transitive",
|
||||
"resolved": "6.1.2",
|
||||
"contentHash": "2hBr6zdbIBTDE3EhK7NSVNdX58uTK6iHW/P/Axmm9sl1xoGSLqDvMtpecn226TNwHByFokYwJmt/aQQNlO5CRw=="
|
||||
},
|
||||
"System.Text.Encodings.Web": {
|
||||
"type": "Transitive",
|
||||
"resolved": "10.0.14",
|
||||
"contentHash": "+aDpFLtsHyft9ZVx9pZQ9MILqwrr8LK1te1L39VMKQYhoYDbs+RUqBhCT3Zydb5ymi2Buo4Cn+3Wi208IxD6rw==",
|
||||
"dependencies": {
|
||||
"System.Buffers": "4.6.1",
|
||||
"System.Memory": "4.6.3",
|
||||
"System.Runtime.CompilerServices.Unsafe": "6.1.2"
|
||||
}
|
||||
},
|
||||
"System.Threading.Tasks.Extensions": {
|
||||
"type": "Transitive",
|
||||
"resolved": "4.6.3",
|
||||
"contentHash": "7sCiwilJLYbTZELaKnc7RecBBXWXA+xMLQWZKWawBxYjp6DBlSE3v9/UcvKBvr1vv2tTOhipiogM8rRmxlhrVA==",
|
||||
"dependencies": {
|
||||
"System.Runtime.CompilerServices.Unsafe": "6.1.2"
|
||||
}
|
||||
},
|
||||
"System.ValueTuple": {
|
||||
"type": "Transitive",
|
||||
"resolved": "4.6.2",
|
||||
"contentHash": "yQgmjfFximrNm9LIV3mL6T5MzjeC+epeE5rl4hXxAlYmxby7RM1dPSkIKXk9HNkl6G54h2JHOmLD46+Pey+IRg=="
|
||||
},
|
||||
"cuaprotocol": {
|
||||
"type": "Project",
|
||||
"dependencies": {
|
||||
"JsonSchema.Net": "[9.4.0, )"
|
||||
"JsonSchema.Net": "[9.4.0, )",
|
||||
"System.Text.Json": "[10.0.14, 10.0.14]"
|
||||
}
|
||||
}
|
||||
},
|
||||
"net10.0-windows10.0.19041/win-arm64": {},
|
||||
"net10.0-windows10.0.19041/win-x64": {}
|
||||
".NETFramework,Version=v4.8/win-x86": {}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -64,9 +64,9 @@ public static class AccessibilityText
|
||||
if (actions.Length != 0) text.Append(" actions=[").Append(string.Join(", ", actions.Select(Quote))).Append(']');
|
||||
if (details)
|
||||
{
|
||||
if (!string.IsNullOrEmpty(node.Identifier)) text.Append(" id=").Append(Quote(node.Identifier));
|
||||
if (node.Identifier is { Length: > 0 } identifier) text.Append(" id=").Append(Quote(identifier));
|
||||
if (index.HasValue && node.Bounds is { } bounds)
|
||||
text.Append(" bounds=[").Append(string.Join(',', new[] { bounds.X, bounds.Y, bounds.Width, bounds.Height }
|
||||
text.Append(" bounds=[").Append(string.Join(",", new[] { bounds.X, bounds.Y, bounds.Width, bounds.Height }
|
||||
.Select(number => number.ToString("G", CultureInfo.InvariantCulture)))).Append(']');
|
||||
}
|
||||
return text.ToString();
|
||||
|
||||
@@ -1,10 +1,9 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net10.0</TargetFramework>
|
||||
<TargetFramework>net48</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
<RestorePackagesWithLockFile>true</RestorePackagesWithLockFile>
|
||||
<RuntimeIdentifiers>win-x64;win-arm64</RuntimeIdentifiers>
|
||||
<IsPublishable>false</IsPublishable>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
|
||||
@@ -6,10 +6,10 @@ public sealed record KeyChord(string Key, string[] Modifiers)
|
||||
{
|
||||
if (text.Length == 0) throw new NativeFailure("INVALID_ARGUMENT", "A key name is required");
|
||||
var plus = text == "+" || text.EndsWith("++", StringComparison.Ordinal);
|
||||
var parts = plus ? text[..^1].TrimEnd('+').Split('+', StringSplitOptions.RemoveEmptyEntries) : text.Split('+');
|
||||
var parts = plus ? text[..^1].TrimEnd('+').Split(new[] { '+' }, StringSplitOptions.RemoveEmptyEntries) : text.Split('+');
|
||||
var key = plus ? "+" : parts[^1];
|
||||
if (key.Length == 0) throw new NativeFailure("INVALID_ARGUMENT", "A key chord must end with a key");
|
||||
var modifiers = (plus ? parts : parts[..^1]).Concat(extra).Select(NormalizeModifier).Distinct().ToArray();
|
||||
var modifiers = (plus ? parts : parts.Take(parts.Length - 1)).Concat(extra).Select(NormalizeModifier).Distinct().ToArray();
|
||||
return new(key, modifiers);
|
||||
}
|
||||
|
||||
|
||||
@@ -80,7 +80,7 @@ public sealed class FrameReader(Stream stream)
|
||||
{
|
||||
if (start == end)
|
||||
{
|
||||
end = await stream.ReadAsync(buffer, cancellation);
|
||||
end = await stream.ReadAsync(buffer, 0, buffer.Length, cancellation);
|
||||
start = 0;
|
||||
if (end == 0)
|
||||
{
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"version": 1,
|
||||
"dependencies": {
|
||||
"net10.0": {
|
||||
".NETFramework,Version=v4.8": {
|
||||
"JsonSchema.Net": {
|
||||
"type": "Direct",
|
||||
"requested": "[9.4.0, )",
|
||||
@@ -11,15 +11,55 @@
|
||||
"JsonPointer.Net": "7.0.2"
|
||||
}
|
||||
},
|
||||
"Microsoft.NETFramework.ReferenceAssemblies": {
|
||||
"type": "Direct",
|
||||
"requested": "[1.0.3, )",
|
||||
"resolved": "1.0.3",
|
||||
"contentHash": "vUc9Npcs14QsyOD01tnv/m8sQUnGTGOw1BCmKcv77LBJY7OxhJ+zJF7UD/sCL3lYNFuqmQEVlkfS4Quif6FyYg==",
|
||||
"dependencies": {
|
||||
"Microsoft.NETFramework.ReferenceAssemblies.net48": "1.0.3"
|
||||
}
|
||||
},
|
||||
"PolySharp": {
|
||||
"type": "Direct",
|
||||
"requested": "[1.15.0, )",
|
||||
"resolved": "1.15.0",
|
||||
"contentHash": "FbU0El+EEjdpuIX4iDbeS7ki1uzpJPx8vbqOzEtqnl1GZeAGJfq+jCbxeJL2y0EPnUNk8dRnnqR2xnYXg9Tf+g=="
|
||||
},
|
||||
"System.Text.Json": {
|
||||
"type": "Direct",
|
||||
"requested": "[10.0.14, 10.0.14]",
|
||||
"resolved": "10.0.14",
|
||||
"contentHash": "JSSLGJTJJDvS76VnLdY1X289rFcHuYApk7QGw0hCoP5wVR1mk7BvJbOYxQLXq4x1qK/Ml9OHa/AKaAbBVCfSSQ==",
|
||||
"dependencies": {
|
||||
"Microsoft.Bcl.AsyncInterfaces": "10.0.14",
|
||||
"System.Buffers": "4.6.1",
|
||||
"System.IO.Pipelines": "10.0.14",
|
||||
"System.Memory": "4.6.3",
|
||||
"System.Runtime.CompilerServices.Unsafe": "6.1.2",
|
||||
"System.Text.Encodings.Web": "10.0.14",
|
||||
"System.Threading.Tasks.Extensions": "4.6.3",
|
||||
"System.ValueTuple": "4.6.2"
|
||||
}
|
||||
},
|
||||
"Humanizer.Core": {
|
||||
"type": "Transitive",
|
||||
"resolved": "3.0.10",
|
||||
"contentHash": "yZIhtw8sYuvsONzQbZxWpR60tMWYHXoo0DL6nyOqSFiU5POjBTSEyWFpTQtJEZuy+oqiYTXKXY/Mjx7KnqIQFw=="
|
||||
"contentHash": "yZIhtw8sYuvsONzQbZxWpR60tMWYHXoo0DL6nyOqSFiU5POjBTSEyWFpTQtJEZuy+oqiYTXKXY/Mjx7KnqIQFw==",
|
||||
"dependencies": {
|
||||
"System.Collections.Immutable": "9.0.10",
|
||||
"System.ComponentModel.Annotations": "5.0.0",
|
||||
"System.Memory": "4.6.3"
|
||||
}
|
||||
},
|
||||
"Json.More.Net": {
|
||||
"type": "Transitive",
|
||||
"resolved": "3.0.1",
|
||||
"contentHash": "fRctF2J2SILYG6wqP21drmeEODmCVkVQ/b3MndDu2fT1swfySyUgq7ePCk+aENGlDcIm05fyfjh9vcuqDEfv3w=="
|
||||
"contentHash": "fRctF2J2SILYG6wqP21drmeEODmCVkVQ/b3MndDu2fT1swfySyUgq7ePCk+aENGlDcIm05fyfjh9vcuqDEfv3w==",
|
||||
"dependencies": {
|
||||
"System.Collections.Immutable": "10.0.5",
|
||||
"System.Text.Json": "10.0.5"
|
||||
}
|
||||
},
|
||||
"JsonPointer.Net": {
|
||||
"type": "Transitive",
|
||||
@@ -29,9 +69,92 @@
|
||||
"Humanizer.Core": "3.0.10",
|
||||
"Json.More.Net": "3.0.1"
|
||||
}
|
||||
},
|
||||
"Microsoft.Bcl.AsyncInterfaces": {
|
||||
"type": "Transitive",
|
||||
"resolved": "10.0.14",
|
||||
"contentHash": "HCu9NbiXDh9++j4eRNRHCOiKPw/7I5UEJlFIRaDM3v0+ttZaH8p8rjxSWfNgP2cGv5JAa4EZnmc/nlcUOTFlpA==",
|
||||
"dependencies": {
|
||||
"System.Threading.Tasks.Extensions": "4.6.3"
|
||||
}
|
||||
},
|
||||
"Microsoft.NETFramework.ReferenceAssemblies.net48": {
|
||||
"type": "Transitive",
|
||||
"resolved": "1.0.3",
|
||||
"contentHash": "zMk4D+9zyiEWByyQ7oPImPN/Jhpj166Ky0Nlla4eXlNL8hI/BtSJsgR8Inldd4NNpIAH3oh8yym0W2DrhXdSLQ=="
|
||||
},
|
||||
"System.Buffers": {
|
||||
"type": "Transitive",
|
||||
"resolved": "4.6.1",
|
||||
"contentHash": "N8GXpmiLMtljq7gwvyS+1QvKT/W2J8sNAvx+HVg4NGmsG/H+2k/y9QI23auLJRterrzCiDH+IWAw4V/GPwsMlw=="
|
||||
},
|
||||
"System.Collections.Immutable": {
|
||||
"type": "Transitive",
|
||||
"resolved": "10.0.5",
|
||||
"contentHash": "nozrOKfEgfrvvswkCfxaumY68RA/x1F3ZYwtwRvva8ul91NCnUzb6MKpl5/P7u9v/nIagVL4OXXj8d007tucxw==",
|
||||
"dependencies": {
|
||||
"System.Memory": "4.6.3",
|
||||
"System.Runtime.CompilerServices.Unsafe": "6.1.2"
|
||||
}
|
||||
},
|
||||
"System.ComponentModel.Annotations": {
|
||||
"type": "Transitive",
|
||||
"resolved": "5.0.0",
|
||||
"contentHash": "dMkqfy2el8A8/I76n2Hi1oBFEbG1SfxD2l5nhwXV3XjlnOmwxJlQbYpJH4W51odnU9sARCSAgv7S3CyAFMkpYg=="
|
||||
},
|
||||
"System.IO.Pipelines": {
|
||||
"type": "Transitive",
|
||||
"resolved": "10.0.14",
|
||||
"contentHash": "pLVClkIC4XfXhcOQXNtNDJl5LYJOS4XAQAdzbqF8rj6sk2zdXO/5uikBsZqgqnAAb07z9Fmtu0sMj3TwEiBtIw==",
|
||||
"dependencies": {
|
||||
"System.Buffers": "4.6.1",
|
||||
"System.Memory": "4.6.3",
|
||||
"System.Threading.Tasks.Extensions": "4.6.3"
|
||||
}
|
||||
},
|
||||
"System.Memory": {
|
||||
"type": "Transitive",
|
||||
"resolved": "4.6.3",
|
||||
"contentHash": "qdcDOgnFZY40+Q9876JUHnlHu7bosOHX8XISRoH94fwk6hgaeQGSgfZd8srWRZNt5bV9ZW2TljcegDNxsf+96A==",
|
||||
"dependencies": {
|
||||
"System.Buffers": "4.6.1",
|
||||
"System.Numerics.Vectors": "4.6.1",
|
||||
"System.Runtime.CompilerServices.Unsafe": "6.1.2"
|
||||
}
|
||||
},
|
||||
"System.Numerics.Vectors": {
|
||||
"type": "Transitive",
|
||||
"resolved": "4.6.1",
|
||||
"contentHash": "sQxefTnhagrhoq2ReR0D/6K0zJcr9Hrd6kikeXsA1I8kOCboTavcUC4r7TSfpKFeE163uMuxZcyfO1mGO3EN8Q=="
|
||||
},
|
||||
"System.Runtime.CompilerServices.Unsafe": {
|
||||
"type": "Transitive",
|
||||
"resolved": "6.1.2",
|
||||
"contentHash": "2hBr6zdbIBTDE3EhK7NSVNdX58uTK6iHW/P/Axmm9sl1xoGSLqDvMtpecn226TNwHByFokYwJmt/aQQNlO5CRw=="
|
||||
},
|
||||
"System.Text.Encodings.Web": {
|
||||
"type": "Transitive",
|
||||
"resolved": "10.0.14",
|
||||
"contentHash": "+aDpFLtsHyft9ZVx9pZQ9MILqwrr8LK1te1L39VMKQYhoYDbs+RUqBhCT3Zydb5ymi2Buo4Cn+3Wi208IxD6rw==",
|
||||
"dependencies": {
|
||||
"System.Buffers": "4.6.1",
|
||||
"System.Memory": "4.6.3",
|
||||
"System.Runtime.CompilerServices.Unsafe": "6.1.2"
|
||||
}
|
||||
},
|
||||
"System.Threading.Tasks.Extensions": {
|
||||
"type": "Transitive",
|
||||
"resolved": "4.6.3",
|
||||
"contentHash": "7sCiwilJLYbTZELaKnc7RecBBXWXA+xMLQWZKWawBxYjp6DBlSE3v9/UcvKBvr1vv2tTOhipiogM8rRmxlhrVA==",
|
||||
"dependencies": {
|
||||
"System.Runtime.CompilerServices.Unsafe": "6.1.2"
|
||||
}
|
||||
},
|
||||
"System.ValueTuple": {
|
||||
"type": "Transitive",
|
||||
"resolved": "4.6.2",
|
||||
"contentHash": "yQgmjfFximrNm9LIV3mL6T5MzjeC+epeE5rl4hXxAlYmxby7RM1dPSkIKXk9HNkl6G54h2JHOmLD46+Pey+IRg=="
|
||||
}
|
||||
},
|
||||
"net10.0/win-arm64": {},
|
||||
"net10.0/win-x64": {}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,34 +0,0 @@
|
||||
// The native operation owns its capture slot until cleanup finishes, independently of the caller's await.
|
||||
using DeepSeek.Cua.Protocol;
|
||||
|
||||
namespace DeepSeek.Cua.Windows;
|
||||
|
||||
internal sealed class CaptureAdmission
|
||||
{
|
||||
private readonly object gate = new();
|
||||
private Task<byte[]>? pending;
|
||||
|
||||
internal Task<byte[]> Start(Func<Task<byte[]>> operation)
|
||||
{
|
||||
lock (gate)
|
||||
{
|
||||
if (pending is { IsCompleted: false })
|
||||
throw new NativeFailure("CAPTURE_BUSY", "The previous Windows capture is still releasing its resources; UIA and input remain available");
|
||||
pending = operation();
|
||||
_ = pending.ContinueWith(completed => { _ = completed.Exception; }, CancellationToken.None,
|
||||
TaskContinuationOptions.OnlyOnFaulted | TaskContinuationOptions.ExecuteSynchronously, TaskScheduler.Default);
|
||||
return pending;
|
||||
}
|
||||
}
|
||||
|
||||
internal async Task Join()
|
||||
{
|
||||
Task<byte[]>? active;
|
||||
lock (gate) active = pending;
|
||||
if (active is not null)
|
||||
{
|
||||
try { await active; }
|
||||
catch (Exception error) { _ = error; /* The requesting connection owns the capture failure. */ }
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -10,7 +10,7 @@ internal sealed class ClipboardPaste
|
||||
{
|
||||
private sealed class Transaction(ServiceControl control, int targetPid, uint format, byte[] payload, List<(uint Format, byte[] Data)> previous, uint originalSequence)
|
||||
{
|
||||
internal readonly TaskCompletionSource Consumed = new(TaskCreationOptions.RunContinuationsAsynchronously);
|
||||
internal readonly TaskCompletionSource<object?> Consumed = new(TaskCreationOptions.RunContinuationsAsynchronously);
|
||||
private uint sequence = originalSequence;
|
||||
private bool replaced;
|
||||
private bool restoring;
|
||||
@@ -68,7 +68,7 @@ internal sealed class ClipboardPaste
|
||||
rendered = true;
|
||||
sequence = Win32.GetClipboardSequenceNumber();
|
||||
if (changed) Consumed.TrySetException(new NativeFailure("CLIPBOARD_CHANGED", "Another writer changed the clipboard during paste"));
|
||||
else if (message == 0x0305) Consumed.TrySetResult();
|
||||
else if (message == 0x0305) Consumed.TrySetResult(null);
|
||||
}
|
||||
catch (Exception error) { Consumed.TrySetException(error); }
|
||||
finally { if (opened) Win32.CloseClipboard(); }
|
||||
|
||||
@@ -14,7 +14,7 @@ internal sealed class ClientState
|
||||
internal void Clear() { foreach (var app in Apps.Values) app.Dispose(); Apps.Clear(); Launches.Clear(); }
|
||||
}
|
||||
|
||||
internal sealed class DesktopExecutor(MtaDispatcher mta, StaDispatcher sta, int graceMs) : IAsyncDisposable
|
||||
internal sealed class DesktopExecutor(MtaDispatcher mta, StaDispatcher sta) : IAsyncDisposable
|
||||
{
|
||||
private readonly WindowCapture capture = new();
|
||||
private readonly ClipboardPaste clipboard = new();
|
||||
@@ -75,13 +75,13 @@ internal sealed class DesktopExecutor(MtaDispatcher mta, StaDispatcher sta, int
|
||||
var context = new RequestContext(config, cancellation, mta, sta);
|
||||
context.Check();
|
||||
var parameters = request.Params;
|
||||
if (request.Method == "permissionStatus") return DesktopSession.Status(await capture.IsSupported(cancellation));
|
||||
if (request.Method == "permissionStatus") return DesktopSession.Status(false);
|
||||
if (request.Method == "applicationIcons") return await sta.Invoke(_ => Applications.Icons(parameters, context), cancellation);
|
||||
if (request.Method == "getCapabilities")
|
||||
{
|
||||
var locked = DesktopSession.Locked();
|
||||
return new { permissions = new { accessibility = locked == false,
|
||||
screenRecording = locked == false && await capture.IsSupported(cancellation) },
|
||||
screenRecording = false },
|
||||
sessionLocked = locked };
|
||||
}
|
||||
if (request.Method is "requestPermission" or "openPermissionSettings")
|
||||
@@ -255,10 +255,9 @@ internal sealed class DesktopExecutor(MtaDispatcher mta, StaDispatcher sta, int
|
||||
finally { queue.Release(); }
|
||||
}
|
||||
|
||||
public async ValueTask DisposeAsync()
|
||||
public ValueTask DisposeAsync()
|
||||
{
|
||||
try { await capture.DisposeAsync().AsTask().WaitAsync(TimeSpan.FromMilliseconds(graceMs)); }
|
||||
catch (TimeoutException) { NativeServer.Fatal("NATIVE_CLEANUP", "The idle desktop service could not release capture resources"); }
|
||||
queue.Dispose();
|
||||
return default;
|
||||
}
|
||||
}
|
||||
@@ -31,8 +31,8 @@ internal sealed record NativeConfig(int MaxRequestBytes, int MaxResponseBytes, i
|
||||
internal sealed class MtaDispatcher : IAsyncDisposable
|
||||
{
|
||||
private readonly BlockingCollection<Action> queue = new();
|
||||
private readonly TaskCompletionSource stopped = new(TaskCreationOptions.RunContinuationsAsynchronously);
|
||||
private readonly TaskCompletionSource ready = new(TaskCreationOptions.RunContinuationsAsynchronously);
|
||||
private readonly TaskCompletionSource<object?> stopped = new(TaskCreationOptions.RunContinuationsAsynchronously);
|
||||
private readonly TaskCompletionSource<object?> ready = new(TaskCreationOptions.RunContinuationsAsynchronously);
|
||||
private readonly Thread thread;
|
||||
|
||||
internal MtaDispatcher()
|
||||
@@ -45,11 +45,11 @@ internal sealed class MtaDispatcher : IAsyncDisposable
|
||||
Marshal.ThrowExceptionForHR(Win32.RoInitialize(1));
|
||||
initialized = true;
|
||||
Win32.SetThreadDpiAwarenessContext(-4);
|
||||
ready.SetResult();
|
||||
ready.SetResult(null);
|
||||
foreach (var work in queue.GetConsumingEnumerable()) work();
|
||||
}
|
||||
catch (Exception error) { ready.TrySetException(error); }
|
||||
finally { if (initialized) Win32.RoUninitialize(); stopped.TrySetResult(); }
|
||||
finally { if (initialized) Win32.RoUninitialize(); stopped.TrySetResult(null); }
|
||||
}) { IsBackground = true, Name = "dsh-cua-uia" };
|
||||
thread.SetApartmentState(ApartmentState.MTA);
|
||||
thread.Start();
|
||||
@@ -93,7 +93,7 @@ internal sealed class ServiceControl : Forms.Control
|
||||
internal sealed class StaDispatcher : IAsyncDisposable
|
||||
{
|
||||
private readonly TaskCompletionSource<ServiceControl> ready = new(TaskCreationOptions.RunContinuationsAsynchronously);
|
||||
private readonly TaskCompletionSource stopped = new(TaskCreationOptions.RunContinuationsAsynchronously);
|
||||
private readonly TaskCompletionSource<object?> stopped = new(TaskCreationOptions.RunContinuationsAsynchronously);
|
||||
private readonly ConcurrentDictionary<nint, long> epochs = new();
|
||||
private readonly Thread thread;
|
||||
private Win32.WinEvent? windowEvents;
|
||||
@@ -122,7 +122,7 @@ internal sealed class StaDispatcher : IAsyncDisposable
|
||||
finally
|
||||
{
|
||||
if (hook != 0) Win32.UnhookWinEvent(hook);
|
||||
stopped.TrySetResult();
|
||||
stopped.TrySetResult(null);
|
||||
}
|
||||
}) { IsBackground = true, Name = "dsh-cua-clipboard" };
|
||||
thread.SetApartmentState(ApartmentState.STA);
|
||||
|
||||
@@ -33,7 +33,7 @@ internal static class NativeServer
|
||||
await using var sta = new StaDispatcher();
|
||||
await sta.Invoke(() => { }, lifetime.Token);
|
||||
await mta.Invoke(() => true, lifetime.Token);
|
||||
await using var executor = new DesktopExecutor(mta, sta, graceMs);
|
||||
await using var executor = new DesktopExecutor(mta, sta);
|
||||
var clients = new ConcurrentDictionary<Task, byte>();
|
||||
NamedPipeServerStream? listener = NewPipe(pipeName);
|
||||
var membership = new object();
|
||||
@@ -162,6 +162,7 @@ internal static class NativeServer
|
||||
try { response = new { id = request.Id, result = await operation }; }
|
||||
catch (OperationCanceledException) { response = Failure(request.Id, "NATIVE_CANCELLED", "Native operation cancelled; observe before deciding on further input"); }
|
||||
catch (NativeFailure error) { response = Failure(request.Id, error.Code, error.Message); }
|
||||
catch (NotImplementedException error) { response = Failure(request.Id, "NOT_IMPLEMENTED", error.Message); }
|
||||
catch (ElementNotAvailableException) { response = Failure(request.Id, "STALE_SNAPSHOT", "An accessibility element disappeared; read fresh state"); }
|
||||
catch (ElementNotEnabledException) { response = Failure(request.Id, "ELEMENT_DISABLED", "The selected control is disabled"); }
|
||||
catch (UnauthorizedAccessException) { response = Failure(request.Id, "PERMISSION_DENIED", "Windows refused access to the selected application"); }
|
||||
|
||||
@@ -1,243 +1,7 @@
|
||||
// Windows Graphics Capture returns the selected window even when another window covers it.
|
||||
using System.Drawing;
|
||||
using System.Drawing.Imaging;
|
||||
using System.Runtime.InteropServices;
|
||||
using DeepSeek.Cua.Protocol;
|
||||
using Vortice.Direct3D;
|
||||
using Vortice.Direct3D11;
|
||||
using Vortice.DXGI;
|
||||
using WinRT;
|
||||
using global::Windows.Graphics.Capture;
|
||||
using global::Windows.Graphics.DirectX;
|
||||
using global::Windows.Graphics.DirectX.Direct3D11;
|
||||
|
||||
namespace DeepSeek.Cua.Windows;
|
||||
|
||||
internal sealed class WindowCapture : IAsyncDisposable
|
||||
internal sealed class WindowCapture
|
||||
{
|
||||
private readonly MtaDispatcher dispatcher = new();
|
||||
private readonly CaptureAdmission admission = new();
|
||||
private ID3D11Device? device;
|
||||
private ID3D11DeviceContext? immediate;
|
||||
private IDirect3DDevice? captureDevice;
|
||||
|
||||
internal Task<bool> IsSupported(CancellationToken cancellation)
|
||||
=> dispatcher.Invoke(GraphicsCaptureSession.IsSupported, cancellation);
|
||||
|
||||
private void EnsureDevice()
|
||||
{
|
||||
if (device is not null) return;
|
||||
var created = D3D11.D3D11CreateDevice(DriverType.Hardware, DeviceCreationFlags.BgraSupport);
|
||||
try
|
||||
{
|
||||
using var dxgi = created.QueryInterface<IDXGIDevice>();
|
||||
Marshal.ThrowExceptionForHR(CreateDirect3D11DeviceFromDXGIDevice(dxgi.NativePointer, out var pointer));
|
||||
try { captureDevice = MarshalInterface<IDirect3DDevice>.FromAbi(pointer); }
|
||||
finally { Marshal.Release(pointer); }
|
||||
immediate = created.ImmediateContext;
|
||||
device = created;
|
||||
}
|
||||
catch { created.Dispose(); throw; }
|
||||
}
|
||||
|
||||
internal async Task<object> Capture(AppState app, WindowState window, RequestContext context)
|
||||
{
|
||||
if (!await IsSupported(context.Cancellation)) throw new NativeFailure("UNSUPPORTED", "Windows Graphics Capture is unavailable on this desktop");
|
||||
var geometry = window.Geometry(app, context);
|
||||
if (!window.IsOnScreen()) throw new NativeFailure("WINDOW_NOT_VISIBLE", "Restore the selected window with show and observe again before capturing");
|
||||
try
|
||||
{
|
||||
var operation = admission.Start(() => CaptureOwned(window.Handle, geometry, context));
|
||||
var data = await operation.WaitAsync(context.Cancellation);
|
||||
var current = window.Geometry(app, context);
|
||||
if (current.Pixels.Width != geometry.Pixels.Width || current.Pixels.Height != geometry.Pixels.Height || current.Dpi != geometry.Dpi)
|
||||
throw new NativeFailure("WINDOW_CHANGED", "The window changed during capture; observe again");
|
||||
DesktopSession.RequireInteractive();
|
||||
window.Observe(current);
|
||||
return new { mimeType = "image/png", data = Convert.ToBase64String(data), pixelWidth = geometry.Pixels.Width,
|
||||
pixelHeight = geometry.Pixels.Height, windowId = window.Id, bounds = current.Bounds, coordinateSpace = "window-pixels" };
|
||||
}
|
||||
catch (COMException error)
|
||||
{
|
||||
throw new NativeFailure(error.HResult == unchecked((int)0x80070005) ? "PERMISSION_DENIED" : "CAPTURE_FAILED",
|
||||
$"Windows refused the selected window capture (0x{error.HResult:X8}); restore the window and read fresh state");
|
||||
}
|
||||
}
|
||||
|
||||
private async Task<byte[]> CaptureOwned(nint window, WindowGeometry geometry, RequestContext context)
|
||||
{
|
||||
CaptureRequest? request = null;
|
||||
try
|
||||
{
|
||||
await dispatcher.Invoke(() =>
|
||||
{
|
||||
EnsureDevice();
|
||||
request = new CaptureRequest(this, window, geometry, context);
|
||||
return true;
|
||||
}, context.Cancellation);
|
||||
return await request!.Result.WaitAsync(context.Cancellation);
|
||||
}
|
||||
finally
|
||||
{
|
||||
if (request is not null) await dispatcher.Invoke(() => { request.Dispose(); return true; }, CancellationToken.None);
|
||||
}
|
||||
}
|
||||
|
||||
private sealed class CaptureRequest : IDisposable
|
||||
{
|
||||
private readonly object gate = new();
|
||||
private readonly TaskCompletionSource<byte[]> result = new(TaskCreationOptions.RunContinuationsAsynchronously);
|
||||
private readonly WindowCapture owner;
|
||||
private readonly WindowGeometry geometry;
|
||||
private readonly RequestContext context;
|
||||
private readonly GraphicsCaptureItem item;
|
||||
private Direct3D11CaptureFramePool? pool;
|
||||
private GraphicsCaptureSession? session;
|
||||
private bool disposed;
|
||||
|
||||
internal Task<byte[]> Result => result.Task;
|
||||
|
||||
internal CaptureRequest(WindowCapture owner, nint window, WindowGeometry geometry, RequestContext context)
|
||||
{
|
||||
this.owner = owner; this.geometry = geometry; this.context = context;
|
||||
item = ItemForWindow(window);
|
||||
if (item.Size.Width != geometry.Pixels.Width || item.Size.Height != geometry.Pixels.Height)
|
||||
throw new NativeFailure("WINDOW_CHANGED", "Windows capture bounds differ from the observed window; restore it and observe again");
|
||||
try
|
||||
{
|
||||
pool = Direct3D11CaptureFramePool.CreateFreeThreaded(owner.captureDevice!, DirectXPixelFormat.B8G8R8A8UIntNormalized, 2, item.Size);
|
||||
pool.FrameArrived += Frame;
|
||||
item.Closed += Closed;
|
||||
session = pool.CreateCaptureSession(item);
|
||||
session.IsCursorCaptureEnabled = false;
|
||||
session.StartCapture();
|
||||
}
|
||||
catch { Dispose(); throw; }
|
||||
}
|
||||
|
||||
private void Closed(GraphicsCaptureItem sender, object args) => result.TrySetException(new NativeFailure("WINDOW_CHANGED", "The selected window closed during capture"));
|
||||
|
||||
private void Frame(Direct3D11CaptureFramePool sender, object args)
|
||||
{
|
||||
lock (gate)
|
||||
{
|
||||
if (disposed || result.Task.IsCompleted) return;
|
||||
try
|
||||
{
|
||||
context.Check();
|
||||
using var frame = sender.TryGetNextFrame();
|
||||
if (frame is null) return;
|
||||
if (frame.ContentSize.Width != geometry.Pixels.Width || frame.ContentSize.Height != geometry.Pixels.Height)
|
||||
throw new NativeFailure("WINDOW_CHANGED", "The capture frame dimensions changed");
|
||||
result.TrySetResult(owner.Encode(frame.Surface, geometry.Pixels.Width, geometry.Pixels.Height, context));
|
||||
}
|
||||
catch (Exception error) { result.TrySetException(error); }
|
||||
}
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
lock (gate)
|
||||
{
|
||||
if (disposed) return;
|
||||
disposed = true;
|
||||
item.Closed -= Closed;
|
||||
if (pool is not null) pool.FrameArrived -= Frame;
|
||||
}
|
||||
// Native disposal can wait for callbacks; queued callbacks must be able to observe disposed.
|
||||
session?.Dispose();
|
||||
pool?.Dispose();
|
||||
}
|
||||
}
|
||||
|
||||
private byte[] Encode(IDirect3DSurface surface, int width, int height, RequestContext context)
|
||||
{
|
||||
var access = surface.As<IDirect3DDxgiInterfaceAccess>();
|
||||
var textureId = typeof(ID3D11Texture2D).GUID;
|
||||
Marshal.ThrowExceptionForHR(access.GetInterface(ref textureId, out var pointer));
|
||||
using var texture = new ID3D11Texture2D(pointer);
|
||||
if (texture.Description.Width != width || texture.Description.Height != height || texture.Description.Format != Format.B8G8R8A8_UNorm)
|
||||
throw new NativeFailure("WINDOW_CHANGED", "The captured texture differs from the selected window geometry");
|
||||
var description = new Texture2DDescription(Format.B8G8R8A8_UNorm, (uint)width, (uint)height,
|
||||
mipLevels: 1, bindFlags: BindFlags.None, usage: ResourceUsage.Staging, cpuAccessFlags: CpuAccessFlags.Read);
|
||||
using var staging = device!.CreateTexture2D(description);
|
||||
immediate!.CopyResource(staging, texture);
|
||||
var mapped = immediate.Map(staging, 0, MapMode.Read);
|
||||
using var bitmap = new Bitmap(width, height, PixelFormat.Format32bppArgb);
|
||||
try
|
||||
{
|
||||
var pixels = bitmap.LockBits(new Rectangle(0, 0, width, height), ImageLockMode.WriteOnly, PixelFormat.Format32bppArgb);
|
||||
try
|
||||
{
|
||||
var row = new byte[checked(width * 4)];
|
||||
for (var y = 0; y < height; y++)
|
||||
{
|
||||
context.Check();
|
||||
Marshal.Copy(mapped.DataPointer + checked(y * (int)mapped.RowPitch), row, 0, row.Length);
|
||||
Marshal.Copy(row, 0, pixels.Scan0 + y * pixels.Stride, row.Length);
|
||||
}
|
||||
}
|
||||
finally { bitmap.UnlockBits(pixels); }
|
||||
}
|
||||
finally { immediate.Unmap(staging, 0); }
|
||||
context.Check();
|
||||
using var output = new MemoryStream();
|
||||
bitmap.Save(output, ImageFormat.Png);
|
||||
if (output.Length * 4 / 3 > context.Config.MaxResponseBytes)
|
||||
throw new NativeFailure("NATIVE_RESPONSE_LIMIT", "The screenshot exceeds the response byte limit");
|
||||
return output.ToArray();
|
||||
}
|
||||
|
||||
private static GraphicsCaptureItem ItemForWindow(nint window)
|
||||
{
|
||||
const string className = "Windows.Graphics.Capture.GraphicsCaptureItem";
|
||||
Marshal.ThrowExceptionForHR(WindowsCreateString(className, className.Length, out var name));
|
||||
nint factoryPointer = 0;
|
||||
object? factory = null;
|
||||
try
|
||||
{
|
||||
var factoryId = typeof(IGraphicsCaptureItemInterop).GUID;
|
||||
Marshal.ThrowExceptionForHR(RoGetActivationFactory(name, ref factoryId, out factoryPointer));
|
||||
factory = Marshal.GetObjectForIUnknown(factoryPointer);
|
||||
var itemId = new Guid("79C3F95B-31F7-4EC2-A464-632EF5D30760");
|
||||
Marshal.ThrowExceptionForHR(((IGraphicsCaptureItemInterop)factory).CreateForWindow(window, ref itemId, out var item));
|
||||
try { return MarshalInterface<GraphicsCaptureItem>.FromAbi(item); }
|
||||
finally { Marshal.Release(item); }
|
||||
}
|
||||
finally
|
||||
{
|
||||
if (factory is not null) Marshal.FinalReleaseComObject(factory);
|
||||
if (factoryPointer != 0) Marshal.Release(factoryPointer);
|
||||
WindowsDeleteString(name);
|
||||
}
|
||||
}
|
||||
|
||||
public async ValueTask DisposeAsync()
|
||||
{
|
||||
await admission.Join();
|
||||
await dispatcher.Invoke(() =>
|
||||
{
|
||||
captureDevice?.Dispose();
|
||||
immediate?.Dispose();
|
||||
device?.Dispose();
|
||||
return true;
|
||||
}, CancellationToken.None);
|
||||
await dispatcher.DisposeAsync();
|
||||
}
|
||||
|
||||
[ComImport, Guid("3628E81B-3CAC-4C60-B7F4-23CE0E0C3356"), InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
|
||||
private interface IGraphicsCaptureItemInterop
|
||||
{
|
||||
[PreserveSig] int CreateForWindow(nint window, ref Guid id, out nint item);
|
||||
[PreserveSig] int CreateForMonitor(nint monitor, ref Guid id, out nint item);
|
||||
}
|
||||
[ComImport, Guid("A9B3D012-3DF2-4EE3-B8D1-8695F457D3C1"), InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
|
||||
private interface IDirect3DDxgiInterfaceAccess
|
||||
{
|
||||
[PreserveSig] int GetInterface(ref Guid id, out nint value);
|
||||
}
|
||||
[DllImport("d3d11.dll", ExactSpelling = true)] private static extern int CreateDirect3D11DeviceFromDXGIDevice(nint device, out nint result);
|
||||
[DllImport("combase.dll", CharSet = CharSet.Unicode)] private static extern int WindowsCreateString(string source, int length, out nint value);
|
||||
[DllImport("combase.dll")] private static extern int WindowsDeleteString(nint value);
|
||||
[DllImport("combase.dll")] private static extern int RoGetActivationFactory(nint name, ref Guid id, out nint value);
|
||||
internal Task<object> Capture(AppState app, WindowState window, RequestContext context)
|
||||
=> throw new NotImplementedException("Windows screenshots are not implemented.");
|
||||
}
|
||||
@@ -1,7 +1,6 @@
|
||||
// Portable checks exercise admission, framing, text offsets, and model-visible formatting.
|
||||
using System.Text;
|
||||
using DeepSeek.Cua.Protocol;
|
||||
using DeepSeek.Cua.Windows;
|
||||
|
||||
var checks = 0;
|
||||
void Check(bool condition, string message)
|
||||
@@ -75,22 +74,4 @@ Check(!AccessibilityText.Retain(new() { Role = "AXGroup" }), "Empty structural c
|
||||
Check(AccessibilityText.Retain(new() { Role = "AXGroup", Actions = ["Copy"] }), "Actionable containers retain their row");
|
||||
Check(AccessibilityText.Format(new() { Role = "AXTextArea", Value = "abc", HasValue = true, HasSelection = true, Selection = new(2, 5) }, 0, false)
|
||||
.Contains("selection=unavailable"), "Out-of-range selections do not describe valid text");
|
||||
var captures = new CaptureAdmission();
|
||||
var cleanup = new TaskCompletionSource<byte[]>(TaskCreationOptions.RunContinuationsAsynchronously);
|
||||
var ownedCapture = captures.Start(() => cleanup.Task);
|
||||
using var cancelled = new CancellationTokenSource();
|
||||
cancelled.Cancel();
|
||||
try { await ownedCapture.WaitAsync(cancelled.Token); throw new Exception("Cancelled capture caller remained attached"); }
|
||||
catch (OperationCanceledException) { checks++; }
|
||||
Refuses(() => captures.Start(() => Task.FromResult(new byte[] { 2 })), "CAPTURE_BUSY");
|
||||
var joined = captures.Join();
|
||||
Check(!joined.IsCompleted, "Native cleanup retains ownership after its caller stops waiting");
|
||||
cleanup.SetResult([1]);
|
||||
await joined;
|
||||
Check((await captures.Start(() => Task.FromResult(new byte[] { 2 })))[0] == 2, "Completed cleanup admits a fresh capture");
|
||||
var failed = captures.Start(() => Task.FromException<byte[]>(new NativeFailure("CAPTURE_FAILED", "device lost")));
|
||||
try { await failed; throw new Exception("Capture error disappeared"); }
|
||||
catch (NativeFailure failure) { Check(failure.Code == "CAPTURE_FAILED", "Capture failure remains attached to its requesting connection"); }
|
||||
await captures.Join();
|
||||
Check((await captures.Start(() => Task.FromResult(new byte[] { 3 })))[0] == 3, "A settled capture failure does not reserve a permanent slot");
|
||||
Console.WriteLine($"{checks} portable CUA checks passed");
|
||||
@@ -1,11 +1,10 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
<PropertyGroup>
|
||||
<OutputType>Exe</OutputType>
|
||||
<TargetFramework>net10.0</TargetFramework>
|
||||
<TargetFramework>net48</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
<RestorePackagesWithLockFile>true</RestorePackagesWithLockFile>
|
||||
</PropertyGroup>
|
||||
<ItemGroup><ProjectReference Include="../protocol/CuaProtocol.csproj" /></ItemGroup>
|
||||
<ItemGroup><Compile Include="../src/CaptureAdmission.cs" Link="CaptureAdmission.cs" /></ItemGroup>
|
||||
</Project>
|
||||
@@ -1,16 +1,56 @@
|
||||
{
|
||||
"version": 1,
|
||||
"dependencies": {
|
||||
"net10.0": {
|
||||
".NETFramework,Version=v4.8": {
|
||||
"Microsoft.NETFramework.ReferenceAssemblies": {
|
||||
"type": "Direct",
|
||||
"requested": "[1.0.3, )",
|
||||
"resolved": "1.0.3",
|
||||
"contentHash": "vUc9Npcs14QsyOD01tnv/m8sQUnGTGOw1BCmKcv77LBJY7OxhJ+zJF7UD/sCL3lYNFuqmQEVlkfS4Quif6FyYg==",
|
||||
"dependencies": {
|
||||
"Microsoft.NETFramework.ReferenceAssemblies.net48": "1.0.3"
|
||||
}
|
||||
},
|
||||
"PolySharp": {
|
||||
"type": "Direct",
|
||||
"requested": "[1.15.0, )",
|
||||
"resolved": "1.15.0",
|
||||
"contentHash": "FbU0El+EEjdpuIX4iDbeS7ki1uzpJPx8vbqOzEtqnl1GZeAGJfq+jCbxeJL2y0EPnUNk8dRnnqR2xnYXg9Tf+g=="
|
||||
},
|
||||
"System.Text.Json": {
|
||||
"type": "Direct",
|
||||
"requested": "[10.0.14, 10.0.14]",
|
||||
"resolved": "10.0.14",
|
||||
"contentHash": "JSSLGJTJJDvS76VnLdY1X289rFcHuYApk7QGw0hCoP5wVR1mk7BvJbOYxQLXq4x1qK/Ml9OHa/AKaAbBVCfSSQ==",
|
||||
"dependencies": {
|
||||
"Microsoft.Bcl.AsyncInterfaces": "10.0.14",
|
||||
"System.Buffers": "4.6.1",
|
||||
"System.IO.Pipelines": "10.0.14",
|
||||
"System.Memory": "4.6.3",
|
||||
"System.Runtime.CompilerServices.Unsafe": "6.1.2",
|
||||
"System.Text.Encodings.Web": "10.0.14",
|
||||
"System.Threading.Tasks.Extensions": "4.6.3",
|
||||
"System.ValueTuple": "4.6.2"
|
||||
}
|
||||
},
|
||||
"Humanizer.Core": {
|
||||
"type": "Transitive",
|
||||
"resolved": "3.0.10",
|
||||
"contentHash": "yZIhtw8sYuvsONzQbZxWpR60tMWYHXoo0DL6nyOqSFiU5POjBTSEyWFpTQtJEZuy+oqiYTXKXY/Mjx7KnqIQFw=="
|
||||
"contentHash": "yZIhtw8sYuvsONzQbZxWpR60tMWYHXoo0DL6nyOqSFiU5POjBTSEyWFpTQtJEZuy+oqiYTXKXY/Mjx7KnqIQFw==",
|
||||
"dependencies": {
|
||||
"System.Collections.Immutable": "9.0.10",
|
||||
"System.ComponentModel.Annotations": "5.0.0",
|
||||
"System.Memory": "4.6.3"
|
||||
}
|
||||
},
|
||||
"Json.More.Net": {
|
||||
"type": "Transitive",
|
||||
"resolved": "3.0.1",
|
||||
"contentHash": "fRctF2J2SILYG6wqP21drmeEODmCVkVQ/b3MndDu2fT1swfySyUgq7ePCk+aENGlDcIm05fyfjh9vcuqDEfv3w=="
|
||||
"contentHash": "fRctF2J2SILYG6wqP21drmeEODmCVkVQ/b3MndDu2fT1swfySyUgq7ePCk+aENGlDcIm05fyfjh9vcuqDEfv3w==",
|
||||
"dependencies": {
|
||||
"System.Collections.Immutable": "10.0.5",
|
||||
"System.Text.Json": "10.0.5"
|
||||
}
|
||||
},
|
||||
"JsonPointer.Net": {
|
||||
"type": "Transitive",
|
||||
@@ -29,12 +69,99 @@
|
||||
"JsonPointer.Net": "7.0.2"
|
||||
}
|
||||
},
|
||||
"Microsoft.Bcl.AsyncInterfaces": {
|
||||
"type": "Transitive",
|
||||
"resolved": "10.0.14",
|
||||
"contentHash": "HCu9NbiXDh9++j4eRNRHCOiKPw/7I5UEJlFIRaDM3v0+ttZaH8p8rjxSWfNgP2cGv5JAa4EZnmc/nlcUOTFlpA==",
|
||||
"dependencies": {
|
||||
"System.Threading.Tasks.Extensions": "4.6.3"
|
||||
}
|
||||
},
|
||||
"Microsoft.NETFramework.ReferenceAssemblies.net48": {
|
||||
"type": "Transitive",
|
||||
"resolved": "1.0.3",
|
||||
"contentHash": "zMk4D+9zyiEWByyQ7oPImPN/Jhpj166Ky0Nlla4eXlNL8hI/BtSJsgR8Inldd4NNpIAH3oh8yym0W2DrhXdSLQ=="
|
||||
},
|
||||
"System.Buffers": {
|
||||
"type": "Transitive",
|
||||
"resolved": "4.6.1",
|
||||
"contentHash": "N8GXpmiLMtljq7gwvyS+1QvKT/W2J8sNAvx+HVg4NGmsG/H+2k/y9QI23auLJRterrzCiDH+IWAw4V/GPwsMlw=="
|
||||
},
|
||||
"System.Collections.Immutable": {
|
||||
"type": "Transitive",
|
||||
"resolved": "10.0.5",
|
||||
"contentHash": "nozrOKfEgfrvvswkCfxaumY68RA/x1F3ZYwtwRvva8ul91NCnUzb6MKpl5/P7u9v/nIagVL4OXXj8d007tucxw==",
|
||||
"dependencies": {
|
||||
"System.Memory": "4.6.3",
|
||||
"System.Runtime.CompilerServices.Unsafe": "6.1.2"
|
||||
}
|
||||
},
|
||||
"System.ComponentModel.Annotations": {
|
||||
"type": "Transitive",
|
||||
"resolved": "5.0.0",
|
||||
"contentHash": "dMkqfy2el8A8/I76n2Hi1oBFEbG1SfxD2l5nhwXV3XjlnOmwxJlQbYpJH4W51odnU9sARCSAgv7S3CyAFMkpYg=="
|
||||
},
|
||||
"System.IO.Pipelines": {
|
||||
"type": "Transitive",
|
||||
"resolved": "10.0.14",
|
||||
"contentHash": "pLVClkIC4XfXhcOQXNtNDJl5LYJOS4XAQAdzbqF8rj6sk2zdXO/5uikBsZqgqnAAb07z9Fmtu0sMj3TwEiBtIw==",
|
||||
"dependencies": {
|
||||
"System.Buffers": "4.6.1",
|
||||
"System.Memory": "4.6.3",
|
||||
"System.Threading.Tasks.Extensions": "4.6.3"
|
||||
}
|
||||
},
|
||||
"System.Memory": {
|
||||
"type": "Transitive",
|
||||
"resolved": "4.6.3",
|
||||
"contentHash": "qdcDOgnFZY40+Q9876JUHnlHu7bosOHX8XISRoH94fwk6hgaeQGSgfZd8srWRZNt5bV9ZW2TljcegDNxsf+96A==",
|
||||
"dependencies": {
|
||||
"System.Buffers": "4.6.1",
|
||||
"System.Numerics.Vectors": "4.6.1",
|
||||
"System.Runtime.CompilerServices.Unsafe": "6.1.2"
|
||||
}
|
||||
},
|
||||
"System.Numerics.Vectors": {
|
||||
"type": "Transitive",
|
||||
"resolved": "4.6.1",
|
||||
"contentHash": "sQxefTnhagrhoq2ReR0D/6K0zJcr9Hrd6kikeXsA1I8kOCboTavcUC4r7TSfpKFeE163uMuxZcyfO1mGO3EN8Q=="
|
||||
},
|
||||
"System.Runtime.CompilerServices.Unsafe": {
|
||||
"type": "Transitive",
|
||||
"resolved": "6.1.2",
|
||||
"contentHash": "2hBr6zdbIBTDE3EhK7NSVNdX58uTK6iHW/P/Axmm9sl1xoGSLqDvMtpecn226TNwHByFokYwJmt/aQQNlO5CRw=="
|
||||
},
|
||||
"System.Text.Encodings.Web": {
|
||||
"type": "Transitive",
|
||||
"resolved": "10.0.14",
|
||||
"contentHash": "+aDpFLtsHyft9ZVx9pZQ9MILqwrr8LK1te1L39VMKQYhoYDbs+RUqBhCT3Zydb5ymi2Buo4Cn+3Wi208IxD6rw==",
|
||||
"dependencies": {
|
||||
"System.Buffers": "4.6.1",
|
||||
"System.Memory": "4.6.3",
|
||||
"System.Runtime.CompilerServices.Unsafe": "6.1.2"
|
||||
}
|
||||
},
|
||||
"System.Threading.Tasks.Extensions": {
|
||||
"type": "Transitive",
|
||||
"resolved": "4.6.3",
|
||||
"contentHash": "7sCiwilJLYbTZELaKnc7RecBBXWXA+xMLQWZKWawBxYjp6DBlSE3v9/UcvKBvr1vv2tTOhipiogM8rRmxlhrVA==",
|
||||
"dependencies": {
|
||||
"System.Runtime.CompilerServices.Unsafe": "6.1.2"
|
||||
}
|
||||
},
|
||||
"System.ValueTuple": {
|
||||
"type": "Transitive",
|
||||
"resolved": "4.6.2",
|
||||
"contentHash": "yQgmjfFximrNm9LIV3mL6T5MzjeC+epeE5rl4hXxAlYmxby7RM1dPSkIKXk9HNkl6G54h2JHOmLD46+Pey+IRg=="
|
||||
},
|
||||
"cuaprotocol": {
|
||||
"type": "Project",
|
||||
"dependencies": {
|
||||
"JsonSchema.Net": "[9.4.0, )"
|
||||
"JsonSchema.Net": "[9.4.0, )",
|
||||
"System.Text.Json": "[10.0.14, 10.0.14]"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
".NETFramework,Version=v4.8/win-x86": {}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -86,7 +86,7 @@
|
||||
"src"
|
||||
],
|
||||
"scripts": {
|
||||
"build:native": "dotnet publish native/CuaWindows.csproj --configuration Release --runtime win-x64 --self-contained true -p:PublishSingleFile=true -p:IncludeNativeLibrariesForSelfExtract=true -p:EnableWindowsTargeting=true"
|
||||
"build:native": "dotnet build native/CuaWindows.csproj --configuration Release --framework net48"
|
||||
},
|
||||
"os": [
|
||||
"win32",
|
||||
|
||||
Reference in new issue
Block a user