-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathProgram.cs
More file actions
44 lines (34 loc) · 1.66 KB
/
Program.cs
File metadata and controls
44 lines (34 loc) · 1.66 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
global using DCSoft.WinForm2WASM;
using Microsoft.AspNetCore.Components.WebAssembly.Hosting;
using Microsoft.JSInterop;
using Microsoft.Extensions.DependencyInjection;
[assembly: System.Reflection.AssemblyMetadata("IsTrimmable", "false")]
namespace DCSoft.WinForm2WASM
{
[System.Runtime.Versioning.SupportedOSPlatform("browser")]
internal class Prograss
{
public static async Task Main(string[] args)
{
// 1. 构建极简宿主(仅初始化核心服务,不含 RootComponent)
var builder = WebAssemblyHostBuilder.CreateDefault(args);
var host = builder.Build();
// 2. 解析 JSRuntime
var jsRuntime = host.Services.GetRequiredService<IJSRuntime>() as JSInProcessRuntime;
DCWasmWinFormEngine.Start(jsRuntime);
await host.RunAsync();
//// 3. 执行 JS 操作(示例:调用自定义 JS 函数)
//var browserInfo = await jsRuntime.InvokeAsync<string>("getBrowserInfo");
//Console.WriteLine($"从 JS 获取浏览器信息:{browserInfo}");
//// 4. 继续构建完整应用并启动
//builder.RootComponents.Add<App>("#app");
//builder.RootComponents.Add<HeadOutlet>("head::after");
//await host.RunAsync();
//var builder = DCSoft.WebAssemblyHostBuilder.CreateDefault(args);
//DCWasmWinFormEngine.Start(WASMJSRuntime.Instance);
////await System.Runtime.InteropServices.JavaScript.JSHost.ImportAsync("DCWinForm2WASM", "./DCWinForm2WASM.js");
//await WASMJSRuntime.Instance.InvokeVoidAsync("__StartDCSoftWinForm2WASM");
//await builder.Build().RunAsync();
}
}
}