Skip to content

Commit cc0fb66

Browse files
committed
Extract duplicate cleanup code into a method
1 parent 0fabe31 commit cc0fb66

File tree

1 file changed

+11
-21
lines changed

1 file changed

+11
-21
lines changed

Plugins/Flow.Launcher.Plugin.PluginsManager/PluginsManager.cs

Lines changed: 11 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -196,11 +196,7 @@ internal async Task InstallOrUpdateAsync(UserPlugin plugin)
196196
if (downloadCancelled)
197197
return;
198198
else
199-
Application.Current.Dispatcher.Invoke(() =>
200-
{
201-
prgBox.Close();
202-
prgBox = null;
203-
});
199+
CleanupProgressBoxEx(prgBox);
204200
}
205201
else
206202
{
@@ -221,14 +217,7 @@ internal async Task InstallOrUpdateAsync(UserPlugin plugin)
221217
catch (HttpRequestException e)
222218
{
223219
// force close progress box
224-
Application.Current.Dispatcher.Invoke(() =>
225-
{
226-
if (prgBox != null)
227-
{
228-
prgBox.Close();
229-
prgBox = null;
230-
}
231-
});
220+
CleanupProgressBoxEx(prgBox);
232221

233222
// show error message
234223
Context.API.ShowMsgError(
@@ -241,14 +230,7 @@ internal async Task InstallOrUpdateAsync(UserPlugin plugin)
241230
catch (Exception e)
242231
{
243232
// force close progress box
244-
Application.Current.Dispatcher.Invoke(() =>
245-
{
246-
if (prgBox != null)
247-
{
248-
prgBox.Close();
249-
prgBox = null;
250-
}
251-
});
233+
CleanupProgressBoxEx(prgBox);
252234

253235
// show error message
254236
Context.API.ShowMsgError(Context.API.GetTranslation("plugin_pluginsmanager_install_error_title"),
@@ -274,6 +256,14 @@ internal async Task InstallOrUpdateAsync(UserPlugin plugin)
274256
}
275257
}
276258

259+
private static void CleanupProgressBoxEx(IProgressBoxEx prgBox)
260+
{
261+
Application.Current.Dispatcher.Invoke(() =>
262+
{
263+
prgBox?.Close();
264+
});
265+
}
266+
277267
internal async ValueTask<List<Result>> RequestUpdateAsync(string search, CancellationToken token,
278268
bool usePrimaryUrlOnly = false)
279269
{

0 commit comments

Comments
 (0)