You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

86 lines
2.7 KiB

2 years ago
using CommunityToolkit.Mvvm.Messaging;
using CommunityToolkit.Mvvm.Messaging.Messages;
using Microsoft.Web.WebView2.Core;
2 years ago
using SJ.Controls;
using System;
using System.Threading;
2 years ago
using System.Windows;
namespace BBWYB.Client.Views
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : BWindow
{
public MainWindow()
{
InitializeComponent();
this.Width = SystemParameters.WorkArea.Size.Width * 0.8;
this.Height = SystemParameters.WorkArea.Size.Height * 0.7;
this.Loaded += MainWindow_Loaded;
WeakReferenceMessenger.Default.Register<Message_Frame_Refresh>(this, (o, x) =>
{
this.Dispatcher.Invoke(() =>
{
frame.Refresh();
});
});
2 years ago
}
private void MainWindow_Loaded(object sender, RoutedEventArgs e)
{
if (!CheckWebview2Runtime())
{
MessageBox.Show("缺少webview2 runtime,请下载安装之后重新运行bbwyb");
//下载webview2 runtime
//Task.Factory.StartNew(DownloadWebview2Runtime);
var webview2RuntimeUrl = "https://msedge.sf.dl.delivery.mp.microsoft.com/filestreamingservice/files/238fc310-c6c1-4a3e-a806-4a7c3c17b377/MicrosoftEdgeWebView2RuntimeInstallerX64.exe";
try
{
System.Diagnostics.Process.Start("explorer.exe", webview2RuntimeUrl);
Thread.Sleep(1000);
}
catch (Exception ex)
{
Clipboard.SetText(webview2RuntimeUrl);
MessageBox.Show($"{ex.Message}\r\n调用浏览器失败,网页链接已复制到剪切板,请手动打开浏览器访问", "提示");
}
finally
{
Environment.Exit(Environment.ExitCode);
}
}
2 years ago
}
private void frame_Navigated(object sender, System.Windows.Navigation.NavigationEventArgs e)
{
if (frame.CanGoBack)
frame.RemoveBackEntry();
}
private bool CheckWebview2Runtime()
{
bool isInstall = false;
try
{
isInstall = !string.IsNullOrEmpty(CoreWebView2Environment.GetAvailableBrowserVersionString());
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
return isInstall;
}
2 years ago
}
public class Message_Frame_Refresh : ValueChangedMessage<object>
{
public Message_Frame_Refresh(object value) : base(value)
{
}
}
2 years ago
}