Skip to content

Commit a18a777

Browse files
committed
Dispose Disposable or AsyncDisposable plugin on mainwindow close
1 parent d6ec4b5 commit a18a777

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

Flow.Launcher.Core/Plugin/PluginManager.cs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,22 @@ public static void Save()
5858
API.SavePluginSettings();
5959
}
6060

61+
public static async ValueTask DisposePluginsAsync()
62+
{
63+
foreach (var plugin in AllPlugins)
64+
{
65+
switch (plugin)
66+
{
67+
case IDisposable disposable:
68+
disposable.Dispose();
69+
break;
70+
case IAsyncDisposable asyncDisposable:
71+
await asyncDisposable.DisposeAsync();
72+
break;
73+
}
74+
}
75+
}
76+
6177
public static async Task ReloadData()
6278
{
6379
await Task.WhenAll(AllPlugins.Select(plugin => plugin.Plugin switch

Flow.Launcher/MainWindow.xaml.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
using Flow.Launcher.Helper;
1212
using Flow.Launcher.Infrastructure.UserSettings;
1313
using Flow.Launcher.ViewModel;
14+
using Application = System.Windows.Application;
1415
using Screen = System.Windows.Forms.Screen;
1516
using ContextMenuStrip = System.Windows.Forms.ContextMenuStrip;
1617
using DataFormats = System.Windows.DataFormats;
@@ -46,10 +47,13 @@ public MainWindow()
4647
InitializeComponent();
4748
}
4849

49-
private void OnClosing(object sender, CancelEventArgs e)
50+
private async void OnClosing(object sender, CancelEventArgs e)
5051
{
5152
_notifyIcon.Visible = false;
5253
_viewModel.Save();
54+
e.Cancel = true;
55+
await PluginManager.DisposePluginsAsync();
56+
Application.Current.Shutdown();
5357
}
5458

5559
private void OnInitialized(object sender, EventArgs e)

0 commit comments

Comments
 (0)