mirror of
https://github.com/microsoft/PowerToys.git
synced 2026-04-06 03:07:04 +02:00
Refactoring proxy, part 2
This commit is contained in:
@@ -104,7 +104,7 @@ namespace Wox.Plugin.WebSearch
|
||||
|
||||
private async Task<IEnumerable<Result>> Suggestions(string keyword, string subtitle, WebSearch webSearch)
|
||||
{
|
||||
var source = SuggestionSource.GetSuggestionSource(_settings.WebSearchSuggestionSource, Context);
|
||||
var source = SuggestionSource.GetSuggestionSource(_settings.WebSearchSuggestionSource);
|
||||
if (source != null)
|
||||
{
|
||||
var suggestions = await source.GetSuggestions(keyword);
|
||||
|
||||
@@ -24,7 +24,7 @@ namespace Wox.Plugin.WebSearch.SuggestionSources
|
||||
try
|
||||
{
|
||||
const string api = "http://suggestion.baidu.com/su?json=1&wd=";
|
||||
result = await Http.Get(api + Uri.EscapeUriString(query), Proxy, "GB2312");
|
||||
result = await Http.Get(api + Uri.EscapeUriString(query), "GB2312");
|
||||
}
|
||||
catch (WebException e)
|
||||
{
|
||||
@@ -61,9 +61,5 @@ namespace Wox.Plugin.WebSearch.SuggestionSources
|
||||
|
||||
return new List<string>();
|
||||
}
|
||||
|
||||
public Baidu(IHttpProxy httpProxy) : base(httpProxy)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,7 +19,7 @@ namespace Wox.Plugin.WebSearch.SuggestionSources
|
||||
try
|
||||
{
|
||||
const string api = "https://www.google.com/complete/search?output=chrome&q=";
|
||||
result = await Http.Get(api + Uri.EscapeUriString(query), Proxy);
|
||||
result = await Http.Get(api + Uri.EscapeUriString(query));
|
||||
}
|
||||
catch (WebException e)
|
||||
{
|
||||
@@ -48,9 +48,5 @@ namespace Wox.Plugin.WebSearch.SuggestionSources
|
||||
}
|
||||
return new List<string>();
|
||||
}
|
||||
|
||||
public Google(IHttpProxy httpProxy) : base(httpProxy)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,24 +6,18 @@ namespace Wox.Plugin.WebSearch.SuggestionSources
|
||||
public abstract class SuggestionSource
|
||||
{
|
||||
public virtual string Domain { get; set; }
|
||||
public IHttpProxy Proxy { get; set; }
|
||||
|
||||
public SuggestionSource(IHttpProxy httpProxy)
|
||||
{
|
||||
Proxy = httpProxy;
|
||||
}
|
||||
|
||||
public abstract Task<List<string>> GetSuggestions(string query);
|
||||
|
||||
public static SuggestionSource GetSuggestionSource(string name, PluginInitContext context)
|
||||
public static SuggestionSource GetSuggestionSource(string name)
|
||||
{
|
||||
switch (name.ToLower())
|
||||
{
|
||||
case "google":
|
||||
return new Google(context.Proxy);
|
||||
return new Google();
|
||||
|
||||
case "baidu":
|
||||
return new Baidu(context.Proxy);
|
||||
return new Baidu();
|
||||
|
||||
default:
|
||||
return null;
|
||||
|
||||
Reference in New Issue
Block a user