fix #252 web search items lost after restart Wox

This commit is contained in:
qianlifeng
2015-02-20 21:14:15 +08:00
parent 21e5f33487
commit b1a97eca39
9 changed files with 23 additions and 18 deletions

View File

@@ -4,7 +4,6 @@ using System.Linq;
using System.Text.RegularExpressions;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using Wox.Core.UserSettings;
using Wox.Infrastructure.Http;
namespace Wox.Plugin.WebSearch.SuggestionSources
@@ -15,7 +14,7 @@ namespace Wox.Plugin.WebSearch.SuggestionSources
public override List<string> GetSuggestions(string query)
{
var result = HttpRequest.Get("http://suggestion.baidu.com/su?json=1&wd=" + Uri.EscapeUriString(query), HttpProxy.Instance, "GB2312");
var result = HttpRequest.Get("http://suggestion.baidu.com/su?json=1&wd=" + Uri.EscapeUriString(query), Proxy, "GB2312");
if (string.IsNullOrEmpty(result)) return new List<string>();
Match match = reg.Match(result);
@@ -40,5 +39,9 @@ namespace Wox.Plugin.WebSearch.SuggestionSources
return new List<string>();
}
public Baidu(IHttpProxy httpProxy) : base(httpProxy)
{
}
}
}

View File

@@ -3,7 +3,6 @@ using System.Collections.Generic;
using System.Linq;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using Wox.Core.UserSettings;
using Wox.Infrastructure.Http;
namespace Wox.Plugin.WebSearch.SuggestionSources
@@ -12,7 +11,7 @@ namespace Wox.Plugin.WebSearch.SuggestionSources
{
public override List<string> GetSuggestions(string query)
{
var result = HttpRequest.Get("https://www.google.com/complete/search?output=chrome&q=" + Uri.EscapeUriString(query),HttpProxy.Instance);
var result = HttpRequest.Get("https://www.google.com/complete/search?output=chrome&q=" + Uri.EscapeUriString(query), Proxy);
if (string.IsNullOrEmpty(result)) return new List<string>();
try
@@ -31,5 +30,9 @@ namespace Wox.Plugin.WebSearch.SuggestionSources
return new List<string>();
}
public Google(IHttpProxy httpProxy) : base(httpProxy)
{
}
}
}

View File

@@ -9,6 +9,13 @@ namespace Wox.Plugin.WebSearch.SuggestionSources
public abstract class AbstractSuggestionSource : ISuggestionSource
{
public IHttpProxy Proxy { get; set; }
public AbstractSuggestionSource(IHttpProxy httpProxy)
{
Proxy = httpProxy;
}
public abstract List<string> GetSuggestions(string query);
}
}

View File

@@ -2,15 +2,15 @@
{
public class SuggestionSourceFactory
{
public static ISuggestionSource GetSuggestionSource(string name)
public static ISuggestionSource GetSuggestionSource(string name,PluginInitContext context)
{
switch (name.ToLower())
{
case "google":
return new Google();
return new Google(context.Proxy);
case "baidu":
return new Baidu();
return new Baidu(context.Proxy);
default:
return null;