-
-
Notifications
You must be signed in to change notification settings - Fork 663
/
Copy pathMyApp.cs
107 lines (84 loc) · 3.7 KB
/
MyApp.cs
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
// THIS FILE IS PART OF NanUI PROJECT
// THE NanUI PROJECT IS AN OPENSOURCE LIBRARY LICENSED UNDER THE MIT License.
// COPYRIGHTS (C) Xuanchen Lin. ALL RIGHTS RESERVED.
// GITHUB: https://github.com/XuanchenLin/NanUI
using Microsoft.Extensions.DependencyInjection;
using NetDimension.NanUI;
using NetDimension.NanUI.WebResource;
using NetDimension.NanUI.JavaScript;
namespace MinimalWinFormiumApp;
internal class MyApp : NanUIAppStartup
{
protected override MainWindowCreationAction? UseMainWindow(MainWindowOptions opts)
{
return opts.UseMainFormium<MyWindow>();
// 可以指定 Formium 为主窗体,也可以使用原生的 WinForm 窗体。
// You can specify Formium as the main form, or you can use the native WinForm form.
//return opts.UseMainForm<Form1>();
}
protected override void ProgramMain(string[] args)
{
// 现在把 Main 函数搬到这里来。避免用户搞不清主进程和渲染进程的区别,在 Program.cs 里面写太多代码导致子进程内部出现问题。
// Now move the Main function here. To avoid users not knowing the difference between the main process and the rendering process, write too much code in Program.cs, which causes problems in the sub-process.
#if NETCOREAPP3_1_OR_GREATER
// To customize application configuration such as set high DPI settings or default font,
// see https://aka.ms/applicationconfiguration.
ApplicationConfiguration.Initialize();
#else
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
#endif
}
// CEF 的配置可以在Program.cs里面写,也可以在这里写,在这里写更集中,更简洁。
// CEF configuration can be written in Program.cs or here, which is more centralized and concise here.
protected override void ConfigurationChromiumEmbedded(ChromiumEnvironmentBuiler cef)
{
//cef.UseInMemoryUserData();
cef.ConfigureCommandLineArguments(cl =>
{
//cl.AppendArgument("disable-web-security");
//cl.AppendSwitch("no-proxy-server");
cl.AppendSwitch("enable-gpu");
//cl.AppendSwitch("disable-gpu");
});
cef.ConfigureDefaultSettings(settings =>
{
settings.WindowlessRenderingEnabled = true;
});
cef.ConfigureDefaultBrowserSettings(settings =>
{
});
// 启用子进程的示例。
// Example of enabling sub-process.
//cef.ConfigureSubprocess(sub =>
//{
// sub.SubprocessFilePath = "WinFormiumSubProcess.exe";
//});
}
protected override void ConfigureServices(IServiceCollection services)
{
// 注册嵌入资源
// Register embedded resources to specific domain.
services.AddEmbeddedFileResource(new EmbeddedFileResourceOptions
{
Scheme = "http",
DomainName = "embedded.app.local",
ResourceAssembly = typeof(Program).Assembly,
EmbeddedResourceDirectoryName = "wwwroot",
});
// 注册本地资源
// Register local resources to specific domain.
services.AddLocalFileResource(new LocalFileResourceOptions
{
Scheme = "http",
DomainName = "files.app.local",
PhysicalFilePath = Path.Combine(AppContext.BaseDirectory, "wwwroot"),
});
services.AddDataResource("http", "data.app.local", provider => {
provider.ImportFromCurrentAssembly();
});
// 注册 JavaScript Window Binding Object
// Register JavaScript Window Binding Object
services.AddWindowBindingObject<TestWindowBindingObject>();
}
}