Skip to content

Commit

Permalink
fix: dispose webview after leaving mini app page
Browse files Browse the repository at this point in the history
  • Loading branch information
zznty committed Dec 18, 2024
1 parent 2232f96 commit 0a8d987
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
6 changes: 3 additions & 3 deletions MusicX/Views/MiniAppView.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
xmlns:ui="http://schemas.lepo.co/wpfui/2022/xaml"
xmlns:converters="clr-namespace:MusicX.Converters"
mc:Ignorable="d"
d:DataContext="{d:DesignInstance viewModels:MiniAppViewModel}">
d:DataContext="{d:DesignInstance viewModels:MiniAppViewModel}"
Unloaded="MiniAppView_OnUnloaded">
<Page.Resources>
<converters:NullToVisibilityConverter x:Key="NullToVisibilityConverter" />
</Page.Resources>
Expand All @@ -20,8 +21,7 @@
DefaultBackgroundColor="Transparent"
AllowExternalDrop="False"
NavigationStarting="WebView_OnNavigationStarting"
NavigationCompleted="WebView_OnNavigationCompleted"
WebMessageReceived="WebView_OnWebMessageReceived">
NavigationCompleted="WebView_OnNavigationCompleted">
<wv2:WebView2.Style>
<Style TargetType="wv2:WebView2">
<Setter Property="Visibility" Value="Hidden" />
Expand Down
5 changes: 3 additions & 2 deletions MusicX/Views/MiniAppView.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System.Net;
using System.Runtime.Serialization;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Navigation;
Expand Down Expand Up @@ -263,8 +264,8 @@ private void WebView_OnNavigationCompleted(object? sender, CoreWebView2Navigatio
: $"Код ошибки сервера: {(HttpStatusCode)e.HttpStatusCode}";
}

private void WebView_OnWebMessageReceived(object? sender, CoreWebView2WebMessageReceivedEventArgs e)
private void MiniAppView_OnUnloaded(object sender, RoutedEventArgs e)
{

WebView.Dispose();
}
}

0 comments on commit 0a8d987

Please sign in to comment.