From 8dd989b6e03f33b5b1e8a69947aac829fe357af7 Mon Sep 17 00:00:00 2001 From: Dani John Date: Thu, 2 May 2024 09:52:11 +0530 Subject: [PATCH] WebView cleanup --- .../Lively.UI.WinUI/Services/DialogService.cs | 5 ++++- .../Views/Pages/AppUpdateView.xaml | 16 +++++++++++++++- .../Views/Pages/AppUpdateView.xaml.cs | 17 +++++++++++++++++ .../Views/Pages/PatreonSupportersView.xaml | 1 + .../Views/Pages/PatreonSupportersView.xaml.cs | 10 ++++++++++ 5 files changed, 47 insertions(+), 2 deletions(-) diff --git a/src/Lively/Lively.UI.WinUI/Services/DialogService.cs b/src/Lively/Lively.UI.WinUI/Services/DialogService.cs index fe40f36a..7aa96390 100644 --- a/src/Lively/Lively.UI.WinUI/Services/DialogService.cs +++ b/src/Lively/Lively.UI.WinUI/Services/DialogService.cs @@ -240,10 +240,11 @@ public async Task ShowAboutDialogAsync() public async Task ShowPatreonSupportersDialogAsync() { + var page = new PatreonSupportersView(); var dlg = new ContentDialog() { Title = i18n.GetString("TitlePatreon/Text"), - Content = new PatreonSupportersView(), + Content = page, PrimaryButtonText = i18n.GetString("TextBecomePatreonMember/Content"), SecondaryButtonText = i18n.GetString("Cancel/Content"), DefaultButton = ContentDialogButton.Primary, @@ -253,6 +254,8 @@ public async Task ShowPatreonSupportersDialogAsync() if (await dlg.ShowAsyncQueue() == ContentDialogResult.Primary) LinkUtil.OpenBrowser("https://rocksdanister.github.io/lively/coffee/"); + + page.OnClose(); } public async Task ShowControlPanelDialogAsync() diff --git a/src/Lively/Lively.UI.WinUI/Views/Pages/AppUpdateView.xaml b/src/Lively/Lively.UI.WinUI/Views/Pages/AppUpdateView.xaml index ba9eff69..9343594d 100644 --- a/src/Lively/Lively.UI.WinUI/Views/Pages/AppUpdateView.xaml +++ b/src/Lively/Lively.UI.WinUI/Views/Pages/AppUpdateView.xaml @@ -9,6 +9,7 @@ xmlns:local="using:Lively.UI.WinUI.Views.Pages" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" Loaded="Page_Loaded" + Unloaded="Page_Unloaded" mc:Ignorable="d"> @@ -23,9 +24,22 @@ + + + + + + (); this.DataContext = this.viewModel; + // Error when setting in xaml + WebView.DefaultBackgroundColor = ((SolidColorBrush)App.Current.Resources["ApplicationPageBackgroundThemeBrush"]).Color; + // Set website theme to reflect app setting var pageTheme = App.Services.GetRequiredService().Settings.ApplicationTheme switch { AppTheme.Auto => string.Empty, // Website handles theme change based on WebView change. @@ -59,6 +63,7 @@ private void CoreWebView2_NewWindowRequested(Microsoft.Web.WebView2.Core.CoreWeb if (!args.IsUserInitiated) return; + // Open hyperlinks in default browser args.Handled = true; LinkUtil.OpenBrowser(args.Uri); } @@ -68,11 +73,23 @@ private void WebView_NavigationStarting(WebView2 sender, Microsoft.Web.WebView2. // Stay in page if (args.IsRedirected) args.Cancel = true; + else + WebViewProgress.Visibility = Visibility.Visible; + } + + private void WebView_NavigationCompleted(WebView2 sender, CoreWebView2NavigationCompletedEventArgs args) + { + WebViewProgress.Visibility = Visibility.Collapsed; } private void Page_Loaded(object sender, RoutedEventArgs e) { BackgroundGridShadow.Receivers.Add(BackgroundGrid); } + + private void Page_Unloaded(object sender, RoutedEventArgs e) + { + WebView.Close(); + } } } diff --git a/src/Lively/Lively.UI.WinUI/Views/Pages/PatreonSupportersView.xaml b/src/Lively/Lively.UI.WinUI/Views/Pages/PatreonSupportersView.xaml index d38e68c8..8ea5f4ef 100644 --- a/src/Lively/Lively.UI.WinUI/Views/Pages/PatreonSupportersView.xaml +++ b/src/Lively/Lively.UI.WinUI/Views/Pages/PatreonSupportersView.xaml @@ -6,6 +6,7 @@ xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:local="using:Lively.UI.WinUI.Views.Pages" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" + Unloaded="Page_Unloaded" mc:Ignorable="d"> diff --git a/src/Lively/Lively.UI.WinUI/Views/Pages/PatreonSupportersView.xaml.cs b/src/Lively/Lively.UI.WinUI/Views/Pages/PatreonSupportersView.xaml.cs index b8f95911..a540c86d 100644 --- a/src/Lively/Lively.UI.WinUI/Views/Pages/PatreonSupportersView.xaml.cs +++ b/src/Lively/Lively.UI.WinUI/Views/Pages/PatreonSupportersView.xaml.cs @@ -66,5 +66,15 @@ private void WebView_NavigationStarting(WebView2 sender, Microsoft.Web.WebView2. if (args.IsRedirected) args.Cancel = true; } + + public void OnClose() + { + WebView.Close(); + } + + private void Page_Unloaded(object sender, RoutedEventArgs e) + { + // Unloaded is not reliable when used in dialog + } } }