diff --git a/Plugins/Wox.Plugin.CMD/CMD.cs b/Plugins/Wox.Plugin.CMD/CMD.cs index 59c25ef60b..de76413c52 100644 --- a/Plugins/Wox.Plugin.CMD/CMD.cs +++ b/Plugins/Wox.Plugin.CMD/CMD.cs @@ -200,11 +200,7 @@ namespace Wox.Plugin.CMD return context.API.GetTranslation("wox_plugin_cmd_plugin_description"); } - public bool IsInstantQuery(string query) - { - if (query.StartsWith(">")) return true; - return false; - } + public bool IsInstantQuery(string query) => false; public bool IsExclusiveQuery(Query query) { diff --git a/Plugins/Wox.Plugin.WebSearch/WebQueryPlugin.cs b/Plugins/Wox.Plugin.WebSearch/WebQueryPlugin.cs index 4de81492e6..9fc1b9ec45 100644 --- a/Plugins/Wox.Plugin.WebSearch/WebQueryPlugin.cs +++ b/Plugins/Wox.Plugin.WebSearch/WebQueryPlugin.cs @@ -120,19 +120,16 @@ namespace Wox.Plugin.WebSearch return context.API.GetTranslation("wox_plugin_websearch_plugin_description"); } - public bool IsInstantQuery(string query) + public bool IsInstantQuery(string query) => false; + + public bool IsExclusiveQuery(Query query) { - var strings = query.Split(' '); + var strings = query.RawQuery.Split(' '); if (strings.Length > 1) { return WebSearchStorage.Instance.WebSearches.Exists(o => o.ActionWord == strings[0] && o.Enabled); } return false; } - - public bool IsExclusiveQuery(Query query) - { - return IsInstantQuery(query.RawQuery); - } } } diff --git a/Wox.Core/Plugin/PluginManager.cs b/Wox.Core/Plugin/PluginManager.cs index 94170ceeec..0a7cfdb046 100644 --- a/Wox.Core/Plugin/PluginManager.cs +++ b/Wox.Core/Plugin/PluginManager.cs @@ -21,7 +21,7 @@ namespace Wox.Core.Plugin { public const string DirectoryName = "Plugins"; private static List pluginMetadatas; - private static IEnumerable instantSearches; + private static IEnumerable instantQueryPlugins; private static IEnumerable exclusiveSearchPlugins; private static IEnumerable contextMenuPlugins; private static List plugins; @@ -135,14 +135,14 @@ namespace Wox.Core.Plugin private static void QueryDispatch(Query query) { - var nonSystemPlugin = GetNonSystemPlugin(query); - var pluginPairs = nonSystemPlugin != null ? new List { nonSystemPlugin } : GetSystemPlugins(); + var pluginPairs = GetNonSystemPlugin(query) != null ? + new List { GetNonSystemPlugin(query) } : GetSystemPlugins(); foreach (var plugin in pluginPairs) { var customizedPluginConfig = UserSettingStorage.Instance. CustomizedPluginConfigs.FirstOrDefault(o => o.ID == plugin.Metadata.ID); if (customizedPluginConfig != null && customizedPluginConfig.Disabled) return; - if (query.IsIntantQuery && IsInstantSearchPlugin(plugin.Metadata)) + if (IsInstantQueryPlugin(plugin)) { using (new Timeit($"Plugin {plugin.Metadata.Name} is executing instant search")) { @@ -163,7 +163,7 @@ namespace Wox.Core.Plugin { try { - using (var time = new Timeit("Preload programs")) + using (var time = new Timeit($"Query For {pair.Metadata.Name}")) { var results = pair.Plugin.Query(query) ?? new List(); results.ForEach(o => { o.PluginID = pair.Metadata.ID; }); @@ -199,22 +199,18 @@ namespace Wox.Core.Plugin return metadata.ActionKeyword == Query.WildcardSign; } - public static bool IsInstantQuery(string query) + private static bool IsInstantQueryPlugin(PluginPair plugin) { - return GetInstantSearchesPlugins().Any(o => ((IInstantQuery)o.Plugin).IsInstantQuery(query)); - } - - private static bool IsInstantSearchPlugin(PluginMetadata pluginMetadata) - { - //todo:to improve performance, any instant search plugin that takes long than 200ms will not consider a instant plugin anymore - return pluginMetadata.Language.ToUpper() == AllowedLanguage.CSharp && - GetInstantSearchesPlugins().Any(o => o.Metadata.ID == pluginMetadata.ID); + //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() { - instantSearches = instantSearches ?? GetPlugins(); - return instantSearches; + instantQueryPlugins = instantQueryPlugins ?? GetPlugins(); + return instantQueryPlugins; } /// @@ -242,7 +238,7 @@ namespace Wox.Core.Plugin private static PluginPair GetActionKeywordPlugin(Query query) { //if a query doesn't contain a vaild action keyword, it should not be a action keword plugin query - if (String.IsNullOrEmpty(query.ActionKeyword)) return null; + if (string.IsNullOrEmpty(query.ActionKeyword)) return null; return AllPlugins.FirstOrDefault(o => o.Metadata.ActionKeyword == query.ActionKeyword); } diff --git a/Wox.Plugin/Feature.cs b/Wox.Plugin/Feature.cs index e12ef754ef..6a1e753684 100644 --- a/Wox.Plugin/Feature.cs +++ b/Wox.Plugin/Feature.cs @@ -1,4 +1,5 @@ using System.Collections.Generic; +using System; namespace Wox.Plugin { @@ -20,6 +21,7 @@ namespace Wox.Plugin /// public interface IInstantQuery : IFeatures { + [Obsolete("Empty interface is enough. it will be removed in v1.3.0 and possibly replaced by attribute")] bool IsInstantQuery(string query); } diff --git a/Wox.Plugin/Query.cs b/Wox.Plugin/Query.cs index 538b23f9df..86ee08e912 100644 --- a/Wox.Plugin/Query.cs +++ b/Wox.Plugin/Query.cs @@ -34,8 +34,6 @@ namespace Wox.Plugin internal string ActionKeyword { get; set; } - internal bool IsIntantQuery { get; set; } - /// /// Return first search split by space if it has /// diff --git a/Wox/MainWindow.xaml.cs b/Wox/MainWindow.xaml.cs index 11d74834bb..74b8023c83 100644 --- a/Wox/MainWindow.xaml.cs +++ b/Wox/MainWindow.xaml.cs @@ -347,7 +347,7 @@ namespace Wox { //double if to omit calling win32 function if (UserSettingStorage.Instance.IgnoreHotkeysOnFullscreen) - if(WindowIntelopHelper.IsWindowFullscreen()) + if (WindowIntelopHelper.IsWindowFullscreen()) return true; return false; @@ -455,50 +455,31 @@ namespace Wox queryHasReturn = false; Query query = new Query(tbQuery.Text); lastQuery = query.RawQuery; - int searchDelay = GetSearchDelay(lastQuery); - query.IsIntantQuery = searchDelay == 0; - Dispatcher.DelayInvoke("UpdateSearch", - () => + Dispatcher.DelayInvoke("ClearResults", () => + { + // Delay the invocation of clear method of pnlResult, minimize the time-span between clear results and add new results. + // So this will reduce splash issues. After waiting 100ms, if there still no results added, we + // must clear the result. otherwise, it will be confused why the query changed, but the results + // didn't. + if (pnlResult.Dirty) pnlResult.Clear(); + }, TimeSpan.FromMilliseconds(100)); + Query(query); + Dispatcher.DelayInvoke("ShowProgressbar", () => + { + if (!queryHasReturn && !string.IsNullOrEmpty(lastQuery)) { - Dispatcher.DelayInvoke("ClearResults", () => - { - // Delay the invocation of clear method of pnlResult, minimize the time-span between clear results and add new results. - // So this will reduce splash issues. After waiting 100ms, if there still no results added, we - // must clear the result. otherwise, it will be confused why the query changed, but the results - // didn't. - if (pnlResult.Dirty) pnlResult.Clear(); - }, TimeSpan.FromMilliseconds(100)); - Query(query); - Dispatcher.DelayInvoke("ShowProgressbar", () => - { - if (!queryHasReturn && !string.IsNullOrEmpty(lastQuery)) - { - StartProgress(); - } - }, TimeSpan.FromMilliseconds(150)); - //reset query history index after user start new query - ResetQueryHistoryIndex(); - }, TimeSpan.FromMilliseconds(searchDelay)); + StartProgress(); + } + }, TimeSpan.FromMilliseconds(150)); + //reset query history index after user start new query + ResetQueryHistoryIndex(); } private void ResetQueryHistoryIndex() { QueryHistoryStorage.Instance.Reset(); } - - private int GetSearchDelay(string query) - { - if (!string.IsNullOrEmpty(query) && PluginManager.IsInstantQuery(query)) - { - Debug.WriteLine("execute query without delay"); - return 0; - } - - Debug.WriteLine("execute query with 200ms delay"); - return 200; - } - private void Query(Query q) { PluginManager.QueryForAllPlugins(q);