From 3300523b9f64487242a3b1b83aed52c0eab96dc2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BC=98=E9=9F=AC=20=E5=BC=A0?= Date: Sun, 21 Feb 2021 15:46:04 +0800 Subject: [PATCH 01/21] add taskcanceledexception to updater exception catch --- Flow.Launcher.Core/Updater.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Flow.Launcher.Core/Updater.cs b/Flow.Launcher.Core/Updater.cs index 44c34968c55..8f0de798cc5 100644 --- a/Flow.Launcher.Core/Updater.cs +++ b/Flow.Launcher.Core/Updater.cs @@ -87,7 +87,7 @@ public async Task UpdateApp(IPublicAPI api, bool silentUpdate = true) UpdateManager.RestartApp(Constant.ApplicationFileName); } } - catch (Exception e) when (e is HttpRequestException || e is WebException || e is SocketException) + catch (Exception e) when (e is HttpRequestException || e is WebException || e is SocketException || e is TaskCanceledException) { Log.Exception($"|Updater.UpdateApp|Check your connection and proxy settings to github-cloud.s3.amazonaws.com.", e); api.ShowMsg(api.GetTranslation("update_flowlauncher_fail"), From 409efe41f28fed1f0a8765f3c6544d4bb8088b8f Mon Sep 17 00:00:00 2001 From: Jeremy Wu Date: Mon, 22 Feb 2021 05:10:44 +1100 Subject: [PATCH 02/21] version bump --- SolutionAssemblyInfo.cs | 6 +++--- appveyor.yml | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/SolutionAssemblyInfo.cs b/SolutionAssemblyInfo.cs index 7f13f41306a..bcddbd1bddf 100644 --- a/SolutionAssemblyInfo.cs +++ b/SolutionAssemblyInfo.cs @@ -16,6 +16,6 @@ [assembly: AssemblyTrademark("")] [assembly: AssemblyCulture("")] [assembly: ComVisible(false)] -[assembly: AssemblyVersion("1.7.1")] -[assembly: AssemblyFileVersion("1.7.1")] -[assembly: AssemblyInformationalVersion("1.7.1")] \ No newline at end of file +[assembly: AssemblyVersion("1.7.2")] +[assembly: AssemblyFileVersion("1.7.2")] +[assembly: AssemblyInformationalVersion("1.7.2")] \ No newline at end of file diff --git a/appveyor.yml b/appveyor.yml index 6340318d474..299a829bac5 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -1,4 +1,4 @@ -version: '1.7.1.{build}' +version: '1.7.2.{build}' init: - ps: | From f23f3d3e7fb28f6a06594e0e462101bc7b4a205f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BC=98=E9=9F=AC=20=E5=BC=A0?= Date: Fri, 19 Feb 2021 05:05:03 +0800 Subject: [PATCH 03/21] don't remove setting when updating --- .../PluginsManager.cs | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/Plugins/Flow.Launcher.Plugin.PluginsManager/PluginsManager.cs b/Plugins/Flow.Launcher.Plugin.PluginsManager/PluginsManager.cs index 90d103bc712..7baa08a7b8c 100644 --- a/Plugins/Flow.Launcher.Plugin.PluginsManager/PluginsManager.cs +++ b/Plugins/Flow.Launcher.Plugin.PluginsManager/PluginsManager.cs @@ -212,7 +212,7 @@ where existingPlugin.Metadata.Version.CompareTo(pluginFromManifest.Version) < Context.API.GetTranslation("plugin_pluginsmanager_update_title"), MessageBoxButton.YesNo) == MessageBoxResult.Yes) { - Uninstall(x.PluginExistingMetadata); + Uninstall(x.PluginExistingMetadata, false); var downloadToFilePath = Path.Combine(DataLocation.PluginsDirectory, $"{x.Name}-{x.NewVersion}.zip"); @@ -399,10 +399,13 @@ internal List RequestUninstall(string search) return Search(results, uninstallSearch); } - private void Uninstall(PluginMetadata plugin) + private void Uninstall(PluginMetadata plugin, bool removedSetting = true) { - PluginManager.Settings.Plugins.Remove(plugin.ID); - PluginManager.AllPlugins.RemoveAll(p => p.Metadata.ID == plugin.ID); + if (removedSetting) + { + PluginManager.Settings.Plugins.Remove(plugin.ID); + PluginManager.AllPlugins.RemoveAll(p => p.Metadata.ID == plugin.ID); + } // Marked for deletion. Will be deleted on next start up using var _ = File.CreateText(Path.Combine(plugin.PluginDirectory, "NeedDelete.txt")); From c8f6853c94ff9796809eec802b5ea02231976e45 Mon Sep 17 00:00:00 2001 From: Jeremy Wu Date: Mon, 22 Feb 2021 05:24:04 +1100 Subject: [PATCH 04/21] temporary version bump PluginsManager temp bump for hot fix release. Release from dev should follow the existing commits- 1.7.1 --- 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 4cba7ec83e8..66b438fd5ad 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.6.4", + "Version": "1.6.5", "Language": "csharp", "Website": "https://github.com/Flow-Launcher/Flow.Launcher", "ExecuteFileName": "Flow.Launcher.Plugin.PluginsManager.dll", From b2f841ebb958d8f49aa35a4ac43222e79e0eec6c Mon Sep 17 00:00:00 2001 From: Jeremy Wu Date: Wed, 17 Feb 2021 08:50:33 +1100 Subject: [PATCH 05/21] remove duplicate entry with quick access results --- Plugins/Flow.Launcher.Plugin.Explorer/Search/SearchManager.cs | 2 +- Plugins/Flow.Launcher.Plugin.Explorer/plugin.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Plugins/Flow.Launcher.Plugin.Explorer/Search/SearchManager.cs b/Plugins/Flow.Launcher.Plugin.Explorer/Search/SearchManager.cs index 2af09bf2cbb..899412be62e 100644 --- a/Plugins/Flow.Launcher.Plugin.Explorer/Search/SearchManager.cs +++ b/Plugins/Flow.Launcher.Plugin.Explorer/Search/SearchManager.cs @@ -38,7 +38,7 @@ internal async Task> SearchAsync(Query query, CancellationToken tok var quickaccessLinks = QuickAccess.AccessLinkListMatched(query, settings.QuickAccessLinks); if (quickaccessLinks.Count > 0) - results.AddRange(quickaccessLinks); + results.Union(quickaccessLinks); var isEnvironmentVariable = EnvironmentVariables.IsEnvironmentVariableSearch(querySearch); diff --git a/Plugins/Flow.Launcher.Plugin.Explorer/plugin.json b/Plugins/Flow.Launcher.Plugin.Explorer/plugin.json index 9aa54fb8392..63ca66a1e50 100644 --- a/Plugins/Flow.Launcher.Plugin.Explorer/plugin.json +++ b/Plugins/Flow.Launcher.Plugin.Explorer/plugin.json @@ -7,7 +7,7 @@ "Name": "Explorer", "Description": "Search and manage files and folders. Explorer utilises Windows Index Search", "Author": "Jeremy Wu", - "Version": "1.7.0", + "Version": "1.7.1", "Language": "csharp", "Website": "https://github.com/Flow-Launcher/Flow.Launcher", "ExecuteFileName": "Flow.Launcher.Plugin.Explorer.dll", From 857ff739547e96ac3bde141ee68a4dab903f6aa1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BC=98=E9=9F=AC=20=E5=BC=A0?= Date: Wed, 17 Feb 2021 22:36:35 +0800 Subject: [PATCH 06/21] Use IReadOnlyCollection to avoid avoid duplicate iteration Add distinct to NewResults to try avoiding duplicate result --- Flow.Launcher/ViewModel/MainViewModel.cs | 2 +- Flow.Launcher/ViewModel/ResultsViewModel.cs | 13 ++++++------- 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/Flow.Launcher/ViewModel/MainViewModel.cs b/Flow.Launcher/ViewModel/MainViewModel.cs index afbe6e19758..6d92b0c6570 100644 --- a/Flow.Launcher/ViewModel/MainViewModel.cs +++ b/Flow.Launcher/ViewModel/MainViewModel.cs @@ -748,7 +748,7 @@ public void Save() /// /// To avoid deadlock, this method should not called from main thread /// - public void UpdateResultView(IEnumerable resultsForUpdates) + public void UpdateResultView(IReadOnlyCollection resultsForUpdates) { if (!resultsForUpdates.Any()) return; diff --git a/Flow.Launcher/ViewModel/ResultsViewModel.cs b/Flow.Launcher/ViewModel/ResultsViewModel.cs index feab3a7513d..a087304887c 100644 --- a/Flow.Launcher/ViewModel/ResultsViewModel.cs +++ b/Flow.Launcher/ViewModel/ResultsViewModel.cs @@ -1,16 +1,13 @@ -using System; +using Flow.Launcher.Infrastructure.UserSettings; +using Flow.Launcher.Plugin; using System.Collections.Generic; -using System.Collections.ObjectModel; using System.Collections.Specialized; using System.Linq; using System.Threading; -using System.Threading.Tasks; using System.Windows; using System.Windows.Controls; using System.Windows.Data; using System.Windows.Documents; -using Flow.Launcher.Infrastructure.UserSettings; -using Flow.Launcher.Plugin; namespace Flow.Launcher.ViewModel { @@ -146,7 +143,7 @@ public void AddResults(List newRawResults, string resultId) /// /// To avoid deadlock, this method should not called from main thread /// - public void AddResults(IEnumerable resultsForUpdates, CancellationToken token) + public void AddResults(IReadOnlyCollection resultsForUpdates, CancellationToken token) { var newResults = NewResults(resultsForUpdates); @@ -192,10 +189,11 @@ private List NewResults(List newRawResults, string resu return results.Where(r => r.Result.PluginID != resultId) .Concat(newResults) .OrderByDescending(r => r.Result.Score) + .Distinct() .ToList(); } - private List NewResults(IEnumerable resultsForUpdates) + private List NewResults(IReadOnlyCollection resultsForUpdates) { if (!resultsForUpdates.Any()) return Results.ToList(); @@ -205,6 +203,7 @@ private List NewResults(IEnumerable resultsFo return results.Where(r => r != null && !resultsForUpdates.Any(u => u.Metadata.ID == r.Result.PluginID)) .Concat(resultsForUpdates.SelectMany(u => u.Results, (u, r) => new ResultViewModel(r, _settings))) .OrderByDescending(rv => rv.Result.Score) + .Distinct() .ToList(); } #endregion From 6543e4f335584730f3af7eaf4f90898c27c30247 Mon Sep 17 00:00:00 2001 From: Jeremy Wu Date: Thu, 18 Feb 2021 08:09:51 +1100 Subject: [PATCH 07/21] update --- Plugins/Flow.Launcher.Plugin.Explorer/Search/SearchManager.cs | 2 +- Plugins/Flow.Launcher.Plugin.Explorer/plugin.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Plugins/Flow.Launcher.Plugin.Explorer/Search/SearchManager.cs b/Plugins/Flow.Launcher.Plugin.Explorer/Search/SearchManager.cs index 899412be62e..2af09bf2cbb 100644 --- a/Plugins/Flow.Launcher.Plugin.Explorer/Search/SearchManager.cs +++ b/Plugins/Flow.Launcher.Plugin.Explorer/Search/SearchManager.cs @@ -38,7 +38,7 @@ internal async Task> SearchAsync(Query query, CancellationToken tok var quickaccessLinks = QuickAccess.AccessLinkListMatched(query, settings.QuickAccessLinks); if (quickaccessLinks.Count > 0) - results.Union(quickaccessLinks); + results.AddRange(quickaccessLinks); var isEnvironmentVariable = EnvironmentVariables.IsEnvironmentVariableSearch(querySearch); diff --git a/Plugins/Flow.Launcher.Plugin.Explorer/plugin.json b/Plugins/Flow.Launcher.Plugin.Explorer/plugin.json index 63ca66a1e50..9aa54fb8392 100644 --- a/Plugins/Flow.Launcher.Plugin.Explorer/plugin.json +++ b/Plugins/Flow.Launcher.Plugin.Explorer/plugin.json @@ -7,7 +7,7 @@ "Name": "Explorer", "Description": "Search and manage files and folders. Explorer utilises Windows Index Search", "Author": "Jeremy Wu", - "Version": "1.7.1", + "Version": "1.7.0", "Language": "csharp", "Website": "https://github.com/Flow-Launcher/Flow.Launcher", "ExecuteFileName": "Flow.Launcher.Plugin.Explorer.dll", From 32435bcda5ae12b9cb0fed1530a44467dbfe6539 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BC=98=E9=9F=AC=20=E5=BC=A0?= Date: Thu, 18 Feb 2021 06:38:43 +0800 Subject: [PATCH 08/21] Use Hashset and customized equality comparator to filter result --- .../Search/SearchManager.cs | 28 +++++++++++++++---- 1 file changed, 22 insertions(+), 6 deletions(-) diff --git a/Plugins/Flow.Launcher.Plugin.Explorer/Search/SearchManager.cs b/Plugins/Flow.Launcher.Plugin.Explorer/Search/SearchManager.cs index 2af09bf2cbb..7869b083c13 100644 --- a/Plugins/Flow.Launcher.Plugin.Explorer/Search/SearchManager.cs +++ b/Plugins/Flow.Launcher.Plugin.Explorer/Search/SearchManager.cs @@ -22,9 +22,25 @@ public SearchManager(Settings settings, PluginInitContext context) this.settings = settings; } + private class PathEqualityComparator : IEqualityComparer + { + private static PathEqualityComparator instance; + public static PathEqualityComparator Instance => instance ??= new PathEqualityComparator(); + public bool Equals(Result x, Result y) + { + return x.SubTitle == y.SubTitle; + } + + public int GetHashCode(Result obj) + { + return obj.SubTitle.GetHashCode(); + } + + } + internal async Task> SearchAsync(Query query, CancellationToken token) { - var results = new List(); + var results = new HashSet(PathEqualityComparator.Instance); var querySearch = query.Search; @@ -50,9 +66,9 @@ internal async Task> SearchAsync(Query query, CancellationToken tok if (!querySearch.IsLocationPathString() && !isEnvironmentVariablePath) { - results.AddRange(await WindowsIndexFilesAndFoldersSearchAsync(query, querySearch, token).ConfigureAwait(false)); + results.UnionWith(await WindowsIndexFilesAndFoldersSearchAsync(query, querySearch, token).ConfigureAwait(false)); - return results; + return results.ToList(); } var locationPath = querySearch; @@ -62,7 +78,7 @@ internal async Task> SearchAsync(Query query, CancellationToken tok // Check that actual location exists, otherwise directory search will throw directory not found exception if (!FilesFolders.LocationExists(FilesFolders.ReturnPreviousDirectoryIfIncompleteString(locationPath))) - return results; + return results.ToList(); var useIndexSearch = UseWindowsIndexForDirectorySearch(locationPath); @@ -79,9 +95,9 @@ internal async Task> SearchAsync(Query query, CancellationToken tok token.ThrowIfCancellationRequested(); - results.AddRange(directoryResult); + results.UnionWith(directoryResult); - return results; + return results.ToList(); } private async Task> WindowsIndexFileContentSearchAsync(Query query, string querySearchString, CancellationToken token) From a4a824dcc3e62d03f76dc2f63b42456758ccb07e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BC=98=E9=9F=AC=20=E5=BC=A0?= Date: Thu, 18 Feb 2021 06:40:26 +0800 Subject: [PATCH 09/21] Merge branch 'fix_duplicate_entry_quickaccess' of github.com:Flow-Launcher/Flow.Launcher into HEAD From 49eb094354d93b5ac2955ee937727eb5417d8296 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BC=98=E9=9F=AC=20=E5=BC=A0?= Date: Thu, 18 Feb 2021 06:41:56 +0800 Subject: [PATCH 10/21] Use UnionWith --- Plugins/Flow.Launcher.Plugin.Explorer/Search/SearchManager.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Plugins/Flow.Launcher.Plugin.Explorer/Search/SearchManager.cs b/Plugins/Flow.Launcher.Plugin.Explorer/Search/SearchManager.cs index 7869b083c13..ff44773368b 100644 --- a/Plugins/Flow.Launcher.Plugin.Explorer/Search/SearchManager.cs +++ b/Plugins/Flow.Launcher.Plugin.Explorer/Search/SearchManager.cs @@ -54,7 +54,7 @@ internal async Task> SearchAsync(Query query, CancellationToken tok var quickaccessLinks = QuickAccess.AccessLinkListMatched(query, settings.QuickAccessLinks); if (quickaccessLinks.Count > 0) - results.AddRange(quickaccessLinks); + results.UnionWith(quickaccessLinks); var isEnvironmentVariable = EnvironmentVariables.IsEnvironmentVariableSearch(querySearch); From cc48ed54a3b7eb41670fcb1ebaac97d638179f64 Mon Sep 17 00:00:00 2001 From: Jeremy Wu Date: Fri, 19 Feb 2021 21:03:23 +1100 Subject: [PATCH 11/21] update --- Flow.Launcher/ViewModel/MainViewModel.cs | 2 +- Flow.Launcher/ViewModel/ResultsViewModel.cs | 6 ++---- .../Flow.Launcher.Plugin.Explorer/Search/SearchManager.cs | 1 - Plugins/Flow.Launcher.Plugin.Explorer/plugin.json | 2 +- 4 files changed, 4 insertions(+), 7 deletions(-) diff --git a/Flow.Launcher/ViewModel/MainViewModel.cs b/Flow.Launcher/ViewModel/MainViewModel.cs index 6d92b0c6570..afbe6e19758 100644 --- a/Flow.Launcher/ViewModel/MainViewModel.cs +++ b/Flow.Launcher/ViewModel/MainViewModel.cs @@ -748,7 +748,7 @@ public void Save() /// /// To avoid deadlock, this method should not called from main thread /// - public void UpdateResultView(IReadOnlyCollection resultsForUpdates) + public void UpdateResultView(IEnumerable resultsForUpdates) { if (!resultsForUpdates.Any()) return; diff --git a/Flow.Launcher/ViewModel/ResultsViewModel.cs b/Flow.Launcher/ViewModel/ResultsViewModel.cs index a087304887c..344dad58e54 100644 --- a/Flow.Launcher/ViewModel/ResultsViewModel.cs +++ b/Flow.Launcher/ViewModel/ResultsViewModel.cs @@ -143,7 +143,7 @@ public void AddResults(List newRawResults, string resultId) /// /// To avoid deadlock, this method should not called from main thread /// - public void AddResults(IReadOnlyCollection resultsForUpdates, CancellationToken token) + public void AddResults(IEnumerable resultsForUpdates, CancellationToken token) { var newResults = NewResults(resultsForUpdates); @@ -189,11 +189,10 @@ private List NewResults(List newRawResults, string resu return results.Where(r => r.Result.PluginID != resultId) .Concat(newResults) .OrderByDescending(r => r.Result.Score) - .Distinct() .ToList(); } - private List NewResults(IReadOnlyCollection resultsForUpdates) + private List NewResults(IEnumerable resultsForUpdates) { if (!resultsForUpdates.Any()) return Results.ToList(); @@ -203,7 +202,6 @@ private List NewResults(IReadOnlyCollection r return results.Where(r => r != null && !resultsForUpdates.Any(u => u.Metadata.ID == r.Result.PluginID)) .Concat(resultsForUpdates.SelectMany(u => u.Results, (u, r) => new ResultViewModel(r, _settings))) .OrderByDescending(rv => rv.Result.Score) - .Distinct() .ToList(); } #endregion diff --git a/Plugins/Flow.Launcher.Plugin.Explorer/Search/SearchManager.cs b/Plugins/Flow.Launcher.Plugin.Explorer/Search/SearchManager.cs index ff44773368b..d5f882d5ca6 100644 --- a/Plugins/Flow.Launcher.Plugin.Explorer/Search/SearchManager.cs +++ b/Plugins/Flow.Launcher.Plugin.Explorer/Search/SearchManager.cs @@ -35,7 +35,6 @@ public int GetHashCode(Result obj) { return obj.SubTitle.GetHashCode(); } - } internal async Task> SearchAsync(Query query, CancellationToken token) diff --git a/Plugins/Flow.Launcher.Plugin.Explorer/plugin.json b/Plugins/Flow.Launcher.Plugin.Explorer/plugin.json index 9aa54fb8392..63ca66a1e50 100644 --- a/Plugins/Flow.Launcher.Plugin.Explorer/plugin.json +++ b/Plugins/Flow.Launcher.Plugin.Explorer/plugin.json @@ -7,7 +7,7 @@ "Name": "Explorer", "Description": "Search and manage files and folders. Explorer utilises Windows Index Search", "Author": "Jeremy Wu", - "Version": "1.7.0", + "Version": "1.7.1", "Language": "csharp", "Website": "https://github.com/Flow-Launcher/Flow.Launcher", "ExecuteFileName": "Flow.Launcher.Plugin.Explorer.dll", From ff5fd5738cbcef72cf4503b95151e09128c70ccf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BC=98=E9=9F=AC=20=E5=BC=A0?= Date: Mon, 22 Feb 2021 11:46:31 +0800 Subject: [PATCH 12/21] fix potential uri format issue causing program crash --- Flow.Launcher.Infrastructure/Http/Http.cs | 40 ++++++++++++++--------- 1 file changed, 25 insertions(+), 15 deletions(-) diff --git a/Flow.Launcher.Infrastructure/Http/Http.cs b/Flow.Launcher.Infrastructure/Http/Http.cs index de2e823590b..8c7328aa335 100644 --- a/Flow.Launcher.Infrastructure/Http/Http.cs +++ b/Flow.Launcher.Infrastructure/Http/Http.cs @@ -50,25 +50,35 @@ public static HttpProxy Proxy /// public static void UpdateProxy(ProxyProperty property) { - (WebProxy.Address, WebProxy.Credentials) = property switch + if (string.IsNullOrEmpty(Proxy.Server)) + return; + + try { - ProxyProperty.Enabled => Proxy.Enabled switch + (WebProxy.Address, WebProxy.Credentials) = property switch { - true => Proxy.UserName switch + ProxyProperty.Enabled => Proxy.Enabled switch { - var userName when !string.IsNullOrEmpty(userName) => - (new Uri($"http://{Proxy.Server}:{Proxy.Port}"), null), - _ => (new Uri($"http://{Proxy.Server}:{Proxy.Port}"), - new NetworkCredential(Proxy.UserName, Proxy.Password)) + true when !string.IsNullOrEmpty(Proxy.Server) => Proxy.UserName switch + { + var userName when string.IsNullOrEmpty(userName) => + (new Uri($"http://{Proxy.Server}:{Proxy.Port}"), null), + _ => (new Uri($"http://{Proxy.Server}:{Proxy.Port}"), + new NetworkCredential(Proxy.UserName, Proxy.Password)) + }, + _ => (null, null) }, - false => (null, null) - }, - ProxyProperty.Server => (new Uri($"http://{Proxy.Server}:{Proxy.Port}"), WebProxy.Credentials), - ProxyProperty.Port => (new Uri($"http://{Proxy.Server}:{Proxy.Port}"), WebProxy.Credentials), - ProxyProperty.UserName => (WebProxy.Address, new NetworkCredential(Proxy.UserName, Proxy.Password)), - ProxyProperty.Password => (WebProxy.Address, new NetworkCredential(Proxy.UserName, Proxy.Password)), - _ => throw new ArgumentOutOfRangeException() - }; + ProxyProperty.Server => (new Uri($"http://{Proxy.Server}:{Proxy.Port}"), WebProxy.Credentials), + ProxyProperty.Port => (new Uri($"http://{Proxy.Server}:{Proxy.Port}"), WebProxy.Credentials), + ProxyProperty.UserName => (WebProxy.Address, new NetworkCredential(Proxy.UserName, Proxy.Password)), + ProxyProperty.Password => (WebProxy.Address, new NetworkCredential(Proxy.UserName, Proxy.Password)), + _ => throw new ArgumentOutOfRangeException() + }; + } + catch(UriFormatException e) + { + Log.Exception("Http", "Unable to parse Uri", e); + } } public static async Task DownloadAsync([NotNull] string url, [NotNull] string filePath, CancellationToken token = default) From 4c2e306cdb663158dd18981fe8fc55c36a6eb2bd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BC=98=E9=9F=AC=20=E5=BC=A0?= Date: Mon, 22 Feb 2021 11:46:57 +0800 Subject: [PATCH 13/21] Merge branch 'dev' of github.com:Flow-Launcher/Flow.Launcher into fixHttpError From a1e85778838893ac796fc7c09f6792bcdb55951c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BC=98=E9=9F=AC=20=E5=BC=A0?= Date: Mon, 22 Feb 2021 12:11:02 +0800 Subject: [PATCH 14/21] Add api to Http.cs & message shown up when error thrown --- Flow.Launcher.Infrastructure/Http/Http.cs | 8 +++++++- Flow.Launcher/App.xaml.cs | 5 ++++- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/Flow.Launcher.Infrastructure/Http/Http.cs b/Flow.Launcher.Infrastructure/Http/Http.cs index 8c7328aa335..a15add76eb1 100644 --- a/Flow.Launcher.Infrastructure/Http/Http.cs +++ b/Flow.Launcher.Infrastructure/Http/Http.cs @@ -9,6 +9,8 @@ using System; using System.ComponentModel; using System.Threading; +using System.Windows.Interop; +using Flow.Launcher.Plugin; namespace Flow.Launcher.Infrastructure.Http { @@ -18,6 +20,8 @@ public static class Http private static HttpClient client = new HttpClient(); + public static IPublicAPI _api { get; set; } + static Http() { // need to be added so it would work on a win10 machine @@ -77,7 +81,9 @@ var userName when string.IsNullOrEmpty(userName) => } catch(UriFormatException e) { - Log.Exception("Http", "Unable to parse Uri", e); + _api.ShowMsg("Please try again", "Unable to parse Http Proxy"); + Log.Exception("Flow.Launcher.Infrastructure.Http", "Unable to parse Uri", e); + } } diff --git a/Flow.Launcher/App.xaml.cs b/Flow.Launcher/App.xaml.cs index 7c4c6a36716..54ede7ff7ae 100644 --- a/Flow.Launcher/App.xaml.cs +++ b/Flow.Launcher/App.xaml.cs @@ -61,7 +61,6 @@ await Stopwatch.NormalAsync("|App.OnStartup|Startup cost", async () => _settingsVM = new SettingWindowViewModel(_updater, _portable); _settings = _settingsVM.Settings; - Http.Proxy = _settings.Proxy; _alphabet.Initialize(_settings); _stringMatcher = new StringMatcher(_alphabet); @@ -74,6 +73,10 @@ await Stopwatch.NormalAsync("|App.OnStartup|Startup cost", async () => await PluginManager.InitializePlugins(API); var window = new MainWindow(_settings, _mainVM); + Http._api = API; + Http.Proxy = _settings.Proxy; + + Log.Info($"|App.OnStartup|Dependencies Info:{ErrorReporting.DependenciesInfo()}"); Current.MainWindow = window; From da59599461032a617ed2c3d153fabdcfc24f5356 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BC=98=E9=9F=AC=20=E5=BC=A0?= Date: Mon, 22 Feb 2021 13:45:28 +0800 Subject: [PATCH 15/21] add Unit test for Http.cs setting --- Flow.Launcher.Test/HttpTest.cs | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 Flow.Launcher.Test/HttpTest.cs diff --git a/Flow.Launcher.Test/HttpTest.cs b/Flow.Launcher.Test/HttpTest.cs new file mode 100644 index 00000000000..96213aba694 --- /dev/null +++ b/Flow.Launcher.Test/HttpTest.cs @@ -0,0 +1,33 @@ +using NUnit.Framework; +using System; +using System.Collections.Generic; +using System.Text; +using Flow.Launcher.Infrastructure.UserSettings; +using Flow.Launcher.Infrastructure.Http; + +namespace Flow.Launcher.Test +{ + [TestFixture] + class HttpTest + { + [Test] + public void TestSettingUpdate() + { + HttpProxy proxy = new HttpProxy(); + Http.Proxy = proxy; + + proxy.Enabled = true; + proxy.Server = "127.0.0.1"; + Assert.AreEqual(Http.WebProxy.Address, new Uri($"http://{proxy.Server}:{proxy.Port}")); + Assert.IsNull(Http.WebProxy.Credentials); + + proxy.UserName = "test"; + Assert.NotNull(Http.WebProxy.Credentials); + Assert.AreEqual(Http.WebProxy.Credentials.GetCredential(Http.WebProxy.Address, "Basic").UserName, proxy.UserName); + Assert.AreEqual(Http.WebProxy.Credentials.GetCredential(Http.WebProxy.Address, "Basic").Password, ""); + + proxy.Password = "test password"; + Assert.AreEqual(Http.WebProxy.Credentials.GetCredential(Http.WebProxy.Address, "Basic").Password, proxy.Password); + } + } +} From b9c37a135151f62311c4599e57ea5be20efc9986 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BC=98=E9=9F=AC=20=E5=BC=A0?= Date: Mon, 22 Feb 2021 13:45:40 +0800 Subject: [PATCH 16/21] Migrate UrlPluginTest to Plugins folder --- Flow.Launcher.Test/{ => Plugins}/UrlPluginTest.cs | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename Flow.Launcher.Test/{ => Plugins}/UrlPluginTest.cs (100%) diff --git a/Flow.Launcher.Test/UrlPluginTest.cs b/Flow.Launcher.Test/Plugins/UrlPluginTest.cs similarity index 100% rename from Flow.Launcher.Test/UrlPluginTest.cs rename to Flow.Launcher.Test/Plugins/UrlPluginTest.cs From 007583911f5c5e2b99a506ceec24e0c390722e40 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BC=98=E9=9F=AC=20=E5=BC=A0?= Date: Mon, 22 Feb 2021 16:58:00 +0800 Subject: [PATCH 17/21] move http proxy initialization earlier than Plugin initialization --- Flow.Launcher/App.xaml.cs | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/Flow.Launcher/App.xaml.cs b/Flow.Launcher/App.xaml.cs index 54ede7ff7ae..7c9697c07ae 100644 --- a/Flow.Launcher/App.xaml.cs +++ b/Flow.Launcher/App.xaml.cs @@ -70,11 +70,14 @@ await Stopwatch.NormalAsync("|App.OnStartup|Startup cost", async () => PluginManager.LoadPlugins(_settings.PluginSettings); _mainVM = new MainViewModel(_settings); API = new PublicAPIInstance(_settingsVM, _mainVM, _alphabet); - await PluginManager.InitializePlugins(API); - var window = new MainWindow(_settings, _mainVM); Http._api = API; Http.Proxy = _settings.Proxy; + + await PluginManager.InitializePlugins(API); + var window = new MainWindow(_settings, _mainVM); + + Log.Info($"|App.OnStartup|Dependencies Info:{ErrorReporting.DependenciesInfo()}"); From c8f15f898eeb37deac871eb1bb40c5d35af43cdb Mon Sep 17 00:00:00 2001 From: Jeremy Wu Date: Mon, 22 Feb 2021 20:31:00 +1100 Subject: [PATCH 18/21] fix formatting --- Flow.Launcher.Infrastructure/Http/Http.cs | 2 +- Flow.Launcher/App.xaml.cs | 3 --- 2 files changed, 1 insertion(+), 4 deletions(-) diff --git a/Flow.Launcher.Infrastructure/Http/Http.cs b/Flow.Launcher.Infrastructure/Http/Http.cs index a15add76eb1..9dc139056ba 100644 --- a/Flow.Launcher.Infrastructure/Http/Http.cs +++ b/Flow.Launcher.Infrastructure/Http/Http.cs @@ -68,7 +68,7 @@ public static void UpdateProxy(ProxyProperty property) var userName when string.IsNullOrEmpty(userName) => (new Uri($"http://{Proxy.Server}:{Proxy.Port}"), null), _ => (new Uri($"http://{Proxy.Server}:{Proxy.Port}"), - new NetworkCredential(Proxy.UserName, Proxy.Password)) + new NetworkCredential(Proxy.UserName, Proxy.Password)) }, _ => (null, null) }, diff --git a/Flow.Launcher/App.xaml.cs b/Flow.Launcher/App.xaml.cs index 7c9697c07ae..56cd5b9617e 100644 --- a/Flow.Launcher/App.xaml.cs +++ b/Flow.Launcher/App.xaml.cs @@ -77,9 +77,6 @@ await Stopwatch.NormalAsync("|App.OnStartup|Startup cost", async () => await PluginManager.InitializePlugins(API); var window = new MainWindow(_settings, _mainVM); - - - Log.Info($"|App.OnStartup|Dependencies Info:{ErrorReporting.DependenciesInfo()}"); Current.MainWindow = window; From ad9b5a48a6550c285fe2834537a0e81a8541ada6 Mon Sep 17 00:00:00 2001 From: Jeremy Wu Date: Mon, 22 Feb 2021 20:33:11 +1100 Subject: [PATCH 19/21] remove space --- Flow.Launcher.Infrastructure/Http/Http.cs | 1 - 1 file changed, 1 deletion(-) diff --git a/Flow.Launcher.Infrastructure/Http/Http.cs b/Flow.Launcher.Infrastructure/Http/Http.cs index 9dc139056ba..b7aaeb676d5 100644 --- a/Flow.Launcher.Infrastructure/Http/Http.cs +++ b/Flow.Launcher.Infrastructure/Http/Http.cs @@ -83,7 +83,6 @@ var userName when string.IsNullOrEmpty(userName) => { _api.ShowMsg("Please try again", "Unable to parse Http Proxy"); Log.Exception("Flow.Launcher.Infrastructure.Http", "Unable to parse Uri", e); - } } From 7c62a2ff11e83d48188c1c492f02a0633bfca5b3 Mon Sep 17 00:00:00 2001 From: Jeremy Wu Date: Mon, 22 Feb 2021 20:36:06 +1100 Subject: [PATCH 20/21] update variable naming convention --- Flow.Launcher.Infrastructure/Http/Http.cs | 4 ++-- Flow.Launcher/App.xaml.cs | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Flow.Launcher.Infrastructure/Http/Http.cs b/Flow.Launcher.Infrastructure/Http/Http.cs index b7aaeb676d5..b3a507c9060 100644 --- a/Flow.Launcher.Infrastructure/Http/Http.cs +++ b/Flow.Launcher.Infrastructure/Http/Http.cs @@ -20,7 +20,7 @@ public static class Http private static HttpClient client = new HttpClient(); - public static IPublicAPI _api { get; set; } + public static IPublicAPI API { get; set; } static Http() { @@ -81,7 +81,7 @@ var userName when string.IsNullOrEmpty(userName) => } catch(UriFormatException e) { - _api.ShowMsg("Please try again", "Unable to parse Http Proxy"); + API.ShowMsg("Please try again", "Unable to parse Http Proxy"); Log.Exception("Flow.Launcher.Infrastructure.Http", "Unable to parse Uri", e); } } diff --git a/Flow.Launcher/App.xaml.cs b/Flow.Launcher/App.xaml.cs index 56cd5b9617e..a2907c927e2 100644 --- a/Flow.Launcher/App.xaml.cs +++ b/Flow.Launcher/App.xaml.cs @@ -71,7 +71,7 @@ await Stopwatch.NormalAsync("|App.OnStartup|Startup cost", async () => _mainVM = new MainViewModel(_settings); API = new PublicAPIInstance(_settingsVM, _mainVM, _alphabet); - Http._api = API; + Http.API = API; Http.Proxy = _settings.Proxy; await PluginManager.InitializePlugins(API); From 11675a98ce56a1227ef19afcc74778558750e929 Mon Sep 17 00:00:00 2001 From: Jeremy Wu Date: Mon, 22 Feb 2021 21:27:36 +1100 Subject: [PATCH 21/21] update test name --- Flow.Launcher.Test/HttpTest.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Flow.Launcher.Test/HttpTest.cs b/Flow.Launcher.Test/HttpTest.cs index 96213aba694..637747a0785 100644 --- a/Flow.Launcher.Test/HttpTest.cs +++ b/Flow.Launcher.Test/HttpTest.cs @@ -1,4 +1,4 @@ -using NUnit.Framework; +using NUnit.Framework; using System; using System.Collections.Generic; using System.Text; @@ -11,7 +11,7 @@ namespace Flow.Launcher.Test class HttpTest { [Test] - public void TestSettingUpdate() + public void GivenHttpProxy_WhenUpdated_ThenWebProxyShouldAlsoBeUpdatedToTheSame() { HttpProxy proxy = new HttpProxy(); Http.Proxy = proxy;