Repository navigation
Expand file tree
/
Copy pathManagementWindow.Loading.cs
More file actions
107 lines (97 loc) · 4.25 KB
/
Copy pathManagementWindow.Loading.cs
File metadata and controls
107 lines (97 loc) · 4.25 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
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
using Microsoft.Web.WebView2.Core;
using System.Windows;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Threading;
namespace SeewoAutoLogin
{
public partial class ManagementWindow
{
#region 加载 / 兜底面板
private void ShowStatus(string title, string detail, bool busy,
bool showRetry = false, bool showInstall = false, bool showDownload = false)
{
if (!Dispatcher.CheckAccess())
{
Dispatcher.BeginInvoke(new Action(() => ShowStatus(title, detail, busy, showRetry, showInstall, showDownload)));
return;
}
StatusTitle.Text = title;
StatusDetail.Text = detail;
StatusProgress.Visibility = busy ? Visibility.Visible : Visibility.Collapsed;
InstallButton.Visibility = showInstall ? Visibility.Visible : Visibility.Collapsed;
RetryButton.Visibility = showRetry ? Visibility.Visible : Visibility.Collapsed;
DownloadButton.Visibility = showDownload ? Visibility.Visible : Visibility.Collapsed;
StatusButtons.Visibility = busy ? Visibility.Collapsed : Visibility.Visible;
StatusPanel.Visibility = Visibility.Visible;
}
private void ShowStatusPanel(string title, string detail,
bool showRetry = false, bool showInstall = false, bool showDownload = false)
=> ShowStatus(title, detail, busy: false, showRetry: showRetry, showInstall: showInstall,
showDownload: showDownload);
private void HideStatusPanel() => StatusPanel.Visibility = Visibility.Collapsed;
private async void InstallButton_Click(object sender, RoutedEventArgs e)
{
InstallButton.IsEnabled = false;
try
{
ShowStatus("正在安装 WebView2 运行时", "正在下载并静默安装,请稍候…", busy: true);
if (await RunInstallAsync())
{
_app?.WriteDiagnosticLog("[WebView2] 运行时安装成功,重新加载界面");
await RetryInitializeAsync();
}
else
{
ShowStatusPanel("WebView2 安装未成功",
"安装未完成。请确认网络可用,或「手动下载」官方运行时安装后再点击「重新检测」。",
showRetry: true, showInstall: true, showDownload: true);
}
}
catch (Exception ex)
{
_app?.WriteDiagnosticLog($"[WebView2] 安装运行时异常: {ex.GetType().Name} - {ex.Message}");
ShowStatusPanel("WebView2 安装未成功",
"安装过程出错:" + ex.Message + "\n可重试,或用「手动下载」装好官方运行时后点「重新检测」。",
showRetry: true, showInstall: true, showDownload: true);
}
finally
{
InstallButton.IsEnabled = true;
}
}
private async void RetryButton_Click(object sender, RoutedEventArgs e)
{
try
{
_autoInstallAttempted = false; // 重新检测时允许再次自动安装
await RetryInitializeAsync();
}
catch (Exception ex)
{
// 事件处理器是 async void:异常逃出去会带走整个进程
_app?.WriteDiagnosticLog($"[WebView2] 重新检测异常: {ex.GetType().Name} - {ex.Message}");
}
}
private void DownloadButton_Click(object sender, RoutedEventArgs e)
{
try
{
Process.Start(new ProcessStartInfo
{
FileName = WebView2Runtime.ManualDownloadUrl,
UseShellExecute = true
});
}
catch (Exception ex)
{
_app?.WriteDiagnosticLog($"[WebView2] 打开下载页失败: {ex.Message}");
}
}
private void LogButton_Click(object sender, RoutedEventArgs e)
{
try { new LogViewerWindow { Owner = this }.ShowDialog(); } catch { }
}
#endregion
}
}