Dispose mail webviews when closing the shell
This commit is contained in:
@@ -137,6 +137,41 @@ public class DialogService : DialogServiceBase, IMailDialogService
|
||||
WinoCustomMessageDialogIcon.Warning,
|
||||
Translator.Buttons_No);
|
||||
|
||||
public async Task<ThreeButtonDialogResult> ShowThreeButtonDialogAsync(string title,
|
||||
string description,
|
||||
string primaryButtonText,
|
||||
string secondaryButtonText,
|
||||
string cancelButtonText,
|
||||
WinoCustomMessageDialogIcon? icon = null)
|
||||
{
|
||||
var informationContainer = new CustomMessageDialogInformationContainer(
|
||||
title,
|
||||
description,
|
||||
icon ?? WinoCustomMessageDialogIcon.Information,
|
||||
false);
|
||||
|
||||
var dialog = new ContentDialog
|
||||
{
|
||||
Style = ApplicationResourceManager.GetResource<Style>("WinoDialogStyle"),
|
||||
RequestedTheme = ThemeService.RootTheme.ToWindowsElementTheme(),
|
||||
DefaultButton = ContentDialogButton.Primary,
|
||||
PrimaryButtonText = primaryButtonText,
|
||||
SecondaryButtonText = secondaryButtonText,
|
||||
CloseButtonText = cancelButtonText,
|
||||
ContentTemplate = ApplicationResourceManager.GetResource<DataTemplate>("CustomWinoContentDialogContentTemplate"),
|
||||
Content = informationContainer
|
||||
};
|
||||
|
||||
var dialogResult = await HandleDialogPresentationAsync(dialog);
|
||||
|
||||
return dialogResult switch
|
||||
{
|
||||
ContentDialogResult.Primary => ThreeButtonDialogResult.Primary,
|
||||
ContentDialogResult.Secondary => ThreeButtonDialogResult.Secondary,
|
||||
_ => ThreeButtonDialogResult.Cancel
|
||||
};
|
||||
}
|
||||
|
||||
public async Task<MailAccount> ShowAccountPickerDialogAsync(List<MailAccount> availableAccounts)
|
||||
{
|
||||
var accountPicker = new AccountPickerDialog(availableAccounts)
|
||||
|
||||
@@ -5,6 +5,7 @@ using System.Threading.Tasks;
|
||||
using CommunityToolkit.Mvvm.Input;
|
||||
using CommunityToolkit.Mvvm.Messaging;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.UI.Windowing;
|
||||
using Microsoft.UI.Xaml;
|
||||
using Microsoft.UI.Xaml.Controls;
|
||||
using Windows.UI;
|
||||
@@ -20,8 +21,10 @@ using Wino.Mail.WinUI.Helpers;
|
||||
using Wino.Mail.WinUI.Interfaces;
|
||||
using Wino.Mail.WinUI.Models;
|
||||
using Wino.Mail.WinUI.Views;
|
||||
using Wino.Messaging.Client.Mails;
|
||||
using Wino.Messaging.Client.Shell;
|
||||
using Wino.Messaging.UI;
|
||||
using Wino.Views.Mail;
|
||||
using WinUIEx;
|
||||
|
||||
namespace Wino.Mail.WinUI;
|
||||
@@ -356,12 +359,16 @@ public sealed partial class ShellWindow : WindowEx, IWinoShellWindow,
|
||||
SynchronizeTitleBarSearchBox();
|
||||
}
|
||||
|
||||
private void OnAppWindowClosing(object sender, Microsoft.UI.Windowing.AppWindowClosingEventArgs e)
|
||||
private async void OnAppWindowClosing(object sender, AppWindowClosingEventArgs e)
|
||||
{
|
||||
if (_allowClose || (Application.Current as App)?.IsExiting == true)
|
||||
return;
|
||||
|
||||
e.Cancel = true;
|
||||
|
||||
if (!await PrepareMailModeForHideAsync())
|
||||
return;
|
||||
|
||||
var windowManager = WinoApplication.Current.Services.GetService<IWinoWindowManager>();
|
||||
windowManager?.HideWindow(this);
|
||||
}
|
||||
@@ -398,6 +405,55 @@ public sealed partial class ShellWindow : WindowEx, IWinoShellWindow,
|
||||
UnregisterRecipients();
|
||||
}
|
||||
|
||||
private async Task<bool> PrepareMailModeForHideAsync()
|
||||
{
|
||||
if (MainShellFrame.Content is not WinoAppShell shellPage)
|
||||
return true;
|
||||
|
||||
if (shellPage.GetShellFrame().Content is not MailListPage mailListPage)
|
||||
return true;
|
||||
|
||||
var renderingFrame = mailListPage.FindName("RenderingFrame") as Frame;
|
||||
|
||||
if (renderingFrame?.Content is ComposePage composePage)
|
||||
{
|
||||
var closeResult = await MailDialogService.ShowThreeButtonDialogAsync(
|
||||
Translator.DialogMessage_CloseDraftWindowConfirmationTitle,
|
||||
Translator.DialogMessage_CloseDraftWindowConfirmationMessage,
|
||||
Translator.Buttons_Save,
|
||||
Translator.Buttons_Discard,
|
||||
Translator.Buttons_Cancel,
|
||||
WinoCustomMessageDialogIcon.Warning);
|
||||
|
||||
if (closeResult == ThreeButtonDialogResult.Cancel)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
if (closeResult == ThreeButtonDialogResult.Primary)
|
||||
{
|
||||
await composePage.ViewModel.SaveDraftAsync();
|
||||
}
|
||||
else
|
||||
{
|
||||
await composePage.ViewModel.DiscardDraftAsync(requireConfirmation: false);
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
MailDialogService.InfoBarMessage(Translator.GeneralTitle_Error, ex.Message, InfoBarMessageType.Error);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
await mailListPage.ViewModel.MailCollection.UnselectAllAsync();
|
||||
WeakReferenceMessenger.Default.Send(new DisposeRenderingFrameRequested());
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private void RegisterRecipients()
|
||||
{
|
||||
WeakReferenceMessenger.Default.Register<TitleBarShellContentUpdated>(this);
|
||||
|
||||
@@ -56,7 +56,6 @@ public sealed partial class MailListPage : MailListPageAbstract,
|
||||
{
|
||||
private const double RENDERING_COLUMN_MIN_WIDTH = 375;
|
||||
private const int SELECTION_SETTLE_DELAY_MS = 120;
|
||||
private const int RENDERING_FRAME_RELEASE_DELAY_MS = 2000;
|
||||
private int _idleNavigationRequestVersion = 0;
|
||||
private int _mailActivationRequestVersion = 0;
|
||||
private IPopoutClient? _activePopoutClient;
|
||||
@@ -546,11 +545,6 @@ public sealed partial class MailListPage : MailListPageAbstract,
|
||||
}
|
||||
}
|
||||
|
||||
await Task.Delay(RENDERING_FRAME_RELEASE_DELAY_MS);
|
||||
|
||||
if (requestVersion != _idleNavigationRequestVersion) return;
|
||||
if (ViewModel.MailCollection.SelectedItemsCount != 0) return;
|
||||
|
||||
// Ensure rendering frame actually navigates away from Compose/Rendering pages.
|
||||
// Otherwise those pages keep their messenger registrations alive.
|
||||
ViewModel.NavigationService.Navigate(WinoPage.IdlePage, null, NavigationReferenceFrame.RenderingFrame, NavigationTransitionType.DrillIn);
|
||||
|
||||
Reference in New Issue
Block a user