diff --git a/Flow.Launcher/PublicAPIInstance.cs b/Flow.Launcher/PublicAPIInstance.cs index c06c5603991..7f0b03445c7 100644 --- a/Flow.Launcher/PublicAPIInstance.cs +++ b/Flow.Launcher/PublicAPIInstance.cs @@ -251,7 +251,7 @@ public Task HttpGetStreamAsync(string url, CancellationToken token = def Http.GetStreamAsync(url, token); public Task HttpDownloadAsync([NotNull] string url, [NotNull] string filePath, Action reportProgress = null, - CancellationToken token = default) =>Http.DownloadAsync(url, filePath, reportProgress, token); + CancellationToken token = default) => Http.DownloadAsync(url, filePath, reportProgress, token); public void AddActionKeyword(string pluginId, string newActionKeyword) => PluginManager.AddActionKeyword(pluginId, newActionKeyword); diff --git a/Plugins/Flow.Launcher.Plugin.PluginsManager/PluginsManager.cs b/Plugins/Flow.Launcher.Plugin.PluginsManager/PluginsManager.cs index a16778ff461..25182f6d3d2 100644 --- a/Plugins/Flow.Launcher.Plugin.PluginsManager/PluginsManager.cs +++ b/Plugins/Flow.Launcher.Plugin.PluginsManager/PluginsManager.cs @@ -316,61 +316,75 @@ where string.Compare(existingPlugin.Metadata.Version, pluginUpdateSource.Version var downloadToFilePath = Path.Combine(Path.GetTempPath(), $"{x.Name}-{x.NewVersion}.zip"); - _ = Task.Run(async delegate + _ = Task.Run(async () => { - using var cts = new CancellationTokenSource(); - - if (!x.PluginNewUserPlugin.IsFromLocalInstallPath) - { - await DownloadFileAsync( - $"{Context.API.GetTranslation("plugin_pluginsmanager_downloading_plugin")} {x.PluginNewUserPlugin.Name}", - x.PluginNewUserPlugin.UrlDownload, downloadToFilePath, cts); - } - else + try { - downloadToFilePath = x.PluginNewUserPlugin.LocalInstallPath; - } + using var cts = new CancellationTokenSource(); - // check if user cancelled download before installing plugin - if (cts.IsCancellationRequested) - { - return; - } - else - { - await Context.API.UpdatePluginAsync(x.PluginExistingMetadata, x.PluginNewUserPlugin, - downloadToFilePath); + if (!x.PluginNewUserPlugin.IsFromLocalInstallPath) + { + await DownloadFileAsync( + $"{Context.API.GetTranslation("plugin_pluginsmanager_downloading_plugin")} {x.PluginNewUserPlugin.Name}", + x.PluginNewUserPlugin.UrlDownload, downloadToFilePath, cts); + } + else + { + downloadToFilePath = x.PluginNewUserPlugin.LocalInstallPath; + } - if (Settings.AutoRestartAfterChanging) + // check if user cancelled download before installing plugin + if (cts.IsCancellationRequested) { - Context.API.ShowMsg( - Context.API.GetTranslation("plugin_pluginsmanager_update_title"), - string.Format( - Context.API.GetTranslation( - "plugin_pluginsmanager_update_success_restart"), - x.Name)); - Context.API.RestartApp(); + return; } else { - Context.API.ShowMsg( - Context.API.GetTranslation("plugin_pluginsmanager_update_title"), - string.Format( - Context.API.GetTranslation( - "plugin_pluginsmanager_update_success_no_restart"), - x.Name)); + await Context.API.UpdatePluginAsync(x.PluginExistingMetadata, x.PluginNewUserPlugin, + downloadToFilePath); + + if (Settings.AutoRestartAfterChanging) + { + Context.API.ShowMsg( + Context.API.GetTranslation("plugin_pluginsmanager_update_title"), + string.Format( + Context.API.GetTranslation( + "plugin_pluginsmanager_update_success_restart"), + x.Name)); + Context.API.RestartApp(); + } + else + { + Context.API.ShowMsg( + Context.API.GetTranslation("plugin_pluginsmanager_update_title"), + string.Format( + Context.API.GetTranslation( + "plugin_pluginsmanager_update_success_no_restart"), + x.Name)); + } } } - }).ContinueWith(t => - { - Context.API.LogException(ClassName, $"Update failed for {x.Name}", - t.Exception.InnerException); - Context.API.ShowMsg( - Context.API.GetTranslation("plugin_pluginsmanager_install_error_title"), - string.Format( - Context.API.GetTranslation("plugin_pluginsmanager_install_error_subtitle"), - x.Name)); - }, token, TaskContinuationOptions.OnlyOnFaulted, TaskScheduler.Default); + catch (HttpRequestException e) + { + // show error message + Context.API.ShowMsgError( + string.Format(Context.API.GetTranslation("plugin_pluginsmanager_downloading_plugin"), x.Name), + Context.API.GetTranslation("plugin_pluginsmanager_download_error")); + Context.API.LogException(ClassName, "An error occurred while downloading plugin", e); + return; + } + catch (Exception e) + { + // show error message + Context.API.LogException(ClassName, $"Update failed for {x.Name}", e); + Context.API.ShowMsgError( + Context.API.GetTranslation("plugin_pluginsmanager_install_error_title"), + string.Format( + Context.API.GetTranslation("plugin_pluginsmanager_install_error_subtitle"), + x.Name)); + return; + } + }); return true; }, @@ -436,7 +450,7 @@ await Context.API.UpdatePluginAsync(plugin.PluginExistingMetadata, plugin.Plugin catch (Exception ex) { Context.API.LogException(ClassName, $"Update failed for {plugin.Name}", ex.InnerException); - Context.API.ShowMsg( + Context.API.ShowMsgError( Context.API.GetTranslation("plugin_pluginsmanager_install_error_title"), string.Format( Context.API.GetTranslation("plugin_pluginsmanager_install_error_subtitle"),