From e2fa9683b93aca33b2517d4a55335510cc9da5bf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BC=98=E9=9F=AC=20=E5=BC=A0?= Date: Tue, 23 Feb 2021 09:36:37 +0800 Subject: [PATCH 1/4] change taskcanceledexception to operationcanceledexception --- 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 8f0de798cc5..9f9c0c2d178 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 || e is TaskCanceledException) + catch (Exception e) when (e is HttpRequestException || e is WebException || e is SocketException || e is OperationCanceledException) { 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 b07b1ddb311e57ad034eace2d12bc08fc52600d0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BC=98=E9=9F=AC=20=E5=BC=A0?= Date: Tue, 23 Feb 2021 09:53:17 +0800 Subject: [PATCH 2/4] Change TaskCanceledException in WebSearch plugin to operationCanceledException --- Plugins/Flow.Launcher.Plugin.WebSearch/Main.cs | 3 +-- .../SuggestionSources/Baidu.cs | 2 +- .../SuggestionSources/Bing.cs | 2 +- .../SuggestionSources/Google.cs | 6 +++--- 4 files changed, 6 insertions(+), 7 deletions(-) diff --git a/Plugins/Flow.Launcher.Plugin.WebSearch/Main.cs b/Plugins/Flow.Launcher.Plugin.WebSearch/Main.cs index 4135bb59ab5..7eca5a56824 100644 --- a/Plugins/Flow.Launcher.Plugin.WebSearch/Main.cs +++ b/Plugins/Flow.Launcher.Plugin.WebSearch/Main.cs @@ -125,8 +125,7 @@ private async Task> SuggestionsAsync(string keyword, string { var suggestions = await source.Suggestions(keyword, token).ConfigureAwait(false); - if (token.IsCancellationRequested) - return null; + token.ThrowIfCancellationRequested(); var resultsFromSuggestion = suggestions?.Select(o => new Result { diff --git a/Plugins/Flow.Launcher.Plugin.WebSearch/SuggestionSources/Baidu.cs b/Plugins/Flow.Launcher.Plugin.WebSearch/SuggestionSources/Baidu.cs index 385a9f8b5b2..38a58979702 100644 --- a/Plugins/Flow.Launcher.Plugin.WebSearch/SuggestionSources/Baidu.cs +++ b/Plugins/Flow.Launcher.Plugin.WebSearch/SuggestionSources/Baidu.cs @@ -25,7 +25,7 @@ public override async Task> Suggestions(string query, CancellationT const string api = "http://suggestion.baidu.com/su?json=1&wd="; result = await Http.GetAsync(api + Uri.EscapeUriString(query), token).ConfigureAwait(false); } - catch (TaskCanceledException) + catch (OperationCanceledException) { return null; } diff --git a/Plugins/Flow.Launcher.Plugin.WebSearch/SuggestionSources/Bing.cs b/Plugins/Flow.Launcher.Plugin.WebSearch/SuggestionSources/Bing.cs index e505d78cf5d..10de8682024 100644 --- a/Plugins/Flow.Launcher.Plugin.WebSearch/SuggestionSources/Bing.cs +++ b/Plugins/Flow.Launcher.Plugin.WebSearch/SuggestionSources/Bing.cs @@ -28,7 +28,7 @@ public override async Task> Suggestions(string query, CancellationT json = (await JsonDocument.ParseAsync(resultStream, cancellationToken: token)).RootElement.GetProperty("AS"); } - catch (TaskCanceledException) + catch (OperationCanceledException) { return new List(); } diff --git a/Plugins/Flow.Launcher.Plugin.WebSearch/SuggestionSources/Google.cs b/Plugins/Flow.Launcher.Plugin.WebSearch/SuggestionSources/Google.cs index c075f4d5d49..5f1ecb31b98 100644 --- a/Plugins/Flow.Launcher.Plugin.WebSearch/SuggestionSources/Google.cs +++ b/Plugins/Flow.Launcher.Plugin.WebSearch/SuggestionSources/Google.cs @@ -23,11 +23,11 @@ public override async Task> Suggestions(string query, CancellationT const string api = "https://www.google.com/complete/search?output=chrome&q="; using var resultStream = await Http.GetStreamAsync(api + Uri.EscapeUriString(query)).ConfigureAwait(false); - - json = await JsonDocument.ParseAsync(resultStream); + + json = await JsonDocument.ParseAsync(resultStream, cancellationToken: token); } - catch (TaskCanceledException) + catch (OperationCanceledException) { return new List(); } From 7739ac73fdd33f16a92f28f5251daace0640e056 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BC=98=E9=9F=AC=20=E5=BC=A0?= Date: Wed, 24 Feb 2021 15:55:03 +0800 Subject: [PATCH 3/4] change exception handling in Updater and WebSearch suggestion source --- Flow.Launcher.Core/Updater.cs | 2 +- .../SuggestionSources/Baidu.cs | 9 +++++---- .../SuggestionSources/Bing.cs | 8 ++++---- .../SuggestionSources/Google.cs | 8 ++++---- 4 files changed, 14 insertions(+), 13 deletions(-) diff --git a/Flow.Launcher.Core/Updater.cs b/Flow.Launcher.Core/Updater.cs index 9f9c0c2d178..76713ce2ab1 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 || e is OperationCanceledException) + catch (Exception e) when (e is HttpRequestException || e is WebException || e is 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"), diff --git a/Plugins/Flow.Launcher.Plugin.WebSearch/SuggestionSources/Baidu.cs b/Plugins/Flow.Launcher.Plugin.WebSearch/SuggestionSources/Baidu.cs index 38a58979702..94458ff5203 100644 --- a/Plugins/Flow.Launcher.Plugin.WebSearch/SuggestionSources/Baidu.cs +++ b/Plugins/Flow.Launcher.Plugin.WebSearch/SuggestionSources/Baidu.cs @@ -25,16 +25,17 @@ public override async Task> Suggestions(string query, CancellationT const string api = "http://suggestion.baidu.com/su?json=1&wd="; result = await Http.GetAsync(api + Uri.EscapeUriString(query), token).ConfigureAwait(false); } - catch (OperationCanceledException) + catch (Exception e) when (e is HttpRequestException || e.InnerException is TimeoutException) { + Log.Exception("|Baidu.Suggestions|Can't get suggestion from baidu", e); return null; } - catch (HttpRequestException e) + catch (OperationCanceledException) { - Log.Exception("|Baidu.Suggestions|Can't get suggestion from baidu", e); return null; } + if (string.IsNullOrEmpty(result)) return new List(); Match match = _reg.Match(result); if (match.Success) @@ -44,7 +45,7 @@ public override async Task> Suggestions(string query, CancellationT { json = JsonDocument.Parse(match.Groups[1].Value); } - catch(JsonException e) + catch (JsonException e) { Log.Exception("|Baidu.Suggestions|can't parse suggestions", e); return new List(); diff --git a/Plugins/Flow.Launcher.Plugin.WebSearch/SuggestionSources/Bing.cs b/Plugins/Flow.Launcher.Plugin.WebSearch/SuggestionSources/Bing.cs index 10de8682024..28868100f22 100644 --- a/Plugins/Flow.Launcher.Plugin.WebSearch/SuggestionSources/Bing.cs +++ b/Plugins/Flow.Launcher.Plugin.WebSearch/SuggestionSources/Bing.cs @@ -28,13 +28,13 @@ public override async Task> Suggestions(string query, CancellationT json = (await JsonDocument.ParseAsync(resultStream, cancellationToken: token)).RootElement.GetProperty("AS"); } - catch (OperationCanceledException) + catch (Exception e) when (e is HttpRequestException || e.InnerException is TimeoutException) { - return new List(); + Log.Exception("|Baidu.Suggestions|Can't get suggestion from baidu", e); + return null; } - catch (HttpRequestException e) + catch (OperationCanceledException) { - Log.Exception("|Bing.Suggestions|Can't get suggestion from Bing", e); return new List(); } catch (JsonException e) diff --git a/Plugins/Flow.Launcher.Plugin.WebSearch/SuggestionSources/Google.cs b/Plugins/Flow.Launcher.Plugin.WebSearch/SuggestionSources/Google.cs index 5f1ecb31b98..a06deea296b 100644 --- a/Plugins/Flow.Launcher.Plugin.WebSearch/SuggestionSources/Google.cs +++ b/Plugins/Flow.Launcher.Plugin.WebSearch/SuggestionSources/Google.cs @@ -27,13 +27,13 @@ public override async Task> Suggestions(string query, CancellationT json = await JsonDocument.ParseAsync(resultStream, cancellationToken: token); } - catch (OperationCanceledException) + catch (Exception e) when (e is HttpRequestException || e.InnerException is TimeoutException) { - return new List(); + Log.Exception("|Baidu.Suggestions|Can't get suggestion from baidu", e); + return null; } - catch (HttpRequestException e) + catch (OperationCanceledException) { - Log.Exception("|Google.Suggestions|Can't get suggestion from google", e); return new List(); } catch (JsonException e) From 3a45c99c2916be4edb89f723c7e3ad56f1517e86 Mon Sep 17 00:00:00 2001 From: Jeremy Wu Date: Thu, 25 Feb 2021 13:59:29 +1100 Subject: [PATCH 4/4] version bump WebSearch plugin --- Plugins/Flow.Launcher.Plugin.WebSearch/plugin.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Plugins/Flow.Launcher.Plugin.WebSearch/plugin.json b/Plugins/Flow.Launcher.Plugin.WebSearch/plugin.json index 6e998674964..996c9b686e2 100644 --- a/Plugins/Flow.Launcher.Plugin.WebSearch/plugin.json +++ b/Plugins/Flow.Launcher.Plugin.WebSearch/plugin.json @@ -25,7 +25,7 @@ "Name": "Web Searches", "Description": "Provide the web search ability", "Author": "qianlifeng", - "Version": "1.3.2", + "Version": "1.3.3", "Language": "csharp", "Website": "https://github.com/Flow-Launcher/Flow.Launcher", "ExecuteFileName": "Flow.Launcher.Plugin.WebSearch.dll",