Skip to content

Commit

Permalink
fix: Check if WebView2 is available before using it (Jorixon#135)
Browse files Browse the repository at this point in the history
  • Loading branch information
Jorixon authored Mar 22, 2024
1 parent 9b882e2 commit 1bba6e6
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,8 @@
<WebView2
x:Name="ModPageBrowser"
DefaultBackgroundColor="Transparent"
Source="{x:Bind ViewModel.ModPage, Mode=TwoWay}" />
Source="{x:Bind ViewModel.ModPage, Mode=TwoWay}"
Visibility="Collapsed" />
</Grid>

</Grid>
Expand Down
22 changes: 22 additions & 0 deletions src/GIMI-ModManager.WinUI/Views/ModUpdateAvailableWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ public sealed partial class ModUpdateAvailableWindow : WindowEx
public readonly ModUpdateVM ViewModel;
public readonly IThemeSelectorService ThemeSelectorService = App.GetService<IThemeSelectorService>();

public bool WebViewIsAvailable = false;

//private bool _isFirstTimeNavigation = true;

public ModUpdateAvailableWindow(Guid notificationId)
Expand All @@ -25,6 +27,24 @@ public ModUpdateAvailableWindow(Guid notificationId)
rootElement.RequestedTheme = ThemeSelectorService.Theme;
}


InitWebView();
}

private void InitWebView()
{
try
{
CoreWebView2Environment.GetAvailableBrowserVersionString();
}
catch (Exception e)
{
return;
}

WebViewIsAvailable = true;
ModPageBrowser.Visibility = Visibility.Visible;

ModPageBrowser.Loading += async (_, _) =>
{
await ModPageBrowser.EnsureCoreWebView2Async();
Expand Down Expand Up @@ -64,6 +84,8 @@ public ModUpdateAvailableWindow(Guid notificationId)

private async void ButtonBase_OnClick(object sender, RoutedEventArgs e)
{
if (!WebViewIsAvailable)
return;
await ModPageBrowser.EnsureCoreWebView2Async();

if (ModPageBrowser.CoreWebView2.IsDefaultDownloadDialogOpen)
Expand Down

0 comments on commit 1bba6e6

Please sign in to comment.