Update WebSearch plugin as System Plugin or User Plugin

This commit is contained in:
Jeremy Wu
2019-08-01 20:55:13 +10:00
parent 4231d7b50a
commit 52252453d9

View File

@@ -23,6 +23,8 @@ namespace Wox.Plugin.WebSearch
public const string Images = "Images"; public const string Images = "Images";
public static string ImagesDirectory; public static string ImagesDirectory;
private readonly string SystemPluginSearchSourceWildCardSign = "*";
public void Save() public void Save()
{ {
_viewModel.Save(); _viewModel.Save();
@@ -34,14 +36,21 @@ namespace Wox.Plugin.WebSearch
_updateSource = new CancellationTokenSource(); _updateSource = new CancellationTokenSource();
_updateToken = _updateSource.Token; _updateToken = _updateSource.Token;
SearchSource searchSource = var searchSourceList = new List<SearchSource>();
_settings.SearchSources.FirstOrDefault(o => o.ActionKeyword == query.ActionKeyword && o.Enabled);
if (searchSource != null) _settings.SearchSources.Where(o => (o.ActionKeyword == query.ActionKeyword || o.ActionKeyword == SystemPluginSearchSourceWildCardSign)
&& o.Enabled)
.ToList()
.ForEach(x => searchSourceList.Add(x));
if (searchSourceList.Any())
{
foreach (SearchSource searchSource in searchSourceList)
{ {
string keyword = query.Search; string keyword = query.Search;
string title = keyword; string title = keyword;
string subtitle = _context.API.GetTranslation("wox_plugin_websearch_search") + " " + searchSource.Title; string subtitle = _context.API.GetTranslation("wox_plugin_websearch_search") + " " +
searchSource.Title;
if (string.IsNullOrEmpty(keyword)) if (string.IsNullOrEmpty(keyword))
{ {
var result = new Result var result = new Result
@@ -72,10 +81,9 @@ namespace Wox.Plugin.WebSearch
return results; return results;
} }
} }
else
{
return new List<Result>();
} }
return new List<Result>();
} }
private void UpdateResultsFromSuggestion(List<Result> results, string keyword, string subtitle, private void UpdateResultsFromSuggestion(List<Result> results, string keyword, string subtitle,