mirror of
https://github.com/microsoft/PowerToys.git
synced 2026-04-09 20:57:22 +02:00
Update WebSearch plugin as System Plugin or User Plugin
This commit is contained in:
@@ -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,48 +36,54 @@ 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())
|
||||||
{
|
{
|
||||||
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,
|
||||||
|
|||||||
Reference in New Issue
Block a user