Handling some warnings and proper disposals of shells etc.

This commit is contained in:
Burak Kaan Köse
2026-03-27 14:45:36 +01:00
parent 3712041689
commit fb8a3d8f90
21 changed files with 470 additions and 298 deletions
+19 -1
View File
@@ -34,6 +34,7 @@ public sealed partial class ShellWindow : WindowEx, IWinoShellWindow,
IRecipient<WinoAccountProfileUpdatedMessage>,
IRecipient<WinoAccountProfileDeletedMessage>
{
private bool _allowClose;
public IStatePersistanceService StatePersistanceService { get; } = WinoApplication.Current.Services.GetService<IStatePersistanceService>() ?? throw new Exception("StatePersistanceService not registered in DI container.");
public IPreferencesService PreferencesService { get; } = WinoApplication.Current.Services.GetService<IPreferencesService>() ?? throw new Exception("PreferencesService not registered in DI container.");
public INavigationService NavigationService { get; } = WinoApplication.Current.Services.GetService<INavigationService>() ?? throw new Exception("NavigationService not registered in DI container.");
@@ -354,7 +355,7 @@ public sealed partial class ShellWindow : WindowEx, IWinoShellWindow,
private void OnAppWindowClosing(object sender, Microsoft.UI.Windowing.AppWindowClosingEventArgs e)
{
if ((Application.Current as App)?.IsExiting == true)
if (_allowClose || (Application.Current as App)?.IsExiting == true)
return;
e.Cancel = true;
@@ -362,10 +363,27 @@ public sealed partial class ShellWindow : WindowEx, IWinoShellWindow,
windowManager?.HideWindow(this);
}
public void PrepareForClose()
{
if (MainShellFrame.Content is WinoAppShell shellPage)
{
shellPage.PrepareForWindowClose();
}
_allowClose = true;
}
private void OnWindowClosed(object sender, WindowEventArgs e)
{
Closed -= OnWindowClosed;
AppWindow.Closing -= OnAppWindowClosing;
StatePersistanceService.StatePropertyChanged -= StatePersistenceServiceChanged;
if (MainShellFrame.Content is WinoAppShell shellPage)
{
shellPage.PrepareForWindowClose();
}
UnregisterRecipients();
}