mirror of
https://github.com/microsoft/PowerToys.git
synced 2026-04-06 03:07:04 +02:00
MVVM refactoring for web search plugin, part 1
1. #486 2. fix #778 #763 #742 3. MVVM refactoring 4. remove IMultipleActionKeywords interface, use PluginManager directly
This commit is contained in:
@@ -13,11 +13,9 @@ namespace Wox.Plugin.WebSearch.SuggestionSources
|
||||
{
|
||||
public class Baidu : SuggestionSource
|
||||
{
|
||||
public override string Domain { get; set; } = "www.baidu.com";
|
||||
private readonly Regex _reg = new Regex("window.baidu.sug\\((.*)\\)");
|
||||
|
||||
Regex reg = new Regex("window.baidu.sug\\((.*)\\)");
|
||||
|
||||
public override async Task<List<string>> GetSuggestions(string query)
|
||||
public override async Task<List<string>> Suggestions(string query)
|
||||
{
|
||||
string result;
|
||||
|
||||
@@ -30,12 +28,12 @@ namespace Wox.Plugin.WebSearch.SuggestionSources
|
||||
{
|
||||
Log.Warn("Can't get suggestion from baidu");
|
||||
Log.Exception(e);
|
||||
return new List<string>(); ;
|
||||
return new List<string>();
|
||||
;
|
||||
}
|
||||
|
||||
if (string.IsNullOrEmpty(result)) return new List<string>();
|
||||
|
||||
Match match = reg.Match(result);
|
||||
Match match = _reg.Match(result);
|
||||
if (match.Success)
|
||||
{
|
||||
JContainer json;
|
||||
@@ -61,5 +59,10 @@ namespace Wox.Plugin.WebSearch.SuggestionSources
|
||||
|
||||
return new List<string>();
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return "Baidu";
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -12,8 +12,7 @@ namespace Wox.Plugin.WebSearch.SuggestionSources
|
||||
{
|
||||
public class Google : SuggestionSource
|
||||
{
|
||||
public override string Domain { get; set; } = "www.google.com";
|
||||
public override async Task<List<string>> GetSuggestions(string query)
|
||||
public override async Task<List<string>> Suggestions(string query)
|
||||
{
|
||||
string result;
|
||||
try
|
||||
@@ -25,7 +24,8 @@ namespace Wox.Plugin.WebSearch.SuggestionSources
|
||||
{
|
||||
Log.Warn("Can't get suggestion from google");
|
||||
Log.Exception(e);
|
||||
return new List<string>(); ;
|
||||
return new List<string>();
|
||||
;
|
||||
}
|
||||
if (string.IsNullOrEmpty(result)) return new List<string>();
|
||||
JContainer json;
|
||||
@@ -48,5 +48,10 @@ namespace Wox.Plugin.WebSearch.SuggestionSources
|
||||
}
|
||||
return new List<string>();
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return "Google";
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -3,25 +3,9 @@ using System.Threading.Tasks;
|
||||
|
||||
namespace Wox.Plugin.WebSearch.SuggestionSources
|
||||
{
|
||||
//todo rename file
|
||||
public abstract class SuggestionSource
|
||||
{
|
||||
public virtual string Domain { get; set; }
|
||||
|
||||
public abstract Task<List<string>> GetSuggestions(string query);
|
||||
|
||||
public static SuggestionSource GetSuggestionSource(string name)
|
||||
{
|
||||
switch (name.ToLower())
|
||||
{
|
||||
case "google":
|
||||
return new Google();
|
||||
|
||||
case "baidu":
|
||||
return new Baidu();
|
||||
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
}
|
||||
public abstract Task<List<string>> Suggestions(string query);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user