Skip to content

Commit dec9941

Browse files
authored
Merge pull request #346 from taooceros/fixSuggestSource
Remove unused check for Stream length
2 parents 6c42458 + 2bc290a commit dec9941

File tree

5 files changed

+8
-14
lines changed

5 files changed

+8
-14
lines changed

Flow.Launcher.Core/Plugin/PluginManager.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -195,11 +195,11 @@ public static async Task<List<Result>> QueryForPlugin(PluginPair pair, Query que
195195
catch (OperationCanceledException)
196196
{
197197
// null will be fine since the results will only be added into queue if the token hasn't been cancelled
198-
return results = null;
198+
return null;
199199
}
200200
catch (Exception e)
201201
{
202-
Log.Exception($"|PluginManager.QueryForPlugin|Exception for plugin <{pair.Metadata.Name}> when query <{query}>", e);
202+
Log.Exception($"|PluginManager.QueryForPlugin|Exception for plugin <{pair.Metadata.Name}> when query <{query}>", e);
203203
}
204204

205205
return results;

Plugins/Flow.Launcher.Plugin.WebSearch/Main.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -123,12 +123,12 @@ private async Task<IEnumerable<Result>> SuggestionsAsync(string keyword, string
123123
var source = _settings.SelectedSuggestion;
124124
if (source != null)
125125
{
126-
var suggestions = await source.Suggestions(keyword, token);
126+
var suggestions = await source.Suggestions(keyword, token).ConfigureAwait(false);
127127

128128
if (token.IsCancellationRequested)
129129
return null;
130130

131-
var resultsFromSuggestion = suggestions.Select(o => new Result
131+
var resultsFromSuggestion = suggestions?.Select(o => new Result
132132
{
133133
Title = o,
134134
SubTitle = subtitle,

Plugins/Flow.Launcher.Plugin.WebSearch/SuggestionSources/Baidu.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ public override async Task<List<string>> Suggestions(string query, CancellationT
3232
catch (HttpRequestException e)
3333
{
3434
Log.Exception("|Baidu.Suggestions|Can't get suggestion from baidu", e);
35-
return new List<string>();
35+
return null;
3636
}
3737

3838
if (string.IsNullOrEmpty(result)) return new List<string>();

Plugins/Flow.Launcher.Plugin.WebSearch/SuggestionSources/Bing.cs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,16 +24,13 @@ public override async Task<List<string>> Suggestions(string query, CancellationT
2424
const string api = "https://api.bing.com/qsonhs.aspx?q=";
2525

2626
using var resultStream = await Http.GetStreamAsync(api + Uri.EscapeUriString(query), token).ConfigureAwait(false);
27-
28-
if (resultStream.Length == 0)
29-
return new List<string>(); // this handles the cancellation
30-
27+
3128
json = (await JsonDocument.ParseAsync(resultStream, cancellationToken: token)).RootElement.GetProperty("AS");
3229

3330
}
3431
catch (TaskCanceledException)
3532
{
36-
return null;
33+
return new List<string>();
3734
}
3835
catch (HttpRequestException e)
3936
{

Plugins/Flow.Launcher.Plugin.WebSearch/SuggestionSources/Google.cs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,15 +24,12 @@ public override async Task<List<string>> Suggestions(string query, CancellationT
2424

2525
using var resultStream = await Http.GetStreamAsync(api + Uri.EscapeUriString(query)).ConfigureAwait(false);
2626

27-
if (resultStream.Length == 0)
28-
return new List<string>();
29-
3027
json = await JsonDocument.ParseAsync(resultStream);
3128

3229
}
3330
catch (TaskCanceledException)
3431
{
35-
return null;
32+
return new List<string>();
3633
}
3734
catch (HttpRequestException e)
3835
{

0 commit comments

Comments
 (0)