mirror of
https://github.com/microsoft/PowerToys.git
synced 2026-04-06 03:07:04 +02:00
Web search suggestion is loaded async
1. suggestion is async 2. if ping time of domain less than 300ms, then suggestion is still sync 3. #578 #539
This commit is contained in:
@@ -8,8 +8,10 @@ using Wox.Infrastructure.Http;
|
||||
|
||||
namespace Wox.Plugin.WebSearch.SuggestionSources
|
||||
{
|
||||
public class Baidu : AbstractSuggestionSource
|
||||
public class Baidu : SuggestionSource
|
||||
{
|
||||
public override string Domain { get; set; } = "www.baidu.com";
|
||||
|
||||
Regex reg = new Regex("window.baidu.sug\\((.*)\\)");
|
||||
|
||||
public override List<string> GetSuggestions(string query)
|
||||
|
||||
@@ -7,8 +7,9 @@ using Wox.Infrastructure.Http;
|
||||
|
||||
namespace Wox.Plugin.WebSearch.SuggestionSources
|
||||
{
|
||||
public class Google : AbstractSuggestionSource
|
||||
public class Google : SuggestionSource
|
||||
{
|
||||
public override string Domain { get; set; } = "www.google.com";
|
||||
public override List<string> GetSuggestions(string query)
|
||||
{
|
||||
var result = HttpRequest.Get("https://www.google.com/complete/search?output=chrome&q=" + Uri.EscapeUriString(query), Proxy);
|
||||
|
||||
@@ -2,20 +2,31 @@
|
||||
|
||||
namespace Wox.Plugin.WebSearch.SuggestionSources
|
||||
{
|
||||
public interface ISuggestionSource
|
||||
{
|
||||
List<string> GetSuggestions(string query);
|
||||
}
|
||||
|
||||
public abstract class AbstractSuggestionSource : ISuggestionSource
|
||||
public abstract class SuggestionSource
|
||||
{
|
||||
public virtual string Domain { get; set; }
|
||||
public IHttpProxy Proxy { get; set; }
|
||||
|
||||
public AbstractSuggestionSource(IHttpProxy httpProxy)
|
||||
public SuggestionSource(IHttpProxy httpProxy)
|
||||
{
|
||||
Proxy = httpProxy;
|
||||
}
|
||||
|
||||
public abstract List<string> GetSuggestions(string query);
|
||||
|
||||
public static SuggestionSource GetSuggestionSource(string name, PluginInitContext context)
|
||||
{
|
||||
switch (name.ToLower())
|
||||
{
|
||||
case "google":
|
||||
return new Google(context.Proxy);
|
||||
|
||||
case "baidu":
|
||||
return new Baidu(context.Proxy);
|
||||
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,20 +0,0 @@
|
||||
namespace Wox.Plugin.WebSearch.SuggestionSources
|
||||
{
|
||||
public class SuggestionSourceFactory
|
||||
{
|
||||
public static ISuggestionSource GetSuggestionSource(string name,PluginInitContext context)
|
||||
{
|
||||
switch (name.ToLower())
|
||||
{
|
||||
case "google":
|
||||
return new Google(context.Proxy);
|
||||
|
||||
case "baidu":
|
||||
return new Baidu(context.Proxy);
|
||||
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user