mirror of
https://github.com/microsoft/PowerToys.git
synced 2026-04-06 11:16:51 +02:00
Merge branch 'dev' of https://github.com/Wox-launcher/Wox.git
This commit is contained in:
@@ -21,22 +21,17 @@ namespace Wox.Plugin.CMD
|
||||
public List<Result> Query(Query query)
|
||||
{
|
||||
List<Result> results = new List<Result>();
|
||||
List<Result> pushedResults = new List<Result>();
|
||||
string cmd = query.Search;
|
||||
if (string.IsNullOrEmpty(cmd))
|
||||
{
|
||||
return GetAllHistoryCmds();
|
||||
return ResultsFromlHistory();
|
||||
}
|
||||
else
|
||||
{
|
||||
var queryCmd = GetCurrentCmd(cmd);
|
||||
context.API.PushResults(query, context.CurrentPluginMetadata, new List<Result>() { queryCmd });
|
||||
pushedResults.Add(queryCmd);
|
||||
|
||||
results.Add(queryCmd);
|
||||
var history = GetHistoryCmds(cmd, queryCmd);
|
||||
context.API.PushResults(query, context.CurrentPluginMetadata, history);
|
||||
pushedResults.AddRange(history);
|
||||
|
||||
results.AddRange(history);
|
||||
|
||||
try
|
||||
{
|
||||
@@ -57,7 +52,11 @@ namespace Wox.Plugin.CMD
|
||||
|
||||
if (basedir != null)
|
||||
{
|
||||
List<string> autocomplete = Directory.GetFileSystemEntries(basedir).Select(o => dir + Path.GetFileName(o)).Where(o => o.StartsWith(cmd, StringComparison.OrdinalIgnoreCase) && !results.Any(p => o.Equals(p.Title, StringComparison.OrdinalIgnoreCase)) && !pushedResults.Any(p => o.Equals(p.Title, StringComparison.OrdinalIgnoreCase))).ToList();
|
||||
var autocomplete = Directory.GetFileSystemEntries(basedir).
|
||||
Select(o => dir + Path.GetFileName(o)).
|
||||
Where(o => o.StartsWith(cmd, StringComparison.OrdinalIgnoreCase) &&
|
||||
!results.Any(p => o.Equals(p.Title, StringComparison.OrdinalIgnoreCase)) &&
|
||||
!results.Any(p => o.Equals(p.Title, StringComparison.OrdinalIgnoreCase))).ToList();
|
||||
autocomplete.Sort();
|
||||
results.AddRange(autocomplete.ConvertAll(m => new Result()
|
||||
{
|
||||
@@ -94,7 +93,7 @@ namespace Wox.Plugin.CMD
|
||||
var ret = new Result
|
||||
{
|
||||
Title = m.Key,
|
||||
SubTitle = string.Format(context.API.GetTranslation("wox_plugin_cmd_cmd_has_been_executed_times"), m.Value),
|
||||
SubTitle = string.Format(context.API.GetTranslation("wox_plugin_cmd_cmd_has_been_executed_times"), m.Value),
|
||||
IcoPath = "Images/cmd.png",
|
||||
Action = (c) =>
|
||||
{
|
||||
@@ -125,13 +124,13 @@ namespace Wox.Plugin.CMD
|
||||
return result;
|
||||
}
|
||||
|
||||
private List<Result> GetAllHistoryCmds()
|
||||
private List<Result> ResultsFromlHistory()
|
||||
{
|
||||
IEnumerable<Result> history = CMDStorage.Instance.CMDHistory.OrderByDescending(o => o.Value)
|
||||
.Select(m => new Result
|
||||
{
|
||||
Title = m.Key,
|
||||
SubTitle = string.Format(context.API.GetTranslation("wox_plugin_cmd_cmd_has_been_executed_times"), m.Value),
|
||||
SubTitle = string.Format(context.API.GetTranslation("wox_plugin_cmd_cmd_has_been_executed_times"), m.Value),
|
||||
IcoPath = "Images/cmd.png",
|
||||
Action = (c) =>
|
||||
{
|
||||
|
||||
@@ -13,10 +13,9 @@ namespace Wox.Plugin.PluginIndicator
|
||||
|
||||
public List<Result> Query(Query query)
|
||||
{
|
||||
var results = from plugin in PluginManager.NonGlobalPlugins
|
||||
select plugin.Metadata into metadata
|
||||
from keyword in metadata.ActionKeywords
|
||||
var results = from keyword in PluginManager.NonGlobalPlugins.Keys
|
||||
where keyword.StartsWith(query.Terms[0])
|
||||
let metadata = PluginManager.NonGlobalPlugins[keyword].Metadata
|
||||
let customizedPluginConfig =
|
||||
UserSettingStorage.Instance.CustomizedPluginConfigs.FirstOrDefault(o => o.ID == metadata.ID)
|
||||
where customizedPluginConfig == null || !customizedPluginConfig.Disabled
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
using System.Threading;
|
||||
|
||||
using Wox.Infrastructure.Logger;
|
||||
namespace Wox.Plugin.Program
|
||||
{
|
||||
internal class FileChangeWatcher
|
||||
@@ -15,7 +15,7 @@ namespace Wox.Plugin.Program
|
||||
if (watchedPath.Contains(path)) return;
|
||||
if (!Directory.Exists(path))
|
||||
{
|
||||
Debug.WriteLine(string.Format("FileChangeWatcher: {0} doesn't exist", path));
|
||||
Log.Warn($"FileChangeWatcher: {path} doesn't exist");
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@@ -57,7 +57,7 @@ namespace Wox.Plugin.Program.ProgramSources
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Log.Error(e.StackTrace);
|
||||
Log.Error(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using Wox.Core.Exception;
|
||||
using Wox.Infrastructure.Logger;
|
||||
|
||||
namespace Wox.Plugin.Program.ProgramSources
|
||||
@@ -70,7 +71,8 @@ namespace Wox.Plugin.Program.ProgramSources
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Log.Warn(string.Format("GetAppFromDirectory failed: {0} - {1}", path, e.Message));
|
||||
var woxPluginException = new WoxPluginException("Program", $"GetAppFromDirectory failed: {path}", e);
|
||||
Log.Error(woxPluginException);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -8,6 +8,7 @@ using System.Windows;
|
||||
using IWshRuntimeLibrary;
|
||||
using Wox.Infrastructure;
|
||||
using Wox.Plugin.Program.ProgramSources;
|
||||
using Wox.Infrastructure.Logger;
|
||||
using Stopwatch = Wox.Infrastructure.Stopwatch;
|
||||
|
||||
namespace Wox.Plugin.Program
|
||||
@@ -17,7 +18,7 @@ namespace Wox.Plugin.Program
|
||||
private static object lockObject = new object();
|
||||
private static List<Program> programs = new List<Program>();
|
||||
private static List<IProgramSource> sources = new List<IProgramSource>();
|
||||
private static Dictionary<string, Type> SourceTypes = new Dictionary<string, Type>() {
|
||||
private static Dictionary<string, Type> SourceTypes = new Dictionary<string, Type>() {
|
||||
{"FileSystemProgramSource", typeof(FileSystemProgramSource)},
|
||||
{"CommonStartMenuProgramSource", typeof(CommonStartMenuProgramSource)},
|
||||
{"UserStartMenuProgramSource", typeof(UserStartMenuProgramSource)},
|
||||
@@ -27,7 +28,7 @@ namespace Wox.Plugin.Program
|
||||
|
||||
public List<Result> Query(Query query)
|
||||
{
|
||||
|
||||
|
||||
var fuzzyMather = FuzzyMatcher.Create(query.Search);
|
||||
List<Program> returnList = programs.Where(o => MatchProgram(o, fuzzyMather)).ToList();
|
||||
returnList.ForEach(ScoreFilter);
|
||||
@@ -75,7 +76,7 @@ namespace Wox.Plugin.Program
|
||||
{
|
||||
programs = ProgramCacheStorage.Instance.Programs;
|
||||
});
|
||||
Debug.WriteLine($"Preload {programs.Count} programs from cache");
|
||||
Log.Info($"Preload {programs.Count} programs from cache");
|
||||
Stopwatch.Debug("Program Index", IndexPrograms);
|
||||
}
|
||||
|
||||
@@ -98,7 +99,7 @@ namespace Wox.Plugin.Program
|
||||
}
|
||||
|
||||
sources.Clear();
|
||||
foreach(var source in programSources.Where(o => o.Enabled))
|
||||
foreach (var source in programSources.Where(o => o.Enabled))
|
||||
{
|
||||
Type sourceClass;
|
||||
if (SourceTypes.TryGetValue(source.Type, out sourceClass))
|
||||
|
||||
@@ -1,40 +0,0 @@
|
||||
using System;
|
||||
|
||||
namespace Wox.Plugin.WebSearch
|
||||
{
|
||||
public static class EasyTimer
|
||||
{
|
||||
public static IDisposable SetInterval(Action method, int delayInMilliseconds)
|
||||
{
|
||||
System.Timers.Timer timer = new System.Timers.Timer(delayInMilliseconds);
|
||||
timer.Elapsed += (source, e) =>
|
||||
{
|
||||
method();
|
||||
};
|
||||
|
||||
timer.Enabled = true;
|
||||
timer.Start();
|
||||
|
||||
// Returns a stop handle which can be used for stopping
|
||||
// the timer, if required
|
||||
return timer as IDisposable;
|
||||
}
|
||||
|
||||
public static IDisposable SetTimeout(Action method, int delayInMilliseconds)
|
||||
{
|
||||
System.Timers.Timer timer = new System.Timers.Timer(delayInMilliseconds);
|
||||
timer.Elapsed += (source, e) =>
|
||||
{
|
||||
method();
|
||||
};
|
||||
|
||||
timer.AutoReset = false;
|
||||
timer.Enabled = true;
|
||||
timer.Start();
|
||||
|
||||
// Returns a stop handle which can be used for stopping
|
||||
// the timer, if required
|
||||
return timer as IDisposable;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -4,14 +4,14 @@ using System.Diagnostics;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using System.Windows.Controls;
|
||||
using Wox.Plugin.WebSearch.SuggestionSources;
|
||||
|
||||
namespace Wox.Plugin.WebSearch
|
||||
{
|
||||
public class WebSearchPlugin : IPlugin, ISettingProvider, IPluginI18n, IInstantQuery
|
||||
{
|
||||
private PluginInitContext context;
|
||||
private IDisposable suggestionTimer;
|
||||
private PluginInitContext _context;
|
||||
|
||||
public List<Result> Query(Query query)
|
||||
{
|
||||
@@ -21,71 +21,63 @@ namespace Wox.Plugin.WebSearch
|
||||
|
||||
if (webSearch != null)
|
||||
{
|
||||
string keyword = query.ActionKeyword;
|
||||
string keyword = query.Search;
|
||||
string title = keyword;
|
||||
string subtitle = context.API.GetTranslation("wox_plugin_websearch_search") + " " + webSearch.Title;
|
||||
string subtitle = _context.API.GetTranslation("wox_plugin_websearch_search") + " " + webSearch.Title;
|
||||
if (string.IsNullOrEmpty(keyword))
|
||||
{
|
||||
title = subtitle;
|
||||
subtitle = null;
|
||||
subtitle = string.Empty;
|
||||
}
|
||||
context.API.PushResults(query, context.CurrentPluginMetadata, new List<Result>()
|
||||
var result = new Result
|
||||
{
|
||||
new Result()
|
||||
Title = title,
|
||||
SubTitle = subtitle,
|
||||
Score = 6,
|
||||
IcoPath = webSearch.IconPath,
|
||||
Action = c =>
|
||||
{
|
||||
Title = title,
|
||||
SubTitle = subtitle,
|
||||
Score = 6,
|
||||
IcoPath = webSearch.IconPath,
|
||||
Action = (c) =>
|
||||
{
|
||||
Process.Start(webSearch.Url.Replace("{q}", Uri.EscapeDataString(keyword)));
|
||||
return true;
|
||||
}
|
||||
Process.Start(webSearch.Url.Replace("{q}", Uri.EscapeDataString(keyword ?? string.Empty)));
|
||||
return true;
|
||||
}
|
||||
});
|
||||
};
|
||||
results.Add(result);
|
||||
|
||||
if (WebSearchStorage.Instance.EnableWebSearchSuggestion && !string.IsNullOrEmpty(keyword))
|
||||
{
|
||||
if (suggestionTimer != null)
|
||||
{
|
||||
suggestionTimer.Dispose();
|
||||
}
|
||||
suggestionTimer = EasyTimer.SetTimeout(() => { QuerySuggestions(keyword, query, subtitle, webSearch); }, 350);
|
||||
// todo use Task.Wait when .net upgraded
|
||||
results.AddRange(ResultsFromSuggestions(keyword, subtitle, webSearch));
|
||||
}
|
||||
}
|
||||
|
||||
return results;
|
||||
}
|
||||
|
||||
private void QuerySuggestions(string keyword, Query query, string subtitle, WebSearch webSearch)
|
||||
private IEnumerable<Result> ResultsFromSuggestions(string keyword, string subtitle, WebSearch webSearch)
|
||||
{
|
||||
ISuggestionSource sugg = SuggestionSourceFactory.GetSuggestionSource(WebSearchStorage.Instance.WebSearchSuggestionSource, context);
|
||||
if (sugg != null)
|
||||
ISuggestionSource sugg = SuggestionSourceFactory.GetSuggestionSource(WebSearchStorage.Instance.WebSearchSuggestionSource, _context);
|
||||
var suggestions = sugg?.GetSuggestions(keyword);
|
||||
if (suggestions != null)
|
||||
{
|
||||
var result = sugg.GetSuggestions(keyword);
|
||||
if (result != null)
|
||||
var resultsFromSuggestion = suggestions.Select(o => new Result
|
||||
{
|
||||
context.API.PushResults(query, context.CurrentPluginMetadata,
|
||||
result.Select(o => new Result()
|
||||
{
|
||||
Title = o,
|
||||
SubTitle = subtitle,
|
||||
Score = 5,
|
||||
IcoPath = webSearch.IconPath,
|
||||
Action = (c) =>
|
||||
{
|
||||
Process.Start(webSearch.Url.Replace("{q}", Uri.EscapeDataString(o)));
|
||||
return true;
|
||||
}
|
||||
}).ToList());
|
||||
}
|
||||
Title = o,
|
||||
SubTitle = subtitle,
|
||||
Score = 5,
|
||||
IcoPath = webSearch.IconPath,
|
||||
Action = c =>
|
||||
{
|
||||
Process.Start(webSearch.Url.Replace("{q}", Uri.EscapeDataString(o)));
|
||||
return true;
|
||||
}
|
||||
});
|
||||
return resultsFromSuggestion;
|
||||
}
|
||||
return new List<Result>();
|
||||
}
|
||||
|
||||
public void Init(PluginInitContext context)
|
||||
{
|
||||
this.context = context;
|
||||
_context = context;
|
||||
|
||||
if (WebSearchStorage.Instance.WebSearches == null)
|
||||
WebSearchStorage.Instance.WebSearches = WebSearchStorage.Instance.LoadDefaultWebSearches();
|
||||
@@ -93,9 +85,9 @@ namespace Wox.Plugin.WebSearch
|
||||
|
||||
#region ISettingProvider Members
|
||||
|
||||
public System.Windows.Controls.Control CreateSettingPanel()
|
||||
public Control CreateSettingPanel()
|
||||
{
|
||||
return new WebSearchesSetting(context);
|
||||
return new WebSearchesSetting(_context);
|
||||
}
|
||||
|
||||
#endregion
|
||||
@@ -107,12 +99,12 @@ namespace Wox.Plugin.WebSearch
|
||||
|
||||
public string GetTranslatedPluginTitle()
|
||||
{
|
||||
return context.API.GetTranslation("wox_plugin_websearch_plugin_name");
|
||||
return _context.API.GetTranslation("wox_plugin_websearch_plugin_name");
|
||||
}
|
||||
|
||||
public string GetTranslatedPluginDescription()
|
||||
{
|
||||
return context.API.GetTranslation("wox_plugin_websearch_plugin_description");
|
||||
return _context.API.GetTranslation("wox_plugin_websearch_plugin_description");
|
||||
}
|
||||
|
||||
public bool IsInstantQuery(string query) => false;
|
||||
|
||||
@@ -49,7 +49,6 @@
|
||||
<Reference Include="WindowsBase" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="EasyTimer.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
<Compile Include="SuggestionSources\Baidu.cs" />
|
||||
<Compile Include="SuggestionSources\Google.cs" />
|
||||
@@ -93,9 +92,6 @@
|
||||
<SubType>Designer</SubType>
|
||||
</Page>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<WCFMetadata Include="Service References\" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\..\Wox.Infrastructure\Wox.Infrastructure.csproj">
|
||||
<Project>{4fd29318-a8ab-4d8f-aa47-60bc241b8da3}</Project>
|
||||
|
||||
Reference in New Issue
Block a user