mirror of
https://github.com/microsoft/PowerToys.git
synced 2026-04-06 11:16:51 +02:00
fix #252 web search items lost after restart Wox
This commit is contained in:
@@ -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)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -4,7 +4,6 @@ using System.Diagnostics;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using Wox.Core.UserSettings;
|
||||
using Wox.Plugin.Features;
|
||||
using Wox.Plugin.WebSearch.SuggestionSources;
|
||||
|
||||
@@ -54,7 +53,7 @@ namespace Wox.Plugin.WebSearch
|
||||
if (WebSearchStorage.Instance.EnableWebSearchSuggestion && !string.IsNullOrEmpty(keyword))
|
||||
{
|
||||
ISuggestionSource sugg = SuggestionSourceFactory.GetSuggestionSource(
|
||||
WebSearchStorage.Instance.WebSearchSuggestionSource);
|
||||
WebSearchStorage.Instance.WebSearchSuggestionSource,context);
|
||||
if (sugg != null)
|
||||
{
|
||||
var result = sugg.GetSuggestions(keyword);
|
||||
|
||||
@@ -5,7 +5,6 @@ using System.Reflection;
|
||||
using System.Windows;
|
||||
using System.Windows.Media.Imaging;
|
||||
using Microsoft.Win32;
|
||||
using Wox.Core.UserSettings;
|
||||
|
||||
namespace Wox.Plugin.WebSearch
|
||||
{
|
||||
@@ -124,7 +123,7 @@ namespace Wox.Plugin.WebSearch
|
||||
string msg = context.API.GetTranslation("wox_plugin_websearch_succeed");
|
||||
MessageBox.Show(msg);
|
||||
}
|
||||
UserSettingStorage.Instance.Save();
|
||||
WebSearchStorage.Instance.Save();
|
||||
settingWindow.ReloadWebSearchView();
|
||||
Close();
|
||||
}
|
||||
|
||||
@@ -5,7 +5,6 @@ using System.Linq;
|
||||
using System.Reflection;
|
||||
using System.Text;
|
||||
using Newtonsoft.Json;
|
||||
using Wox.Core.UserSettings;
|
||||
using Wox.Infrastructure.Storage;
|
||||
|
||||
namespace Wox.Plugin.WebSearch
|
||||
|
||||
@@ -2,7 +2,6 @@
|
||||
using System.Linq;
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using Wox.Core.UserSettings;
|
||||
|
||||
namespace Wox.Plugin.WebSearch
|
||||
{
|
||||
@@ -111,7 +110,7 @@ namespace Wox.Plugin.WebSearch
|
||||
if (e.AddedItems.Count > 0)
|
||||
{
|
||||
WebSearchStorage.Instance.WebSearchSuggestionSource = ((ComboBoxItem) e.AddedItems[0]).Content.ToString();
|
||||
UserSettingStorage.Instance.Save();
|
||||
WebSearchStorage.Instance.Save();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -98,10 +98,6 @@
|
||||
<WCFMetadata Include="Service References\" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\..\Wox.Core\Wox.Core.csproj">
|
||||
<Project>{B749F0DB-8E75-47DB-9E5E-265D16D0C0D2}</Project>
|
||||
<Name>Wox.Core</Name>
|
||||
</ProjectReference>
|
||||
<ProjectReference Include="..\..\Wox.Infrastructure\Wox.Infrastructure.csproj">
|
||||
<Project>{4fd29318-a8ab-4d8f-aa47-60bc241b8da3}</Project>
|
||||
<Name>Wox.Infrastructure</Name>
|
||||
|
||||
Reference in New Issue
Block a user