diff --git a/Flow.Launcher.Core/Plugin/PluginManager.cs b/Flow.Launcher.Core/Plugin/PluginManager.cs index a2a00932954..134c3c002dc 100644 --- a/Flow.Launcher.Core/Plugin/PluginManager.cs +++ b/Flow.Launcher.Core/Plugin/PluginManager.cs @@ -58,6 +58,22 @@ public static void Save() API.SavePluginSettings(); } + public static async ValueTask DisposePluginsAsync() + { + foreach (var pluginPair in AllPlugins) + { + switch (pluginPair.Plugin) + { + case IDisposable disposable: + disposable.Dispose(); + break; + case IAsyncDisposable asyncDisposable: + await asyncDisposable.DisposeAsync(); + break; + } + } + } + public static async Task ReloadData() { await Task.WhenAll(AllPlugins.Select(plugin => plugin.Plugin switch diff --git a/Flow.Launcher/MainWindow.xaml.cs b/Flow.Launcher/MainWindow.xaml.cs index 735103938f0..5fab812e6e2 100644 --- a/Flow.Launcher/MainWindow.xaml.cs +++ b/Flow.Launcher/MainWindow.xaml.cs @@ -11,6 +11,7 @@ using Flow.Launcher.Helper; using Flow.Launcher.Infrastructure.UserSettings; using Flow.Launcher.ViewModel; +using Application = System.Windows.Application; using Screen = System.Windows.Forms.Screen; using ContextMenuStrip = System.Windows.Forms.ContextMenuStrip; using DataFormats = System.Windows.DataFormats; @@ -46,10 +47,13 @@ public MainWindow() InitializeComponent(); } - private void OnClosing(object sender, CancelEventArgs e) + private async void OnClosing(object sender, CancelEventArgs e) { _notifyIcon.Visible = false; _viewModel.Save(); + e.Cancel = true; + await PluginManager.DisposePluginsAsync(); + Application.Current.Shutdown(); } private void OnInitialized(object sender, EventArgs e)