-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
62 lines (56 loc) · 1.98 KB
/
Copy pathProgram.cs
File metadata and controls
62 lines (56 loc) · 1.98 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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
using System.Runtime.InteropServices;
using Avalonia;
using Microsoft.Web.WebView2.Core;
namespace SquadTools;
internal static class Program
{
[STAThread]
private static void Main()
{
bool webView2Available = CheckWebView2Runtime();
// Keep the WinForms host hidden; it owns the global hotkeys and input services.
LegacyRuntime.Start(webView2Available);
BuildAvaloniaApp().StartWithClassicDesktopLifetime([webView2Available.ToString()]);
LegacyRuntime.Stop();
}
private static AppBuilder BuildAvaloniaApp() =>
AppBuilder.Configure<App>()
.UsePlatformDetect()
.LogToTrace();
private static bool CheckWebView2Runtime()
{
try
{
string? version = CoreWebView2Environment.GetAvailableBrowserVersionString();
if (!string.IsNullOrWhiteSpace(version))
{
return true;
}
}
catch (WebView2RuntimeNotFoundException)
{
}
catch (COMException)
{
}
System.Windows.Forms.DialogResult result = System.Windows.Forms.MessageBox.Show(
"未检测到 Microsoft Edge WebView2 Runtime。地图工具需要安装此运行环境,其他功能仍可正常使用。\n\n是否打开微软官方下载页面?",
"缺少 WebView2 Runtime",
System.Windows.Forms.MessageBoxButtons.YesNo,
System.Windows.Forms.MessageBoxIcon.Warning);
if (result == System.Windows.Forms.DialogResult.Yes)
{
try
{
System.Diagnostics.Process.Start(new System.Diagnostics.ProcessStartInfo
{
FileName = "https://developer.microsoft.com/microsoft-edge/webview2/",
UseShellExecute = true
});
}
catch (InvalidOperationException) { }
catch (System.ComponentModel.Win32Exception) { }
}
return false;
}
}