From 5ae9ee46c06c33f2a9aa85c5227187a9b372ea24 Mon Sep 17 00:00:00 2001 From: Hongtao Zhang Date: Sun, 19 Dec 2021 11:35:34 -0600 Subject: [PATCH 1/3] Suppress Startup Manifest Download Error Notification --- .../ExternalPlugins/PluginsManifest.cs | 2 +- .../Main.cs | 20 ++--- .../PluginsManager.cs | 73 ++++++++++--------- 3 files changed, 50 insertions(+), 45 deletions(-) diff --git a/Flow.Launcher.Core/ExternalPlugins/PluginsManifest.cs b/Flow.Launcher.Core/ExternalPlugins/PluginsManifest.cs index c0cd022eaa7..a9585f6a4f9 100644 --- a/Flow.Launcher.Core/ExternalPlugins/PluginsManifest.cs +++ b/Flow.Launcher.Core/ExternalPlugins/PluginsManifest.cs @@ -31,7 +31,7 @@ public static Task UpdateManifestAsync() return UpdateTask = DownloadManifestAsync(); } - private async static Task DownloadManifestAsync() + private static async Task DownloadManifestAsync() { try { diff --git a/Plugins/Flow.Launcher.Plugin.PluginsManager/Main.cs b/Plugins/Flow.Launcher.Plugin.PluginsManager/Main.cs index f445826fa8c..8aaae95d65c 100644 --- a/Plugins/Flow.Launcher.Plugin.PluginsManager/Main.cs +++ b/Plugins/Flow.Launcher.Plugin.PluginsManager/Main.cs @@ -38,10 +38,12 @@ public Task InitAsync(PluginInitContext context) viewModel = new SettingsViewModel(context, Settings); contextMenu = new ContextMenu(Context); pluginManager = new PluginsManager(Context, Settings); - _manifestUpdateTask = pluginManager.UpdateManifestAsync().ContinueWith(_ => - { - lastUpdateTime = DateTime.Now; - }, TaskContinuationOptions.OnlyOnRanToCompletion); + _manifestUpdateTask = pluginManager + .UpdateManifestAsync(true) + .ContinueWith(_ => + { + lastUpdateTime = DateTime.Now; + }, TaskContinuationOptions.OnlyOnRanToCompletion); return Task.CompletedTask; } @@ -50,7 +52,7 @@ public List LoadContextMenus(Result selectedResult) { return contextMenu.LoadContextMenus(selectedResult); } - + private Task _manifestUpdateTask = Task.CompletedTask; public async Task> QueryAsync(Query query, CancellationToken token) @@ -72,11 +74,11 @@ public async Task> QueryAsync(Query query, CancellationToken token) { //search could be url, no need ToLower() when passed in var s when s.StartsWith(Settings.HotKeyInstall, StringComparison.OrdinalIgnoreCase) - => await pluginManager.RequestInstallOrUpdate(search, token), + => await pluginManager.RequestInstallOrUpdate(search, token), var s when s.StartsWith(Settings.HotkeyUninstall, StringComparison.OrdinalIgnoreCase) - => pluginManager.RequestUninstall(search), - var s when s.StartsWith(Settings.HotkeyUpdate, StringComparison.OrdinalIgnoreCase) - => await pluginManager.RequestUpdate(search, token), + => pluginManager.RequestUninstall(search), + var s when s.StartsWith(Settings.HotkeyUpdate, StringComparison.OrdinalIgnoreCase) + => await pluginManager.RequestUpdate(search, token), _ => pluginManager.GetDefaultHotKeys().Where(hotkey => { hotkey.Score = StringMatcher.FuzzySearch(search, hotkey.Title).Score; diff --git a/Plugins/Flow.Launcher.Plugin.PluginsManager/PluginsManager.cs b/Plugins/Flow.Launcher.Plugin.PluginsManager/PluginsManager.cs index a2f580ee113..8d4177c2b66 100644 --- a/Plugins/Flow.Launcher.Plugin.PluginsManager/PluginsManager.cs +++ b/Plugins/Flow.Launcher.Plugin.PluginsManager/PluginsManager.cs @@ -51,7 +51,7 @@ internal PluginsManager(PluginInitContext context, Settings settings) private Task _downloadManifestTask = Task.CompletedTask; - internal Task UpdateManifestAsync() + internal Task UpdateManifestAsync(bool silent = false) { if (_downloadManifestTask.Status == TaskStatus.Running) { @@ -60,10 +60,11 @@ internal Task UpdateManifestAsync() else { _downloadManifestTask = PluginsManifest.UpdateTask; - _downloadManifestTask.ContinueWith(_ => - Context.API.ShowMsg(Context.API.GetTranslation("plugin_pluginsmanager_update_failed_title"), - Context.API.GetTranslation("plugin_pluginsmanager_update_failed_subtitle"), icoPath, false), - TaskContinuationOptions.OnlyOnFaulted); + if (!silent) + _downloadManifestTask.ContinueWith(_ => + Context.API.ShowMsg(Context.API.GetTranslation("plugin_pluginsmanager_update_failed_title"), + Context.API.GetTranslation("plugin_pluginsmanager_update_failed_subtitle"), icoPath, false), + TaskContinuationOptions.OnlyOnFaulted); return _downloadManifestTask; } } @@ -113,8 +114,8 @@ internal async Task InstallOrUpdate(UserPlugin plugin) .Any(x => x.Metadata.ID == plugin.ID && x.Metadata.Version.CompareTo(plugin.Version) < 0)) { if (MessageBox.Show(Context.API.GetTranslation("plugin_pluginsmanager_update_exists"), - Context.API.GetTranslation("plugin_pluginsmanager_update_title"), - MessageBoxButton.YesNo) == MessageBoxResult.Yes) + Context.API.GetTranslation("plugin_pluginsmanager_update_title"), + MessageBoxButton.YesNo) == MessageBoxResult.Yes) Context .API .ChangeQuery( @@ -138,13 +139,13 @@ internal async Task InstallOrUpdate(UserPlugin plugin) Environment.NewLine, Environment.NewLine); if (MessageBox.Show(message, Context.API.GetTranslation("plugin_pluginsmanager_install_title"), - MessageBoxButton.YesNo) == MessageBoxResult.No) + MessageBoxButton.YesNo) == MessageBoxResult.No) return; // at minimum should provide a name, but handle plugin that is not downloaded from plugins manifest and is a url download var downloadFilename = string.IsNullOrEmpty(plugin.Version) - ? $"{plugin.Name}-{Guid.NewGuid()}.zip" - : $"{plugin.Name}-{plugin.Version}.zip"; + ? $"{plugin.Name}-{Guid.NewGuid()}.zip" + : $"{plugin.Name}-{plugin.Version}.zip"; var filePath = Path.Combine(DataLocation.PluginsDirectory, downloadFilename); @@ -161,7 +162,7 @@ internal async Task InstallOrUpdate(UserPlugin plugin) { if (e is HttpRequestException) MessageBox.Show(Context.API.GetTranslation("plugin_pluginsmanager_download_error"), - Context.API.GetTranslation("plugin_pluginsmanager_downloading_plugin")); + Context.API.GetTranslation("plugin_pluginsmanager_downloading_plugin")); Context.API.ShowMsgError(Context.API.GetTranslation("plugin_pluginsmanager_install_error_title"), string.Format(Context.API.GetTranslation("plugin_pluginsmanager_install_error_subtitle"), @@ -173,7 +174,7 @@ internal async Task InstallOrUpdate(UserPlugin plugin) } Context.API.ShowMsg(Context.API.GetTranslation("plugin_pluginsmanager_install_title"), - Context.API.GetTranslation("plugin_pluginsmanager_install_success_restart")); + Context.API.GetTranslation("plugin_pluginsmanager_install_success_restart")); Context.API.RestartApp(); } @@ -241,8 +242,8 @@ where existingPlugin.Metadata.Version.CompareTo(pluginFromManifest.Version) < Environment.NewLine, Environment.NewLine); if (MessageBox.Show(message, - Context.API.GetTranslation("plugin_pluginsmanager_update_title"), - MessageBoxButton.YesNo) == MessageBoxResult.Yes) + Context.API.GetTranslation("plugin_pluginsmanager_update_title"), + MessageBoxButton.YesNo) == MessageBoxResult.Yes) { Uninstall(x.PluginExistingMetadata, false); @@ -277,11 +278,10 @@ await Http.DownloadAsync(x.PluginNewUserPlugin.UrlDownload, downloadToFilePath) return false; }, - ContextData = + ContextData = new UserPlugin { - Website = x.PluginNewUserPlugin.Website, - UrlSourceCode = x.PluginNewUserPlugin.UrlSourceCode + Website = x.PluginNewUserPlugin.Website, UrlSourceCode = x.PluginNewUserPlugin.UrlSourceCode } }); @@ -340,21 +340,24 @@ internal List InstallFromWeb(string url) if (Settings.WarnFromUnknownSource) { if (!InstallSourceKnown(plugin.UrlDownload) - && MessageBox.Show(string.Format(Context.API.GetTranslation("plugin_pluginsmanager_install_unknown_source_warning"), - Environment.NewLine), - Context.API.GetTranslation("plugin_pluginsmanager_install_unknown_source_warning_title"), - MessageBoxButton.YesNo) == MessageBoxResult.No) + && MessageBox.Show(string.Format(Context.API.GetTranslation("plugin_pluginsmanager_install_unknown_source_warning"), + Environment.NewLine), + Context.API.GetTranslation("plugin_pluginsmanager_install_unknown_source_warning_title"), + MessageBoxButton.YesNo) == MessageBoxResult.No) return false; } Application.Current.MainWindow.Hide(); _ = InstallOrUpdate(plugin); - + return ShouldHideWindow; } }; - return new List { result }; + return new List + { + result + }; } private bool InstallSourceKnown(string url) @@ -377,7 +380,7 @@ internal async ValueTask> RequestInstallOrUpdate(string searchName, var searchNameWithoutKeyword = searchName.Replace(Settings.HotKeyInstall, string.Empty, StringComparison.OrdinalIgnoreCase).Trim(); - if (Uri.IsWellFormedUriString(searchNameWithoutKeyword, UriKind.Absolute) + if (Uri.IsWellFormedUriString(searchNameWithoutKeyword, UriKind.Absolute) && searchNameWithoutKeyword.Split('.').Last() == zip) return InstallFromWeb(searchNameWithoutKeyword); @@ -438,21 +441,21 @@ private void Install(UserPlugin plugin, string downloadedFilePath) if (string.IsNullOrEmpty(metadataJsonFilePath) || string.IsNullOrEmpty(pluginFolderPath)) { MessageBox.Show(Context.API.GetTranslation("plugin_pluginsmanager_install_errormetadatafile"), - Context.API.GetTranslation("plugin_pluginsmanager_install_error_title")); - - throw new FileNotFoundException ( + Context.API.GetTranslation("plugin_pluginsmanager_install_error_title")); + + throw new FileNotFoundException( string.Format("Unable to find plugin.json from the extracted zip file, or this path {0} does not exist", pluginFolderPath)); } if (SameOrLesserPluginVersionExists(metadataJsonFilePath)) { MessageBox.Show(string.Format(Context.API.GetTranslation("plugin_pluginsmanager_install_error_duplicate"), plugin.Name), - Context.API.GetTranslation("plugin_pluginsmanager_install_error_title")); + Context.API.GetTranslation("plugin_pluginsmanager_install_error_title")); throw new InvalidOperationException( string.Format("A plugin with the same ID and version already exists, " + - "or the version is greater than this downloaded plugin {0}", - plugin.Name)); + "or the version is greater than this downloaded plugin {0}", + plugin.Name)); } var directory = string.IsNullOrEmpty(plugin.Version) ? $"{plugin.Name}-{Guid.NewGuid()}" : $"{plugin.Name}-{plugin.Version}"; @@ -491,8 +494,8 @@ internal List RequestUninstall(string search) Environment.NewLine, Environment.NewLine); if (MessageBox.Show(message, - Context.API.GetTranslation("plugin_pluginsmanager_uninstall_title"), - MessageBoxButton.YesNo) == MessageBoxResult.Yes) + Context.API.GetTranslation("plugin_pluginsmanager_uninstall_title"), + MessageBoxButton.YesNo) == MessageBoxResult.Yes) { Application.Current.MainWindow.Hide(); Uninstall(x.Metadata); @@ -554,8 +557,8 @@ private bool SameOrLesserPluginVersionExists(string metadataPath) { var newMetadata = JsonSerializer.Deserialize(File.ReadAllText(metadataPath)); return Context.API.GetAllPlugins() - .Any(x => x.Metadata.ID == newMetadata.ID - && newMetadata.Version.CompareTo(x.Metadata.Version) <= 0); + .Any(x => x.Metadata.ID == newMetadata.ID + && newMetadata.Version.CompareTo(x.Metadata.Version) <= 0); } } -} +} \ No newline at end of file From a42df2aacd0cb91c353d89af00ccfc60a1a1ca1f Mon Sep 17 00:00:00 2001 From: Hongtao Zhang Date: Sun, 19 Dec 2021 11:37:27 -0600 Subject: [PATCH 2/3] Suppress Startup Update error Notifcation --- Flow.Launcher.Core/Updater.cs | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/Flow.Launcher.Core/Updater.cs b/Flow.Launcher.Core/Updater.cs index e09c6380c5d..69b537b3914 100644 --- a/Flow.Launcher.Core/Updater.cs +++ b/Flow.Launcher.Core/Updater.cs @@ -91,8 +91,9 @@ public async Task UpdateAppAsync(IPublicAPI api, bool silentUpdate = true) catch (Exception e) when (e is HttpRequestException or WebException or SocketException || e.InnerException is TimeoutException) { Log.Exception($"|Updater.UpdateApp|Check your connection and proxy settings to github-cloud.s3.amazonaws.com.", e); - api.ShowMsg(api.GetTranslation("update_flowlauncher_fail"), - api.GetTranslation("update_flowlauncher_check_connection")); + if (!silentUpdate) + api.ShowMsg(api.GetTranslation("update_flowlauncher_fail"), + api.GetTranslation("update_flowlauncher_check_connection")); } finally { @@ -124,7 +125,7 @@ private async Task GitHubUpdateManager(string repository) var releases = await System.Text.Json.JsonSerializer.DeserializeAsync>(jsonStream).ConfigureAwait(false); var latest = releases.Where(r => !r.Prerelease).OrderByDescending(r => r.PublishedAt).First(); var latestUrl = latest.HtmlUrl.Replace("/tag/", "/download/"); - + var client = new WebClient { Proxy = Http.WebProxy From 7d9bd3ae4806643d3acbf4c04607d16f13f67cfc Mon Sep 17 00:00:00 2001 From: Jeremy Date: Mon, 20 Dec 2021 08:35:09 +1100 Subject: [PATCH 3/3] version bump PluginsManager --- Plugins/Flow.Launcher.Plugin.PluginsManager/plugin.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Plugins/Flow.Launcher.Plugin.PluginsManager/plugin.json b/Plugins/Flow.Launcher.Plugin.PluginsManager/plugin.json index c46ea91d94b..de1604d4b57 100644 --- a/Plugins/Flow.Launcher.Plugin.PluginsManager/plugin.json +++ b/Plugins/Flow.Launcher.Plugin.PluginsManager/plugin.json @@ -6,7 +6,7 @@ "Name": "Plugins Manager", "Description": "Management of installing, uninstalling or updating Flow Launcher plugins", "Author": "Jeremy Wu", - "Version": "1.11.0", + "Version": "1.11.1", "Language": "csharp", "Website": "https://github.com/Flow-Launcher/Flow.Launcher", "ExecuteFileName": "Flow.Launcher.Plugin.PluginsManager.dll",