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();
@@ -33,49 +35,55 @@ namespace Wox.Plugin.WebSearch
_updateSource?.Cancel(); _updateSource?.Cancel();
_updateSource = new CancellationTokenSource(); _updateSource = new CancellationTokenSource();
_updateToken = _updateSource.Token; _updateToken = _updateSource.Token;
var searchSourceList = new List<SearchSource>();
_settings.SearchSources.Where(o => (o.ActionKeyword == query.ActionKeyword || o.ActionKeyword == SystemPluginSearchSourceWildCardSign)
&& o.Enabled)
.ToList()
.ForEach(x => searchSourceList.Add(x));
SearchSource searchSource = if (searchSourceList.Any())
_settings.SearchSources.FirstOrDefault(o => o.ActionKeyword == query.ActionKeyword && o.Enabled);
if (searchSource != null)
{ {
string keyword = query.Search; foreach (SearchSource searchSource in searchSourceList)
string title = keyword;
string subtitle = _context.API.GetTranslation("wox_plugin_websearch_search") + " " + searchSource.Title;
if (string.IsNullOrEmpty(keyword))
{ {
var result = new Result string keyword = query.Search;
string title = keyword;
string subtitle = _context.API.GetTranslation("wox_plugin_websearch_search") + " " +
searchSource.Title;
if (string.IsNullOrEmpty(keyword))
{ {
Title = subtitle, var result = new Result
SubTitle = string.Empty,
IcoPath = searchSource.IconPath
};
return new List<Result> {result};
}
else
{
var results = new List<Result>();
var result = new Result
{
Title = title,
SubTitle = subtitle,
Score = 6,
IcoPath = searchSource.IconPath,
Action = c =>
{ {
Process.Start(searchSource.Url.Replace("{q}", Uri.EscapeDataString(keyword))); Title = subtitle,
return true; SubTitle = string.Empty,
} IcoPath = searchSource.IconPath
}; };
results.Add(result); return new List<Result> {result};
UpdateResultsFromSuggestion(results, keyword, subtitle, searchSource, query); }
return results; else
{
var results = new List<Result>();
var result = new Result
{
Title = title,
SubTitle = subtitle,
Score = 6,
IcoPath = searchSource.IconPath,
Action = c =>
{
Process.Start(searchSource.Url.Replace("{q}", Uri.EscapeDataString(keyword)));
return true;
}
};
results.Add(result);
UpdateResultsFromSuggestion(results, keyword, subtitle, searchSource, query);
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,