diff --git a/DesktopNotifications.Avalonia/AppBuilderExtensions.cs b/DesktopNotifications.Avalonia/AppBuilderExtensions.cs index a793222..be5dc84 100644 --- a/DesktopNotifications.Avalonia/AppBuilderExtensions.cs +++ b/DesktopNotifications.Avalonia/AppBuilderExtensions.cs @@ -1,5 +1,6 @@ using Avalonia; using Avalonia.Controls; +using Avalonia.Controls.ApplicationLifetimes; using Avalonia.Platform; using DesktopNotifications.FreeDesktop; using DesktopNotifications.Windows; @@ -47,6 +48,17 @@ namespace DesktopNotifications.Avalonia //TODO Any better way of doing this? manager.Initialize().GetAwaiter().GetResult(); + builder.AfterSetup(b => + { + if (b.Instance.ApplicationLifetime is IControlledApplicationLifetime lifetime) + { + lifetime.Exit += (s, e) => + { + manager.Dispose(); + }; + } + }); + AvaloniaLocator.CurrentMutable.Bind().ToConstant(manager); return builder;