Extract duplicate cleanup code into a method

This commit is contained in:
Jack251970 2025-01-06 21:26:05 +08:00
parent 0fabe31fe4
commit cc0fb66b22

View file

@ -196,11 +196,7 @@ namespace Flow.Launcher.Plugin.PluginsManager
if (downloadCancelled)
return;
else
Application.Current.Dispatcher.Invoke(() =>
{
prgBox.Close();
prgBox = null;
});
CleanupProgressBoxEx(prgBox);
}
else
{
@ -221,14 +217,7 @@ namespace Flow.Launcher.Plugin.PluginsManager
catch (HttpRequestException e)
{
// force close progress box
Application.Current.Dispatcher.Invoke(() =>
{
if (prgBox != null)
{
prgBox.Close();
prgBox = null;
}
});
CleanupProgressBoxEx(prgBox);
// show error message
Context.API.ShowMsgError(
@ -241,14 +230,7 @@ namespace Flow.Launcher.Plugin.PluginsManager
catch (Exception e)
{
// force close progress box
Application.Current.Dispatcher.Invoke(() =>
{
if (prgBox != null)
{
prgBox.Close();
prgBox = null;
}
});
CleanupProgressBoxEx(prgBox);
// show error message
Context.API.ShowMsgError(Context.API.GetTranslation("plugin_pluginsmanager_install_error_title"),
@ -274,6 +256,14 @@ namespace Flow.Launcher.Plugin.PluginsManager
}
}
private static void CleanupProgressBoxEx(IProgressBoxEx prgBox)
{
Application.Current.Dispatcher.Invoke(() =>
{
prgBox?.Close();
});
}
internal async ValueTask<List<Result>> RequestUpdateAsync(string search, CancellationToken token,
bool usePrimaryUrlOnly = false)
{