From 07bb16c8f30813eece608b09cde5bbced5ac91a3 Mon Sep 17 00:00:00 2001 From: Jack251970 <1160210343@qq.com> Date: Sun, 5 Jan 2025 21:08:23 +0800 Subject: [PATCH] Improve code quality --- .../PluginsManager.cs | 38 +++++++++++-------- 1 file changed, 22 insertions(+), 16 deletions(-) diff --git a/Plugins/Flow.Launcher.Plugin.PluginsManager/PluginsManager.cs b/Plugins/Flow.Launcher.Plugin.PluginsManager/PluginsManager.cs index a1b37f428..f1c634640 100644 --- a/Plugins/Flow.Launcher.Plugin.PluginsManager/PluginsManager.cs +++ b/Plugins/Flow.Launcher.Plugin.PluginsManager/PluginsManager.cs @@ -161,7 +161,7 @@ namespace Flow.Launcher.Plugin.PluginsManager if (canReportProgress && (prgBox = Context.API.ShowProgressBox($"Download {plugin.Name}...", () => - { + { httpClient.CancelPendingRequests(); downloadCancelled = true; prgBox = null; @@ -209,32 +209,31 @@ namespace Flow.Launcher.Plugin.PluginsManager else { filePath = plugin.LocalInstallPath; - Install(plugin, filePath); - } + Install(plugin, filePath); + } } catch (HttpRequestException e) { + // force close progress box + Application.Current.Dispatcher.Invoke(() => + { + if (prgBox != null) + { + prgBox.Close(); + prgBox = null; + } + }); + + // show error message Context.API.ShowMsgError( string.Format(Context.API.GetTranslation("plugin_pluginsmanager_downloading_plugin"), plugin.Name), Context.API.GetTranslation("plugin_pluginsmanager_download_error")); Log.Exception("PluginsManager", "An error occurred while downloading plugin", e); - // force close progress box - Application.Current.Dispatcher.Invoke(() => - { - if (prgBox != null) - { - prgBox.Close(); - prgBox = null; - } - }); + return; } catch (Exception e) { - Context.API.ShowMsgError(Context.API.GetTranslation("plugin_pluginsmanager_install_error_title"), - string.Format(Context.API.GetTranslation("plugin_pluginsmanager_install_error_subtitle"), - plugin.Name)); - Log.Exception("PluginsManager", "An error occurred while downloading plugin", e); // force close progress box Application.Current.Dispatcher.Invoke(() => { @@ -244,6 +243,13 @@ namespace Flow.Launcher.Plugin.PluginsManager prgBox = null; } }); + + // show error message + Context.API.ShowMsgError(Context.API.GetTranslation("plugin_pluginsmanager_install_error_title"), + string.Format(Context.API.GetTranslation("plugin_pluginsmanager_install_error_subtitle"), + plugin.Name)); + Log.Exception("PluginsManager", "An error occurred while downloading plugin", e); + return; }