diff --git a/Wox.Core/Plugin/PluginManager.cs b/Wox.Core/Plugin/PluginManager.cs index 0a7cfdb046..2ba877c82f 100644 --- a/Wox.Core/Plugin/PluginManager.cs +++ b/Wox.Core/Plugin/PluginManager.cs @@ -1,5 +1,4 @@ -using System; -using System.Collections.Generic; +using System.Collections.Generic; using System.IO; using System.Linq; using System.Reflection; @@ -31,7 +30,7 @@ namespace Wox.Core.Plugin /// private static List pluginDirectories = new List(); - public static List AllPlugins + public static IEnumerable AllPlugins { get { return plugins; } private set { plugins = value.OrderBy(o => o.Metadata.Name).ToList(); } @@ -77,12 +76,10 @@ namespace Wox.Core.Plugin SetupPluginDirectories(); API = api; - AllPlugins?.Clear(); pluginMetadatas = PluginConfig.Parse(pluginDirectories); AllPlugins = (new CSharpPluginLoader().LoadPlugin(pluginMetadatas)). - Concat(new JsonRPCPluginLoader().LoadPlugin(pluginMetadatas)). - ToList(); + Concat(new JsonRPCPluginLoader().LoadPlugin(pluginMetadatas)); //load plugin i18n languages ResourceMerger.ApplyPluginLanguages(); @@ -108,7 +105,9 @@ namespace Wox.Core.Plugin ThreadPool.QueueUserWorkItem(o => { - GetInstantSearchesPlugins(); + instantQueryPlugins = GetPlugins(); + exclusiveSearchPlugins = GetPlugins(); + contextMenuPlugins = GetPlugins(); }); } @@ -119,16 +118,16 @@ namespace Wox.Core.Plugin public static void QueryForAllPlugins(Query query) { - query.ActionKeyword = String.Empty; + query.ActionKeyword = string.Empty; query.Search = query.RawQuery; if (query.Terms.Length == 0) return; if (IsVailldActionKeyword(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); } @@ -186,7 +185,7 @@ namespace Wox.Core.Plugin /// 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); if (pair == null) return false; 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. return plugin.AvgQueryTime < 200 && - plugin.Metadata.Language.ToUpper() == AllowedLanguage.CSharp && - GetInstantSearchesPlugins().Any(p => p.Metadata.ID == plugin.Metadata.ID); - } - - private static IEnumerable GetInstantSearchesPlugins() - { - instantQueryPlugins = instantQueryPlugins ?? GetPlugins(); - return instantQueryPlugins; + plugin.Plugin is IInstantQuery && + instantQueryPlugins.Any(p => p.Metadata.ID == plugin.Metadata.ID); } /// @@ -230,9 +223,7 @@ namespace Wox.Core.Plugin private static PluginPair GetExclusivePlugin(Query query) { - exclusiveSearchPlugins = exclusiveSearchPlugins ?? GetPlugins(); - var plugin = exclusiveSearchPlugins.FirstOrDefault(p => ((IExclusiveQuery)p.Plugin).IsExclusiveQuery(query)); - return plugin; + return exclusiveSearchPlugins.FirstOrDefault(p => ((IExclusiveQuery)p.Plugin).IsExclusiveQuery(query)); } private static PluginPair GetActionKeywordPlugin(Query query) @@ -254,8 +245,6 @@ namespace Wox.Core.Plugin public static List GetPluginContextMenus(Result result) { - contextMenuPlugins = contextMenuPlugins ?? GetPlugins(); - var pluginPair = contextMenuPlugins.FirstOrDefault(o => o.Metadata.ID == result.PluginID); var plugin = (IContextMenu)pluginPair?.Plugin; if (plugin != null) diff --git a/Wox.Infrastructure/Timeit.cs b/Wox.Infrastructure/Timeit.cs index 8bad568501..1e804fc2bf 100644 --- a/Wox.Infrastructure/Timeit.cs +++ b/Wox.Infrastructure/Timeit.cs @@ -1,8 +1,6 @@ using System; -using System.Collections.Generic; using System.Diagnostics; using Wox.Infrastructure.Logger; -using Wox.Plugin; namespace Wox.Infrastructure { @@ -24,9 +22,6 @@ namespace Wox.Infrastructure _stopwatch.Stop(); long seconds = _stopwatch.ElapsedMilliseconds; _stopwatch.Start(); - string info = _name + " : " + _stopwatch.ElapsedMilliseconds + "ms"; - Debug.WriteLine(info); - Log.Info(info); return seconds; } } diff --git a/Wox/ActionKeyword.xaml.cs b/Wox/ActionKeyword.xaml.cs index 0e8b8e1382..03beac0ee0 100644 --- a/Wox/ActionKeyword.xaml.cs +++ b/Wox/ActionKeyword.xaml.cs @@ -45,7 +45,7 @@ namespace Wox } //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")); return; diff --git a/Wox/MainWindow.xaml.cs b/Wox/MainWindow.xaml.cs index 74b8023c83..e823b5d2f2 100644 --- a/Wox/MainWindow.xaml.cs +++ b/Wox/MainWindow.xaml.cs @@ -147,7 +147,7 @@ namespace Wox public List GetAllPlugins() { - return PluginManager.AllPlugins; + return PluginManager.AllPlugins.ToList(); } public event WoxKeyDownEventHandler BackKeyDownEvent;