Skip to content

Commit

Permalink
新增依赖注入处理
Browse files Browse the repository at this point in the history
  • Loading branch information
YanZhiwei committed Jun 20, 2024
1 parent 20a6dbb commit 3af53f3
Show file tree
Hide file tree
Showing 10 changed files with 399 additions and 53 deletions.
32 changes: 26 additions & 6 deletions Recorder.Desktop/Program.cs
Original file line number Diff line number Diff line change
@@ -1,23 +1,43 @@
using System;

using Avalonia;
using Microsoft.Extensions.DependencyInjection;
using Mortise.Accessibility.Locator.Json.Extensions;
using Mortise.UiaAccessibility.Converters;
using Mortise.UiaAccessibility.Extensions;
using Mortise.UiaAccessibility.WeChat.Configurations;

namespace Recorder.Desktop;

class Program
internal class Program
{
public static IServiceProvider ServiceProvider { get; set; }

Check warning on line 13 in Recorder.Desktop/Program.cs

View workflow job for this annotation

GitHub Actions / build

Non-nullable property 'ServiceProvider' must contain a non-null value when exiting constructor. Consider declaring the property as nullable.

Check warning on line 13 in Recorder.Desktop/Program.cs

View workflow job for this annotation

GitHub Actions / build

Non-nullable property 'ServiceProvider' must contain a non-null value when exiting constructor. Consider declaring the property as nullable.

// Initialization code. Don't use any Avalonia, third-party APIs or any
// SynchronizationContext-reliant code before AppMain is called: things aren't initialized
// yet and stuff might break.
[STAThread]
public static void Main(string[] args) => BuildAvaloniaApp()
.StartWithClassicDesktopLifetime(args);
public static void Main(string[] args)
{
BuildAvaloniaApp()
.StartWithClassicDesktopLifetime(args);
}

// Avalonia configuration, don't remove; also used by visual designer.
public static AppBuilder BuildAvaloniaApp()
=> AppBuilder.Configure<App>()
{
ServiceProvider = ConfigureServices();
return AppBuilder.Configure<App>()
.UsePlatformDetect()
.WithInterFont()
.LogToTrace();
}


}
private static IServiceProvider ConfigureServices()
{
var services = new ServiceCollection();
services.AddUiaAccessible(option => { option.AddWeChatAccessible(); });
services.AddJsonLocator(option => { option.UseLocalStorage(); }, [new UiaAccessibleComponentConverter()]);
return services.BuildServiceProvider();
}
}
25 changes: 24 additions & 1 deletion Recorder.Desktop/Recorder.Desktop.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,41 @@
<OutputType>WinExe</OutputType>
<!--If you are willing to use Windows/MacOS native APIs you will need to create 3 projects.
One for Windows with net7.0-windows TFM, one for MacOS with net7.0-macos and one with net7.0 TFM for Linux.-->
<TargetFramework>net8.0</TargetFramework>
<TargetFramework>net8.0-windows</TargetFramework>
<Nullable>enable</Nullable>
<BuiltInComInteropSupport>true</BuiltInComInteropSupport>
<ApplicationManifest>app.manifest</ApplicationManifest>
<Platforms>AnyCPU;x86;x64</Platforms>
</PropertyGroup>
<ItemGroup>
<None Remove="app.manifest" />
</ItemGroup>
<ItemGroup>
<AdditionalFiles Include="app.manifest" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="Avalonia.Desktop" Version="11.0.10" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="8.0.0" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="8.0.1" />
<PackageReference Include="Microsoft.Extensions.Options" Version="8.0.2" />
<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" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\Recorder\Recorder.csproj" />
</ItemGroup>

<ItemGroup>
<None Update="locators\Calculator.locator">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Update="locators\CalculatorApp.locator">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
</ItemGroup>
</Project>
81 changes: 68 additions & 13 deletions Recorder.Desktop/app.manifest
Original file line number Diff line number Diff line change
@@ -1,18 +1,73 @@
<?xml version="1.0" encoding="utf-8"?>
<assembly manifestVersion="1.0" xmlns="urn:schemas-microsoft-com:asm.v1">
<!-- This manifest is used on Windows only.
Don't remove it as it might cause problems with window transparency and embeded controls.
For more details visit https://learn.microsoft.com/en-us/windows/win32/sbscs/application-manifests -->
<assemblyIdentity version="1.0.0.0" name="AvaloniaTest.Desktop"/>
<assemblyIdentity version="1.0.0.0" name="MyApplication.app"/>
<trustInfo xmlns="urn:schemas-microsoft-com:asm.v2">
<security>
<requestedPrivileges xmlns="urn:schemas-microsoft-com:asm.v3">
<!-- UAC 清单选项
如果想要更改 Windows 用户帐户控制级别,请使用
以下节点之一替换 requestedExecutionLevel 节点。n
<requestedExecutionLevel level="asInvoker" uiAccess="false" />
<requestedExecutionLevel level="requireAdministrator" uiAccess="false" />
<requestedExecutionLevel level="highestAvailable" uiAccess="false" />
<compatibility xmlns="urn:schemas-microsoft-com:compatibility.v1">
<application>
<!-- A list of the Windows versions that this application has been tested on
and is designed to work with. Uncomment the appropriate elements
and Windows will automatically select the most compatible environment. -->
指定 requestedExecutionLevel 元素将禁用文件和注册表虚拟化。
如果你的应用程序需要此虚拟化来实现向后兼容性,则删除此
元素。
-->
<requestedExecutionLevel level="asInvoker" uiAccess="false" />
</requestedPrivileges>
<applicationRequestMinimum>
<defaultAssemblyRequest permissionSetReference="Custom" />
<PermissionSet class="System.Security.PermissionSet" version="1" ID="Custom" SameSite="site" Unrestricted="true" />
</applicationRequestMinimum>
</security>
</trustInfo>

<compatibility xmlns="urn:schemas-microsoft-com:compatibility.v1">
<application>
<!-- 设计此应用程序与其一起工作且已针对此应用程序进行测试的
Windows 版本的列表。取消评论适当的元素,
Windows 将自动选择最兼容的环境。 -->
<!-- Windows Vista -->
<!--<supportedOS Id="{e2011457-1546-43c5-a5fe-008deee3d3f0}" />-->
<!-- Windows 7 -->
<supportedOS Id="{35138b9a-5d96-4fbd-8e2d-a2440225f93a}" />
<!-- Windows 8 -->
<supportedOS Id="{4a2f28e3-53b9-4441-ba9c-d69d4a4a6e38}" />
<!-- Windows 8.1 -->
<supportedOS Id="{1f676c76-80e1-4239-95bb-83d0f6d0da78}" />
<!-- Windows 10 -->
<supportedOS Id="{8e0f7a12-bfb3-4fe8-b9a5-48fd50a15a9a}" />
</application>
</compatibility>


<!-- 指示该应用程序可感知 DPI 且 Windows 在 DPI 较高时将不会对其进行
自动缩放。Windows Presentation Foundation (WPF)应用程序自动感知 DPI,无需
选择加入。选择加入此设置的 Windows 窗体应用程序(面向 .NET Framework 4.6)还应
在其 app.config 中将 "EnableWindowsFormsHighDpiAutoResizing" 设置设置为 "true"。
将应用程序设为感知长路径。请参阅 https://docs.microsoft.com/windows/win32/fileio/maximum-file-path-limitation -->
<application xmlns="urn:schemas-microsoft-com:asm.v3">
<windowsSettings>
<dpiAwareness xmlns="http://schemas.microsoft.com/SMI/2016/WindowsSettings">PerMonitorV2</dpiAwareness>
<dpiAware xmlns="http://schemas.microsoft.com/SMI/2005/WindowsSettings">true</dpiAware>
</windowsSettings>
</application>
<!-- 启用 Windows 公共控件和对话框的主题(Windows XP 和更高版本) -->

<dependency>
<dependentAssembly>
<assemblyIdentity
type="win32"
name="Microsoft.Windows.Common-Controls"
version="6.0.0.0"
processorArchitecture="*"
publicKeyToken="6595b64144ccf1df"
language="*"
/>
</dependentAssembly>
</dependency>

<!-- Windows 10 -->
<supportedOS Id="{8e0f7a12-bfb3-4fe8-b9a5-48fd50a15a9a}" />
</application>
</compatibility>
</assembly>
116 changes: 116 additions & 0 deletions Recorder.Desktop/locators/Calculator.locator
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
[
{
"uniqueId": "num1Button",
"fileName": "Calculator",
"provider": "Uia",
"platform": "Win32NT",
"version": "3.0.0",
"components": [
{
"className": "Button",
"name": "\u4E00",
"controlType": "Button",
"isDialog": false,
"id": "num1Button",
"isPassword": false
},
{
"className": "NamedContainerAutomationPeer",
"name": "\u6570\u5B57\u952E\u76D8",
"controlType": "Group",
"isDialog": false,
"id": "NumberPad",
"isPassword": false
},
{
"className": "LandmarkTarget",
"name": null,
"controlType": "Group",
"isDialog": false,
"id": null,
"isPassword": false
},
{
"className": null,
"name": null,
"controlType": "Custom",
"isDialog": false,
"id": "NavView",
"isPassword": false
},
{
"className": "Windows.UI.Core.CoreWindow",
"name": "\u8BA1\u7B97\u5668",
"controlType": "Window",
"isDialog": false,
"id": null,
"isPassword": false
},
{
"className": "ApplicationFrameWindow",
"name": "\u8BA1\u7B97\u5668",
"controlType": "Window",
"isDialog": false,
"id": null,
"isPassword": false
}
]
},
{
"uniqueId": "num2Button",
"fileName": "Calculator",
"provider": "Uia",
"platform": "Win32NT",
"version": "3.0.0",
"components": [
{
"className": "Button",
"name": "\u4E00",
"controlType": "Button",
"isDialog": false,
"id": "num2Button",
"isPassword": false
},
{
"className": "NamedContainerAutomationPeer",
"name": "\u6570\u5B57\u952E\u76D8",
"controlType": "Group",
"isDialog": false,
"id": "NumberPad",
"isPassword": false
},
{
"className": "LandmarkTarget",
"name": null,
"controlType": "Group",
"isDialog": false,
"id": null,
"isPassword": false
},
{
"className": null,
"name": null,
"controlType": "Custom",
"isDialog": false,
"id": "NavView",
"isPassword": false
},
{
"className": "Windows.UI.Core.CoreWindow",
"name": "\u8BA1\u7B97\u5668",
"controlType": "Window",
"isDialog": false,
"id": null,
"isPassword": false
},
{
"className": "ApplicationFrameWindow",
"name": "\u8BA1\u7B97\u5668",
"controlType": "Window",
"isDialog": false,
"id": null,
"isPassword": false
}
]
}
]
Loading

0 comments on commit 3af53f3

Please sign in to comment.