Skip to content

Commit 0a9a97a

Browse files
committed
自动提示安装 webview2
1 parent 5fc534f commit 0a9a97a

File tree

5 files changed

+56
-21
lines changed

5 files changed

+56
-21
lines changed

AquaMai

MaiChartManager/AppMain.cs

Lines changed: 53 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
1-
using SingleInstanceCore;
1+
using System.Diagnostics;
2+
using SingleInstanceCore;
23
using System.Text.Json;
4+
using Windows.ApplicationModel;
5+
using Windows.ApplicationModel.Activation;
36
using MaiChartManager.Controllers.Music;
7+
using Microsoft.Web.WebView2.Core;
48
using Xabe.FFmpeg;
59

610
namespace MaiChartManager;
@@ -49,7 +53,12 @@ public void Run()
4953
{
5054
try
5155
{
52-
StaticSettings.Config = JsonSerializer.Deserialize<Config>(File.ReadAllText(Path.Combine(StaticSettings.appData, "config.json")));
56+
var cfg = JsonSerializer.Deserialize<Config>(File.ReadAllText(Path.Combine(StaticSettings.appData, "config.json")));
57+
if (cfg == null)
58+
{
59+
throw new Exception("config.json is null");
60+
}
61+
StaticSettings.Config = cfg;
5362
}
5463
catch (Exception e)
5564
{
@@ -59,6 +68,23 @@ public void Run()
5968
}
6069
}
6170

71+
string? availableVersion = null;
72+
try
73+
{
74+
availableVersion = CoreWebView2Environment.GetAvailableBrowserVersionString();
75+
}
76+
catch (WebView2RuntimeNotFoundException) { }
77+
78+
if (availableVersion == null && !IsFromStartup)
79+
{
80+
var answer = MessageBox.Show("WebView2 运行时未安装,在启动之后可能会白屏…\n\n如果你觉得你已经安装了 WebView2 运行时,请尝试重启电脑。\n\n要尝试安装一下 WebView2 吗?", "WebView2 未安装", MessageBoxButtons.YesNo,
81+
MessageBoxIcon.Warning);
82+
if (answer == DialogResult.Yes)
83+
{
84+
Process.Start(new ProcessStartInfo(Path.Combine(StaticSettings.exeDir, "MicrosoftEdgeWebview2Setup.exe")) { UseShellExecute = true });
85+
}
86+
}
87+
6288
IapManager.Init();
6389

6490
_launcher = new Launcher();
@@ -73,6 +99,31 @@ public void Run()
7399
}
74100
}
75101

102+
private static bool? _isFromStartup;
103+
104+
public static bool IsFromStartup
105+
{
106+
get
107+
{
108+
if (_isFromStartup.HasValue)
109+
return _isFromStartup.Value;
110+
try
111+
{
112+
var aeArgs = AppInstance.GetActivatedEventArgs();
113+
_isFromStartup = aeArgs?.Kind == ActivationKind.StartupTask;
114+
return _isFromStartup.Value;
115+
}
116+
catch (Exception e)
117+
{
118+
Console.WriteLine(e);
119+
SentrySdk.CaptureException(e);
120+
}
121+
122+
_isFromStartup = false;
123+
return false;
124+
}
125+
}
126+
76127
public void OnInstanceInvoked(string[] args)
77128
{
78129
_launcher.ShowWindow();

MaiChartManager/Launcher.cs

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ public Launcher()
3434
notifyIcon1.Visible = true;
3535
WindowState = FormWindowState.Minimized;
3636
# endif
37-
if (!isFromStartup())
37+
if (!AppMain.IsFromStartup)
3838
{
3939
Visible = true;
4040
IapManager.BindToForm(this);
@@ -49,22 +49,6 @@ public Launcher()
4949
StartClicked(null, null);
5050
}
5151

52-
private bool isFromStartup()
53-
{
54-
try
55-
{
56-
var aeArgs = AppInstance.GetActivatedEventArgs();
57-
return aeArgs?.Kind == ActivationKind.StartupTask;
58-
}
59-
catch (Exception e)
60-
{
61-
Console.WriteLine(e);
62-
SentrySdk.CaptureException(e);
63-
}
64-
65-
return false;
66-
}
67-
6852
private async Task CheckStartupStatus()
6953
{
7054
var startupTask = await StartupTask.GetAsync("MaiChartManagerStartupId");

MaiChartManager/Properties/AssemblyInfo.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,4 @@
88
[assembly: AssemblyTitle("MaiChartManager")]
99
[assembly: AssemblyVersion(AppMain.Version)]
1010
[assembly: System.Runtime.Versioning.TargetPlatformAttribute("Windows10.0.17763.0")]
11-
[assembly: System.Runtime.Versioning.SupportedOSPlatformAttribute("Windows10.0.14393.0")]
11+
[assembly: System.Runtime.Versioning.SupportedOSPlatformAttribute("Windows10.0.17134.0")]
1.58 MB
Binary file not shown.

0 commit comments

Comments
 (0)