Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

新增UseLocalStorage支持 #9

Merged
merged 1 commit into from
Jun 20, 2024
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
105 changes: 64 additions & 41 deletions Samples/WindowsHighlightSample/MainForm.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
using System.Collections.Concurrent;
using System.Globalization;
using System.Text;
using System.Text.Json;
using FlaUI.Core.AutomationElements;
using Mortise.Accessibility.Abstractions;
using Mortise.Accessibility.Locator.Abstractions;
using Mortise.UiaAccessibility;
using Tenon.Automation.Windows;
using Tenon.Infra.Windows.Form.Common;
Expand All @@ -21,17 +21,20 @@
private readonly Accessible _accessible;
private readonly string[] _ignoreProcessNames;
private readonly ISerializer _serializer;
private readonly IAccessibleLocatorStorage _accessibleLocatorStorage;
private readonly WindowsHighlightRectangle _windowsHighlight;
protected readonly ConcurrentStack<MouseEventArgs> MouseDownQueue = new();
protected readonly ConcurrentStack<MouseEventArgs> MouseMoveQueue = new();
private bool _isLeftControl;
private bool _shutdown;
protected Thread? WorkerThread;

public MainForm(Accessible accessible, ISerializer serializer)
public MainForm(Accessible accessible, ISerializer serializer, IAccessibleLocatorStorage accessibleLocatorStorage)
{
_accessible = accessible ?? throw new ArgumentNullException(nameof(accessible));
_serializer = serializer;
_accessibleLocatorStorage = accessibleLocatorStorage ??
throw new ArgumentNullException(nameof(accessibleLocatorStorage));
InitializeComponent();
_windowsHighlight = new WindowsHighlightRectangle();
_ignoreProcessNames = [Process.GetCurrentProcess().ProcessName];
Expand Down Expand Up @@ -213,11 +216,12 @@
if (buttonTest != null)
{
buttonTest?.Invoke();
_accessible.Record(buttonTest);

Check warning on line 219 in Samples/WindowsHighlightSample/MainForm.cs

View workflow job for this annotation

GitHub Actions / build

Possible null reference argument for parameter 'component' in 'void Accessible.Record(object component)'.

Check warning on line 219 in Samples/WindowsHighlightSample/MainForm.cs

View workflow job for this annotation

GitHub Actions / build

Possible null reference argument for parameter 'component' in 'void Accessible.Record(object component)'.
var jsonString = _serializer.SerializeObject(_accessible);

var jsonString = _serializer.SerializeObject(_accessible);
File.WriteAllText("locator.path", jsonString, Encoding.UTF8);
var findElement = _accessible.FindComponent(jsonString);
var accessible1 = _serializer.DeserializeObject<UiaAccessible>(jsonString);
var findElement = _accessible.FindComponent(accessible1);
AddLog(findElement != null ? "find Element" : "not find Element");
if (findElement is UiaAccessibleComponent component)
component.Click();
Expand All @@ -242,42 +246,61 @@
var accessibleDict =
new ConcurrentDictionary<string, Accessible>(StringComparer.OrdinalIgnoreCase);
var locator1 = @"{
""fileName"": ""CalculatorApp"",
""provider"": ""Uia"",
""platform"": ""Win32NT"",
""version"": ""3.0.0"",
""components"": [
{
""name"": ""¼ÆËãÆ÷"",
""controlType"": ""Window"",
""isDialog"": false,
""id"": null
},
{
""name"": null,
""controlType"": ""Custom"",
""isDialog"": false,
""id"": ""NavView""
},
{
""name"": null,
""controlType"": ""Group"",
""isDialog"": false,
""id"": null
},
{
""name"": ""Êý×Ö¼üÅÌ"",
""controlType"": ""Group"",
""isDialog"": false,
""id"": ""NumberPad""
},
{
""name"": ""Ò»"",
""controlType"": ""Button"",
""isDialog"": false,
""id"": ""num1Button""
}
]
""uniqueId"": ""num1Button"",
""fileName"": ""CalculatorApp"",
""provider"": ""Uia"",
""platform"": ""Win32NT"",
""version"": ""3.0.0"",
""components"": [
{
""className"": ""ApplicationFrameWindow"",
""name"": ""\u8BA1\u7B97\u5668"",
""controlType"": ""Window"",
""isDialog"": false,
""id"": null,
""isPassword"": false
},
{
""className"": ""Windows.UI.Core.CoreWindow"",
""name"": ""\u8BA1\u7B97\u5668"",
""controlType"": ""Window"",
""isDialog"": false,
""id"": null,
""isPassword"": false
},
{
""className"": null,
""name"": null,
""controlType"": ""Custom"",
""isDialog"": false,
""id"": ""NavView"",
""isPassword"": false
},
{
""className"": ""LandmarkTarget"",
""name"": null,
""controlType"": ""Group"",
""isDialog"": false,
""id"": null,
""isPassword"": false
},
{
""className"": ""NamedContainerAutomationPeer"",
""name"": ""\u6570\u5B57\u952E\u76D8"",
""controlType"": ""Group"",
""isDialog"": false,
""id"": ""NumberPad"",
""isPassword"": false
},
{
""className"": ""Button"",
""name"": ""\u4E00"",
""controlType"": ""Button"",
""isDialog"": false,
""id"": ""num1Button"",
""isPassword"": false
}
]
}";
var accessible1 = _serializer.DeserializeObject<UiaAccessible>(locator1);
AddLog(accessible1.FileName);
Expand Down
4 changes: 4 additions & 0 deletions Samples/WindowsHighlightSample/Program.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
using Microsoft.Extensions.DependencyInjection;
using Mortise.Accessibility.Locator.Json.Configurations;
using Mortise.Accessibility.Locator.Json.Extensions;
using Mortise.UiaAccessibility.Converters;
using Mortise.UiaAccessibility.Extensions;
using Mortise.UiaAccessibility.WeChat.Configurations;

Expand Down Expand Up @@ -37,5 +40,6 @@ private static void ConfigureServices(ServiceCollection services)
{
services.AddScoped<MainForm>();
services.AddUiaAccessible(option => { option.AddWeChatAccessible(); });
services.AddJsonLocator(option => { option.UseLocalStorage(); }, [new UiaAccessibleComponentConverter()]);
}
}
14 changes: 11 additions & 3 deletions Samples/WindowsHighlightSample/WindowsHighlightSample.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,11 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Mortise.Accessibility.Abstractions" Version="0.0.1-alpha-202406190206" />
<PackageReference Include="Mortise.UiaAccessibility" Version="0.0.1-alpha-202406190206" />
<PackageReference Include="Mortise.UiaAccessibility.WeChat" Version="0.0.1-alpha-202406190206" />
<PackageReference Include="Mortise.Accessibility.Abstractions" Version="0.0.1-alpha-202406201222" />
<PackageReference Include="Mortise.Accessibility.Locator.Abstractions" Version="0.0.1-alpha-202406201222" />
<PackageReference Include="Mortise.Accessibility.Locator.Json" Version="0.0.1-alpha-202406201222" />
<PackageReference Include="Mortise.UiaAccessibility" Version="0.0.1-alpha-202406201222" />
<PackageReference Include="Mortise.UiaAccessibility.WeChat" Version="0.0.1-alpha-202406201222" />
<PackageReference Include="System.Drawing.Common" Version="8.0.6" />
<PackageReference Include="Tenon.Automation.Windows" Version="0.0.1-alpha-202406141611" />
<PackageReference Include="Tenon.Helper" Version="0.0.1-alpha-202406141611" />
Expand All @@ -27,6 +29,12 @@
<Reference Include="Mortise.Accessibility.Abstractions">
<HintPath>..\..\..\Mortise\src\Mortise.Accessibility.Abstractions\bin\Debug\net8.0\Mortise.Accessibility.Abstractions.dll</HintPath>
</Reference>
<Reference Include="Mortise.Accessibility.Locator.Abstractions">
<HintPath>..\..\..\Mortise\src\Mortise.Accessibility.Locator.Json\bin\Debug\net8.0\Mortise.Accessibility.Locator.Abstractions.dll</HintPath>
</Reference>
<Reference Include="Mortise.Accessibility.Locator.Json">
<HintPath>..\..\..\Mortise\src\Mortise.Accessibility.Locator.Json\bin\Debug\net8.0\Mortise.Accessibility.Locator.Json.dll</HintPath>
</Reference>
<Reference Include="Mortise.UiaAccessibility">
<HintPath>..\..\..\Mortise\src\UIA\Mortise.UIAAccessibility\bin\Debug\net8.0-windows\Mortise.UiaAccessibility.dll</HintPath>
</Reference>
Expand Down