mirror of
https://github.com/microsoft/PowerToys.git
synced 2026-04-07 03:36:44 +02:00
Misc
This commit is contained in:
@@ -1,5 +1,4 @@
|
|||||||
using System;
|
using System.Collections.Generic;
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
@@ -31,7 +30,7 @@ namespace Wox.Core.Plugin
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
private static List<string> pluginDirectories = new List<string>();
|
private static List<string> pluginDirectories = new List<string>();
|
||||||
|
|
||||||
public static List<PluginPair> AllPlugins
|
public static IEnumerable<PluginPair> AllPlugins
|
||||||
{
|
{
|
||||||
get { return plugins; }
|
get { return plugins; }
|
||||||
private set { plugins = value.OrderBy(o => o.Metadata.Name).ToList(); }
|
private set { plugins = value.OrderBy(o => o.Metadata.Name).ToList(); }
|
||||||
@@ -77,12 +76,10 @@ namespace Wox.Core.Plugin
|
|||||||
|
|
||||||
SetupPluginDirectories();
|
SetupPluginDirectories();
|
||||||
API = api;
|
API = api;
|
||||||
AllPlugins?.Clear();
|
|
||||||
|
|
||||||
pluginMetadatas = PluginConfig.Parse(pluginDirectories);
|
pluginMetadatas = PluginConfig.Parse(pluginDirectories);
|
||||||
AllPlugins = (new CSharpPluginLoader().LoadPlugin(pluginMetadatas)).
|
AllPlugins = (new CSharpPluginLoader().LoadPlugin(pluginMetadatas)).
|
||||||
Concat(new JsonRPCPluginLoader<PythonPlugin>().LoadPlugin(pluginMetadatas)).
|
Concat(new JsonRPCPluginLoader<PythonPlugin>().LoadPlugin(pluginMetadatas));
|
||||||
ToList();
|
|
||||||
|
|
||||||
//load plugin i18n languages
|
//load plugin i18n languages
|
||||||
ResourceMerger.ApplyPluginLanguages();
|
ResourceMerger.ApplyPluginLanguages();
|
||||||
@@ -108,7 +105,9 @@ namespace Wox.Core.Plugin
|
|||||||
|
|
||||||
ThreadPool.QueueUserWorkItem(o =>
|
ThreadPool.QueueUserWorkItem(o =>
|
||||||
{
|
{
|
||||||
GetInstantSearchesPlugins();
|
instantQueryPlugins = GetPlugins<IInstantQuery>();
|
||||||
|
exclusiveSearchPlugins = GetPlugins<IExclusiveQuery>();
|
||||||
|
contextMenuPlugins = GetPlugins<IContextMenu>();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -119,16 +118,16 @@ namespace Wox.Core.Plugin
|
|||||||
|
|
||||||
public static void QueryForAllPlugins(Query query)
|
public static void QueryForAllPlugins(Query query)
|
||||||
{
|
{
|
||||||
query.ActionKeyword = String.Empty;
|
query.ActionKeyword = string.Empty;
|
||||||
query.Search = query.RawQuery;
|
query.Search = query.RawQuery;
|
||||||
if (query.Terms.Length == 0) return;
|
if (query.Terms.Length == 0) return;
|
||||||
if (IsVailldActionKeyword(query.Terms[0]))
|
if (IsVailldActionKeyword(query.Terms[0]))
|
||||||
{
|
{
|
||||||
query.ActionKeyword = query.Terms[0];
|
query.ActionKeyword = query.Terms[0];
|
||||||
}
|
}
|
||||||
if (!String.IsNullOrEmpty(query.ActionKeyword))
|
if (!string.IsNullOrEmpty(query.ActionKeyword))
|
||||||
{
|
{
|
||||||
query.Search = String.Join(Query.Seperater, query.Terms.Skip(1).ToArray());
|
query.Search = string.Join(Query.Seperater, query.Terms.Skip(1).ToArray());
|
||||||
}
|
}
|
||||||
QueryDispatch(query);
|
QueryDispatch(query);
|
||||||
}
|
}
|
||||||
@@ -186,7 +185,7 @@ namespace Wox.Core.Plugin
|
|||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
private static bool IsVailldActionKeyword(string actionKeyword)
|
private static bool IsVailldActionKeyword(string actionKeyword)
|
||||||
{
|
{
|
||||||
if (String.IsNullOrEmpty(actionKeyword) || actionKeyword == Query.WildcardSign) return false;
|
if (string.IsNullOrEmpty(actionKeyword) || actionKeyword == Query.WildcardSign) return false;
|
||||||
PluginPair pair = AllPlugins.FirstOrDefault(o => o.Metadata.ActionKeyword == actionKeyword);
|
PluginPair pair = AllPlugins.FirstOrDefault(o => o.Metadata.ActionKeyword == actionKeyword);
|
||||||
if (pair == null) return false;
|
if (pair == null) return false;
|
||||||
var customizedPluginConfig = UserSettingStorage.Instance.
|
var customizedPluginConfig = UserSettingStorage.Instance.
|
||||||
@@ -203,14 +202,8 @@ namespace Wox.Core.Plugin
|
|||||||
{
|
{
|
||||||
//any plugin that takes more than 200ms for AvgQueryTime won't be treated as IInstantQuery plugin anymore.
|
//any plugin that takes more than 200ms for AvgQueryTime won't be treated as IInstantQuery plugin anymore.
|
||||||
return plugin.AvgQueryTime < 200 &&
|
return plugin.AvgQueryTime < 200 &&
|
||||||
plugin.Metadata.Language.ToUpper() == AllowedLanguage.CSharp &&
|
plugin.Plugin is IInstantQuery &&
|
||||||
GetInstantSearchesPlugins().Any(p => p.Metadata.ID == plugin.Metadata.ID);
|
instantQueryPlugins.Any(p => p.Metadata.ID == plugin.Metadata.ID);
|
||||||
}
|
|
||||||
|
|
||||||
private static IEnumerable<PluginPair> GetInstantSearchesPlugins()
|
|
||||||
{
|
|
||||||
instantQueryPlugins = instantQueryPlugins ?? GetPlugins<IInstantQuery>();
|
|
||||||
return instantQueryPlugins;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -230,9 +223,7 @@ namespace Wox.Core.Plugin
|
|||||||
|
|
||||||
private static PluginPair GetExclusivePlugin(Query query)
|
private static PluginPair GetExclusivePlugin(Query query)
|
||||||
{
|
{
|
||||||
exclusiveSearchPlugins = exclusiveSearchPlugins ?? GetPlugins<IExclusiveQuery>();
|
return exclusiveSearchPlugins.FirstOrDefault(p => ((IExclusiveQuery)p.Plugin).IsExclusiveQuery(query));
|
||||||
var plugin = exclusiveSearchPlugins.FirstOrDefault(p => ((IExclusiveQuery)p.Plugin).IsExclusiveQuery(query));
|
|
||||||
return plugin;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static PluginPair GetActionKeywordPlugin(Query query)
|
private static PluginPair GetActionKeywordPlugin(Query query)
|
||||||
@@ -254,8 +245,6 @@ namespace Wox.Core.Plugin
|
|||||||
|
|
||||||
public static List<Result> GetPluginContextMenus(Result result)
|
public static List<Result> GetPluginContextMenus(Result result)
|
||||||
{
|
{
|
||||||
contextMenuPlugins = contextMenuPlugins ?? GetPlugins<IContextMenu>();
|
|
||||||
|
|
||||||
var pluginPair = contextMenuPlugins.FirstOrDefault(o => o.Metadata.ID == result.PluginID);
|
var pluginPair = contextMenuPlugins.FirstOrDefault(o => o.Metadata.ID == result.PluginID);
|
||||||
var plugin = (IContextMenu)pluginPair?.Plugin;
|
var plugin = (IContextMenu)pluginPair?.Plugin;
|
||||||
if (plugin != null)
|
if (plugin != null)
|
||||||
|
|||||||
@@ -1,8 +1,6 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
using Wox.Infrastructure.Logger;
|
using Wox.Infrastructure.Logger;
|
||||||
using Wox.Plugin;
|
|
||||||
|
|
||||||
namespace Wox.Infrastructure
|
namespace Wox.Infrastructure
|
||||||
{
|
{
|
||||||
@@ -24,9 +22,6 @@ namespace Wox.Infrastructure
|
|||||||
_stopwatch.Stop();
|
_stopwatch.Stop();
|
||||||
long seconds = _stopwatch.ElapsedMilliseconds;
|
long seconds = _stopwatch.ElapsedMilliseconds;
|
||||||
_stopwatch.Start();
|
_stopwatch.Start();
|
||||||
string info = _name + " : " + _stopwatch.ElapsedMilliseconds + "ms";
|
|
||||||
Debug.WriteLine(info);
|
|
||||||
Log.Info(info);
|
|
||||||
return seconds;
|
return seconds;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -45,7 +45,7 @@ namespace Wox
|
|||||||
}
|
}
|
||||||
|
|
||||||
//check new action keyword didn't used by other plugin
|
//check new action keyword didn't used by other plugin
|
||||||
if (tbAction.Text.Trim() != Query.WildcardSign && PluginManager.AllPlugins.Exists(o => o.Metadata.ActionKeyword == tbAction.Text.Trim()))
|
if (tbAction.Text.Trim() != Query.WildcardSign && PluginManager.AllPlugins.Any(o => o.Metadata.ActionKeyword == tbAction.Text.Trim()))
|
||||||
{
|
{
|
||||||
MessageBox.Show(InternationalizationManager.Instance.GetTranslation("newActionKeywordHasBeenAssigned"));
|
MessageBox.Show(InternationalizationManager.Instance.GetTranslation("newActionKeywordHasBeenAssigned"));
|
||||||
return;
|
return;
|
||||||
|
|||||||
@@ -147,7 +147,7 @@ namespace Wox
|
|||||||
|
|
||||||
public List<PluginPair> GetAllPlugins()
|
public List<PluginPair> GetAllPlugins()
|
||||||
{
|
{
|
||||||
return PluginManager.AllPlugins;
|
return PluginManager.AllPlugins.ToList();
|
||||||
}
|
}
|
||||||
|
|
||||||
public event WoxKeyDownEventHandler BackKeyDownEvent;
|
public event WoxKeyDownEventHandler BackKeyDownEvent;
|
||||||
|
|||||||
Reference in New Issue
Block a user