Merge pull request #346 from taooceros/fixSuggestSource

Remove unused check for Stream length
This commit is contained in:
Jeremy Wu 2021-02-16 19:10:37 +11:00 committed by GitHub
commit dec9941cce
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 8 additions and 14 deletions

View file

@ -195,11 +195,11 @@ namespace Flow.Launcher.Core.Plugin
catch (OperationCanceledException)
{
// null will be fine since the results will only be added into queue if the token hasn't been cancelled
return results = null;
return null;
}
catch (Exception e)
{
Log.Exception($"|PluginManager.QueryForPlugin|Exception for plugin <{pair.Metadata.Name}> when query <{query}>", e);
Log.Exception($"|PluginManager.QueryForPlugin|Exception for plugin <{pair.Metadata.Name}> when query <{query}>", e);
}
return results;

View file

@ -123,12 +123,12 @@ namespace Flow.Launcher.Plugin.WebSearch
var source = _settings.SelectedSuggestion;
if (source != null)
{
var suggestions = await source.Suggestions(keyword, token);
var suggestions = await source.Suggestions(keyword, token).ConfigureAwait(false);
if (token.IsCancellationRequested)
return null;
var resultsFromSuggestion = suggestions.Select(o => new Result
var resultsFromSuggestion = suggestions?.Select(o => new Result
{
Title = o,
SubTitle = subtitle,

View file

@ -32,7 +32,7 @@ namespace Flow.Launcher.Plugin.WebSearch.SuggestionSources
catch (HttpRequestException e)
{
Log.Exception("|Baidu.Suggestions|Can't get suggestion from baidu", e);
return new List<string>();
return null;
}
if (string.IsNullOrEmpty(result)) return new List<string>();

View file

@ -24,16 +24,13 @@ namespace Flow.Launcher.Plugin.WebSearch.SuggestionSources
const string api = "https://api.bing.com/qsonhs.aspx?q=";
using var resultStream = await Http.GetStreamAsync(api + Uri.EscapeUriString(query), token).ConfigureAwait(false);
if (resultStream.Length == 0)
return new List<string>(); // this handles the cancellation
json = (await JsonDocument.ParseAsync(resultStream, cancellationToken: token)).RootElement.GetProperty("AS");
}
catch (TaskCanceledException)
{
return null;
return new List<string>();
}
catch (HttpRequestException e)
{

View file

@ -24,15 +24,12 @@ namespace Flow.Launcher.Plugin.WebSearch.SuggestionSources
using var resultStream = await Http.GetStreamAsync(api + Uri.EscapeUriString(query)).ConfigureAwait(false);
if (resultStream.Length == 0)
return new List<string>();
json = await JsonDocument.ParseAsync(resultStream);
}
catch (TaskCanceledException)
{
return null;
return new List<string>();
}
catch (HttpRequestException e)
{