mirror of
https://github.com/microsoft/PowerToys.git
synced 2026-04-08 04:07:40 +02:00
Add IExclusivePlugin
This commit is contained in:
@@ -14,7 +14,7 @@ using Control = System.Windows.Controls.Control;
|
|||||||
|
|
||||||
namespace Wox.Plugin.CMD
|
namespace Wox.Plugin.CMD
|
||||||
{
|
{
|
||||||
public class CMD : IPlugin, ISettingProvider, IPluginI18n, IInstantSearch,IExclusiveSearch
|
public class CMD : IPlugin, ISettingProvider, IPluginI18n, IInstantQuery, IExclusiveQuery
|
||||||
{
|
{
|
||||||
private PluginInitContext context;
|
private PluginInitContext context;
|
||||||
private bool WinRStroked;
|
private bool WinRStroked;
|
||||||
@@ -213,13 +213,13 @@ namespace Wox.Plugin.CMD
|
|||||||
return Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "Languages");
|
return Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "Languages");
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool IsInstantSearch(string query)
|
public bool IsInstantQuery(string query)
|
||||||
{
|
{
|
||||||
if (query.StartsWith(">")) return true;
|
if (query.StartsWith(">")) return true;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool IsExclusiveSearch(Query query)
|
public bool IsExclusiveQuery(Query query)
|
||||||
{
|
{
|
||||||
return query.Search.StartsWith(">");
|
return query.Search.StartsWith(">");
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ namespace Wox.Plugin.PluginIndicator
|
|||||||
List<Result> results = new List<Result>();
|
List<Result> results = new List<Result>();
|
||||||
if (allPlugins.Count == 0)
|
if (allPlugins.Count == 0)
|
||||||
{
|
{
|
||||||
allPlugins = context.API.GetAllPlugins().Where(o => !PluginManager.IsSystemPlugin(o.Metadata)).ToList();
|
allPlugins = context.API.GetAllPlugins().Where(o => !PluginManager.IsGenericPlugin(o.Metadata)).ToList();
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach (PluginMetadata metadata in allPlugins.Select(o => o.Metadata))
|
foreach (PluginMetadata metadata in allPlugins.Select(o => o.Metadata))
|
||||||
@@ -45,19 +45,6 @@ namespace Wox.Plugin.PluginIndicator
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//results.AddRange(UserSettingStorage.Instance.WebSearches.Where(o => o.ActionWord.StartsWith(query.Search) && o.Enabled).Select(n => new Result()
|
|
||||||
//{
|
|
||||||
// Title = n.ActionWord,
|
|
||||||
// SubTitle = string.Format("Activate {0} web search", n.ActionWord),
|
|
||||||
// Score = 100,
|
|
||||||
// IcoPath = "Images/work.png",
|
|
||||||
// Action = (c) =>
|
|
||||||
// {
|
|
||||||
// context.API.ChangeQuery(n.ActionWord + " ");
|
|
||||||
// return false;
|
|
||||||
// }
|
|
||||||
//}));
|
|
||||||
|
|
||||||
return results;
|
return results;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -5,11 +5,12 @@ using System.IO;
|
|||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
using Wox.Core.UserSettings;
|
using Wox.Core.UserSettings;
|
||||||
|
using Wox.Plugin.Features;
|
||||||
using Wox.Plugin.WebSearch.SuggestionSources;
|
using Wox.Plugin.WebSearch.SuggestionSources;
|
||||||
|
|
||||||
namespace Wox.Plugin.WebSearch
|
namespace Wox.Plugin.WebSearch
|
||||||
{
|
{
|
||||||
public class WebSearchPlugin : IPlugin, ISettingProvider, IPluginI18n, IInstantSearch
|
public class WebQueryPlugin : IPlugin, ISettingProvider, IPluginI18n, IInstantQuery, IExclusiveQuery
|
||||||
{
|
{
|
||||||
private PluginInitContext context;
|
private PluginInitContext context;
|
||||||
|
|
||||||
@@ -18,7 +19,7 @@ namespace Wox.Plugin.WebSearch
|
|||||||
List<Result> results = new List<Result>();
|
List<Result> results = new List<Result>();
|
||||||
|
|
||||||
WebSearch webSearch =
|
WebSearch webSearch =
|
||||||
WebSearchStorage.Instance.WebSearches.FirstOrDefault(o => o.ActionWord == query.FirstSearch.Trim() && o.Enabled);
|
WebSearchStorage.Instance.WebSearches.FirstOrDefault(o => o.ActionWord == query.FirstSearch.Trim() && !string.IsNullOrEmpty(query.SecondSearch) && o.Enabled);
|
||||||
|
|
||||||
if (webSearch != null)
|
if (webSearch != null)
|
||||||
{
|
{
|
||||||
@@ -98,15 +99,19 @@ namespace Wox.Plugin.WebSearch
|
|||||||
return Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "Languages");
|
return Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "Languages");
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool IsInstantSearch(string query)
|
public bool IsInstantQuery(string query)
|
||||||
{
|
{
|
||||||
var strings = query.Split(' ');
|
var strings = query.Split(' ');
|
||||||
if (strings.Length > 1)
|
if (strings.Length > 1)
|
||||||
{
|
{
|
||||||
return WebSearchStorage.Instance.EnableWebSearchSuggestion &&
|
return WebSearchStorage.Instance.WebSearches.Exists(o => o.ActionWord == strings[0] && o.Enabled);
|
||||||
WebSearchStorage.Instance.WebSearches.Exists(o => o.ActionWord == strings[0] && o.Enabled);
|
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public bool IsExclusiveQuery(Query query)
|
||||||
|
{
|
||||||
|
return IsInstantQuery(query.RawQuery);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -60,7 +60,7 @@
|
|||||||
<Compile Include="WebSearchesSetting.xaml.cs">
|
<Compile Include="WebSearchesSetting.xaml.cs">
|
||||||
<DependentUpon>WebSearchesSetting.xaml</DependentUpon>
|
<DependentUpon>WebSearchesSetting.xaml</DependentUpon>
|
||||||
</Compile>
|
</Compile>
|
||||||
<Compile Include="WebSearchPlugin.cs" />
|
<Compile Include="WebQueryPlugin.cs" />
|
||||||
<Compile Include="WebSearchSetting.xaml.cs">
|
<Compile Include="WebSearchSetting.xaml.cs">
|
||||||
<DependentUpon>WebSearchSetting.xaml</DependentUpon>
|
<DependentUpon>WebSearchSetting.xaml</DependentUpon>
|
||||||
</Compile>
|
</Compile>
|
||||||
|
|||||||
@@ -78,7 +78,6 @@ namespace Wox.Core.Plugin
|
|||||||
try
|
try
|
||||||
{
|
{
|
||||||
metadata = JsonConvert.DeserializeObject<PluginMetadata>(File.ReadAllText(configPath));
|
metadata = JsonConvert.DeserializeObject<PluginMetadata>(File.ReadAllText(configPath));
|
||||||
metadata.PluginType = PluginType.User;
|
|
||||||
metadata.PluginDirectory = pluginDirectory;
|
metadata.PluginDirectory = pluginDirectory;
|
||||||
}
|
}
|
||||||
catch (System.Exception)
|
catch (System.Exception)
|
||||||
|
|||||||
@@ -112,7 +112,6 @@ namespace Wox.Core.Plugin
|
|||||||
try
|
try
|
||||||
{
|
{
|
||||||
metadata = JsonConvert.DeserializeObject<PluginMetadata>(File.ReadAllText(configPath));
|
metadata = JsonConvert.DeserializeObject<PluginMetadata>(File.ReadAllText(configPath));
|
||||||
metadata.PluginType = PluginType.User;
|
|
||||||
metadata.PluginDirectory = pluginDirectory;
|
metadata.PluginDirectory = pluginDirectory;
|
||||||
}
|
}
|
||||||
catch (System.Exception)
|
catch (System.Exception)
|
||||||
|
|||||||
@@ -23,8 +23,8 @@ namespace Wox.Core.Plugin
|
|||||||
{
|
{
|
||||||
public const string ActionKeywordWildcardSign = "*";
|
public const string ActionKeywordWildcardSign = "*";
|
||||||
private static List<PluginMetadata> pluginMetadatas;
|
private static List<PluginMetadata> pluginMetadatas;
|
||||||
private static List<KeyValuePair<PluginMetadata, IInstantSearch>> instantSearches;
|
private static List<KeyValuePair<PluginMetadata, IInstantQuery>> instantSearches;
|
||||||
private static List<KeyValuePair<PluginPair,IExclusiveSearch>> exclusiveSearchPlugins;
|
private static List<KeyValuePair<PluginPair, IExclusiveQuery>> exclusiveSearchPlugins;
|
||||||
|
|
||||||
public static String DebuggerMode { get; private set; }
|
public static String DebuggerMode { get; private set; }
|
||||||
public static IPublicAPI API { get; private set; }
|
public static IPublicAPI API { get; private set; }
|
||||||
@@ -117,7 +117,7 @@ namespace Wox.Core.Plugin
|
|||||||
{
|
{
|
||||||
if (!string.IsNullOrEmpty(query.RawQuery.Trim()))
|
if (!string.IsNullOrEmpty(query.RawQuery.Trim()))
|
||||||
{
|
{
|
||||||
query.Search = IsUserPluginQuery(query) ? query.RawQuery.Substring(query.RawQuery.IndexOf(' ') + 1) : query.RawQuery;
|
query.Search = IsActionKeywordQuery(query) ? query.RawQuery.Substring(query.RawQuery.IndexOf(' ') + 1) : query.RawQuery;
|
||||||
QueryDispatcher.QueryDispatcher.Dispatch(query);
|
QueryDispatcher.QueryDispatcher.Dispatch(query);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -130,7 +130,12 @@ namespace Wox.Core.Plugin
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static bool IsUserPluginQuery(Query query)
|
/// <summary>
|
||||||
|
/// Check if a query contains action keyword
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="query"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public static bool IsActionKeywordQuery(Query query)
|
||||||
{
|
{
|
||||||
if (string.IsNullOrEmpty(query.RawQuery)) return false;
|
if (string.IsNullOrEmpty(query.RawQuery)) return false;
|
||||||
var strings = query.RawQuery.Split(' ');
|
var strings = query.RawQuery.Split(' ');
|
||||||
@@ -139,10 +144,10 @@ namespace Wox.Core.Plugin
|
|||||||
var actionKeyword = strings[0].Trim();
|
var actionKeyword = strings[0].Trim();
|
||||||
if (string.IsNullOrEmpty(actionKeyword)) return false;
|
if (string.IsNullOrEmpty(actionKeyword)) return false;
|
||||||
|
|
||||||
return plugins.Any(o => o.Metadata.PluginType == PluginType.User && o.Metadata.ActionKeyword == actionKeyword);
|
return plugins.Any(o => o.Metadata.ActionKeyword == actionKeyword);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static bool IsSystemPlugin(PluginMetadata metadata)
|
public static bool IsGenericPlugin(PluginMetadata metadata)
|
||||||
{
|
{
|
||||||
return metadata.ActionKeyword == ActionKeywordWildcardSign;
|
return metadata.ActionKeyword == ActionKeywordWildcardSign;
|
||||||
}
|
}
|
||||||
@@ -152,9 +157,9 @@ namespace Wox.Core.Plugin
|
|||||||
DebuggerMode = path;
|
DebuggerMode = path;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static bool IsInstantSearch(string query)
|
public static bool IsInstantQuery(string query)
|
||||||
{
|
{
|
||||||
return LoadInstantSearches().Any(o => o.Value.IsInstantSearch(query));
|
return LoadInstantSearches().Any(o => o.Value.IsInstantQuery(query));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static bool IsInstantSearchPlugin(PluginMetadata pluginMetadata)
|
public static bool IsInstantSearchPlugin(PluginMetadata pluginMetadata)
|
||||||
@@ -194,11 +199,11 @@ namespace Wox.Core.Plugin
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static List<KeyValuePair<PluginMetadata, IInstantSearch>> LoadInstantSearches()
|
private static List<KeyValuePair<PluginMetadata, IInstantQuery>> LoadInstantSearches()
|
||||||
{
|
{
|
||||||
if (instantSearches != null) return instantSearches;
|
if (instantSearches != null) return instantSearches;
|
||||||
|
|
||||||
instantSearches = new List<KeyValuePair<PluginMetadata, IInstantSearch>>();
|
instantSearches = new List<KeyValuePair<PluginMetadata, IInstantQuery>>();
|
||||||
List<PluginMetadata> CSharpPluginMetadatas = pluginMetadatas.Where(o => o.Language.ToUpper() == AllowedLanguage.CSharp.ToUpper()).ToList();
|
List<PluginMetadata> CSharpPluginMetadatas = pluginMetadatas.Where(o => o.Language.ToUpper() == AllowedLanguage.CSharp.ToUpper()).ToList();
|
||||||
|
|
||||||
foreach (PluginMetadata metadata in CSharpPluginMetadatas)
|
foreach (PluginMetadata metadata in CSharpPluginMetadatas)
|
||||||
@@ -206,7 +211,7 @@ namespace Wox.Core.Plugin
|
|||||||
try
|
try
|
||||||
{
|
{
|
||||||
Assembly asm = Assembly.Load(AssemblyName.GetAssemblyName(metadata.ExecuteFilePath));
|
Assembly asm = Assembly.Load(AssemblyName.GetAssemblyName(metadata.ExecuteFilePath));
|
||||||
List<Type> types = asm.GetTypes().Where(o => o.IsClass && !o.IsAbstract && o.GetInterfaces().Contains(typeof(IInstantSearch))).ToList();
|
List<Type> types = asm.GetTypes().Where(o => o.IsClass && !o.IsAbstract && o.GetInterfaces().Contains(typeof(IInstantQuery))).ToList();
|
||||||
if (types.Count == 0)
|
if (types.Count == 0)
|
||||||
{
|
{
|
||||||
continue;
|
continue;
|
||||||
@@ -214,7 +219,7 @@ namespace Wox.Core.Plugin
|
|||||||
|
|
||||||
foreach (Type type in types)
|
foreach (Type type in types)
|
||||||
{
|
{
|
||||||
instantSearches.Add(new KeyValuePair<PluginMetadata, IInstantSearch>(metadata, Activator.CreateInstance(type) as IInstantSearch));
|
instantSearches.Add(new KeyValuePair<PluginMetadata, IInstantQuery>(metadata, Activator.CreateInstance(type) as IInstantQuery));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (System.Exception e)
|
catch (System.Exception e)
|
||||||
@@ -241,11 +246,11 @@ namespace Wox.Core.Plugin
|
|||||||
return AllPlugins.FirstOrDefault(o => o.Metadata.ID == id);
|
return AllPlugins.FirstOrDefault(o => o.Metadata.ID == id);
|
||||||
}
|
}
|
||||||
|
|
||||||
internal static List<KeyValuePair<PluginPair, IExclusiveSearch>> LoadExclusiveSearchPlugins()
|
internal static List<KeyValuePair<PluginPair, IExclusiveQuery>> LoadExclusiveSearchPlugins()
|
||||||
{
|
{
|
||||||
if (exclusiveSearchPlugins != null) return exclusiveSearchPlugins;
|
if (exclusiveSearchPlugins != null) return exclusiveSearchPlugins;
|
||||||
|
|
||||||
exclusiveSearchPlugins = new List<KeyValuePair<PluginPair, IExclusiveSearch>>();
|
exclusiveSearchPlugins = new List<KeyValuePair<PluginPair, IExclusiveQuery>>();
|
||||||
List<PluginMetadata> CSharpPluginMetadatas = pluginMetadatas.Where(o => o.Language.ToUpper() == AllowedLanguage.CSharp.ToUpper()).ToList();
|
List<PluginMetadata> CSharpPluginMetadatas = pluginMetadatas.Where(o => o.Language.ToUpper() == AllowedLanguage.CSharp.ToUpper()).ToList();
|
||||||
|
|
||||||
foreach (PluginMetadata metadata in CSharpPluginMetadatas)
|
foreach (PluginMetadata metadata in CSharpPluginMetadatas)
|
||||||
@@ -253,7 +258,7 @@ namespace Wox.Core.Plugin
|
|||||||
try
|
try
|
||||||
{
|
{
|
||||||
Assembly asm = Assembly.Load(AssemblyName.GetAssemblyName(metadata.ExecuteFilePath));
|
Assembly asm = Assembly.Load(AssemblyName.GetAssemblyName(metadata.ExecuteFilePath));
|
||||||
List<Type> types = asm.GetTypes().Where(o => o.IsClass && !o.IsAbstract && o.GetInterfaces().Contains(typeof(IExclusiveSearch))).ToList();
|
List<Type> types = asm.GetTypes().Where(o => o.IsClass && !o.IsAbstract && o.GetInterfaces().Contains(typeof(IExclusiveQuery))).ToList();
|
||||||
if (types.Count == 0)
|
if (types.Count == 0)
|
||||||
{
|
{
|
||||||
continue;
|
continue;
|
||||||
@@ -261,8 +266,8 @@ namespace Wox.Core.Plugin
|
|||||||
|
|
||||||
foreach (Type type in types)
|
foreach (Type type in types)
|
||||||
{
|
{
|
||||||
exclusiveSearchPlugins.Add(new KeyValuePair<PluginPair, IExclusiveSearch>(AllPlugins.First(o => o.Metadata.ID == metadata.ID),
|
exclusiveSearchPlugins.Add(new KeyValuePair<PluginPair, IExclusiveQuery>(AllPlugins.First(o => o.Metadata.ID == metadata.ID),
|
||||||
Activator.CreateInstance(type) as IExclusiveSearch));
|
Activator.CreateInstance(type) as IExclusiveQuery));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (System.Exception e)
|
catch (System.Exception e)
|
||||||
@@ -279,12 +284,31 @@ namespace Wox.Core.Plugin
|
|||||||
return exclusiveSearchPlugins;
|
return exclusiveSearchPlugins;
|
||||||
}
|
}
|
||||||
|
|
||||||
internal static PluginPair GetExclusiveSearchPlugin(Query query)
|
internal static PluginPair GetExclusivePlugin(Query query)
|
||||||
{
|
{
|
||||||
KeyValuePair<PluginPair, IExclusiveSearch> plugin = LoadExclusiveSearchPlugins().FirstOrDefault(o => o.Value.IsExclusiveSearch((query)));
|
KeyValuePair<PluginPair, IExclusiveQuery> plugin = LoadExclusiveSearchPlugins().FirstOrDefault(o => o.Value.IsExclusiveQuery((query)));
|
||||||
if (plugin.Key != null) return plugin.Key;
|
return plugin.Key;
|
||||||
|
}
|
||||||
|
|
||||||
|
internal static PluginPair GetActionKeywordPlugin(Query query)
|
||||||
|
{
|
||||||
|
PluginPair exclusivePluginPair = AllPlugins.FirstOrDefault(o => o.Metadata.ActionKeyword == query.GetActionKeyword());
|
||||||
|
if (exclusivePluginPair != null)
|
||||||
|
{
|
||||||
|
var customizedPluginConfig = UserSettingStorage.Instance.
|
||||||
|
CustomizedPluginConfigs.FirstOrDefault(o => o.ID == exclusivePluginPair.Metadata.ID);
|
||||||
|
if (customizedPluginConfig != null && !customizedPluginConfig.Disabled)
|
||||||
|
{
|
||||||
|
return exclusivePluginPair;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
internal static bool IsExclusivePluginQuery(Query query)
|
||||||
|
{
|
||||||
|
return GetExclusivePlugin(query) != null || GetActionKeywordPlugin(query) != null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
30
Wox.Core/Plugin/QueryDispatcher/ExclusiveQueryDispatcher.cs
Normal file
30
Wox.Core/Plugin/QueryDispatcher/ExclusiveQueryDispatcher.cs
Normal file
@@ -0,0 +1,30 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Threading;
|
||||||
|
using Wox.Core.Exception;
|
||||||
|
using Wox.Core.UserSettings;
|
||||||
|
using Wox.Infrastructure.Logger;
|
||||||
|
using Wox.Plugin;
|
||||||
|
|
||||||
|
namespace Wox.Core.Plugin.QueryDispatcher
|
||||||
|
{
|
||||||
|
public class ExclusiveQueryDispatcher : BaseQueryDispatcher
|
||||||
|
{
|
||||||
|
protected override List<PluginPair> GetPlugins(Query query)
|
||||||
|
{
|
||||||
|
List<PluginPair> pluginPairs = new List<PluginPair>();
|
||||||
|
var exclusivePluginPair = PluginManager.GetExclusivePlugin(query) ??
|
||||||
|
PluginManager.GetActionKeywordPlugin(query);
|
||||||
|
if (exclusivePluginPair != null)
|
||||||
|
{
|
||||||
|
pluginPairs.Add(exclusivePluginPair);
|
||||||
|
}
|
||||||
|
|
||||||
|
return pluginPairs;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -8,14 +8,11 @@ using Wox.Plugin;
|
|||||||
|
|
||||||
namespace Wox.Core.Plugin.QueryDispatcher
|
namespace Wox.Core.Plugin.QueryDispatcher
|
||||||
{
|
{
|
||||||
public class SystemPluginQueryDispatcher : BaseQueryDispatcher
|
public class GenericQueryDispatcher : BaseQueryDispatcher
|
||||||
{
|
{
|
||||||
private readonly List<PluginPair> allSytemPlugins =
|
|
||||||
PluginManager.AllPlugins.Where(o => PluginManager.IsSystemPlugin(o.Metadata)).ToList();
|
|
||||||
|
|
||||||
protected override List<PluginPair> GetPlugins(Query query)
|
protected override List<PluginPair> GetPlugins(Query query)
|
||||||
{
|
{
|
||||||
return allSytemPlugins;
|
return PluginManager.AllPlugins.Where(o => PluginManager.IsGenericPlugin(o.Metadata)).ToList();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -6,28 +6,18 @@ namespace Wox.Core.Plugin.QueryDispatcher
|
|||||||
{
|
{
|
||||||
internal static class QueryDispatcher
|
internal static class QueryDispatcher
|
||||||
{
|
{
|
||||||
private static readonly IQueryDispatcher UserPluginDispatcher = new UserPluginQueryDispatcher();
|
private static readonly IQueryDispatcher exclusivePluginDispatcher = new ExclusiveQueryDispatcher();
|
||||||
private static readonly IQueryDispatcher SystemPluginDispatcher = new SystemPluginQueryDispatcher();
|
private static readonly IQueryDispatcher genericQueryDispatcher = new GenericQueryDispatcher();
|
||||||
|
|
||||||
public static void Dispatch(Wox.Plugin.Query query)
|
public static void Dispatch(Query query)
|
||||||
{
|
{
|
||||||
PluginPair exclusiveSearchPlugin = PluginManager.GetExclusiveSearchPlugin(query);
|
if (PluginManager.IsExclusivePluginQuery(query))
|
||||||
if (exclusiveSearchPlugin != null)
|
|
||||||
{
|
{
|
||||||
ThreadPool.QueueUserWorkItem(state =>
|
exclusivePluginDispatcher.Dispatch(query);
|
||||||
{
|
|
||||||
PluginManager.ExecutePluginQuery(exclusiveSearchPlugin, query);
|
|
||||||
});
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (PluginManager.IsUserPluginQuery(query))
|
|
||||||
{
|
|
||||||
UserPluginDispatcher.Dispatch(query);
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
SystemPluginDispatcher.Dispatch(query);
|
genericQueryDispatcher.Dispatch(query);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,37 +0,0 @@
|
|||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Threading;
|
|
||||||
using Wox.Core.Exception;
|
|
||||||
using Wox.Core.UserSettings;
|
|
||||||
using Wox.Infrastructure.Logger;
|
|
||||||
using Wox.Plugin;
|
|
||||||
|
|
||||||
namespace Wox.Core.Plugin.QueryDispatcher
|
|
||||||
{
|
|
||||||
public class UserPluginQueryDispatcher : BaseQueryDispatcher
|
|
||||||
{
|
|
||||||
protected override List<PluginPair> GetPlugins(Query query)
|
|
||||||
{
|
|
||||||
List<PluginPair> plugins = new List<PluginPair>();
|
|
||||||
//only first plugin that matches action keyword will get executed
|
|
||||||
PluginPair userPlugin = PluginManager.AllPlugins.FirstOrDefault(o => o.Metadata.ActionKeyword == query.GetActionKeyword());
|
|
||||||
if (userPlugin != null)
|
|
||||||
{
|
|
||||||
var customizedPluginConfig = UserSettingStorage.Instance.
|
|
||||||
CustomizedPluginConfigs.FirstOrDefault(o => o.ID == userPlugin.Metadata.ID);
|
|
||||||
if (customizedPluginConfig != null && customizedPluginConfig.Disabled)
|
|
||||||
{
|
|
||||||
//need to stop the loading animation
|
|
||||||
PluginManager.API.StopLoadingBar();
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
plugins.Add(userPlugin);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return plugins;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -86,8 +86,8 @@
|
|||||||
<Compile Include="Plugin\PluginInstaller.cs" />
|
<Compile Include="Plugin\PluginInstaller.cs" />
|
||||||
<Compile Include="Plugin\QueryDispatcher\IQueryDispatcher.cs" />
|
<Compile Include="Plugin\QueryDispatcher\IQueryDispatcher.cs" />
|
||||||
<Compile Include="Plugin\QueryDispatcher\QueryDispatcher.cs" />
|
<Compile Include="Plugin\QueryDispatcher\QueryDispatcher.cs" />
|
||||||
<Compile Include="Plugin\QueryDispatcher\UserPluginQueryDispatcher.cs" />
|
<Compile Include="Plugin\QueryDispatcher\ExclusiveQueryDispatcher.cs" />
|
||||||
<Compile Include="Plugin\QueryDispatcher\SystemPluginQueryDispatcher.cs" />
|
<Compile Include="Plugin\QueryDispatcher\GenericQueryDispatcher.cs" />
|
||||||
<Compile Include="Plugin\JsonRPCPlugin.cs" />
|
<Compile Include="Plugin\JsonRPCPlugin.cs" />
|
||||||
<Compile Include="Plugin\JsonRPCPluginLoader.cs" />
|
<Compile Include="Plugin\JsonRPCPluginLoader.cs" />
|
||||||
<Compile Include="Plugin\CSharpPluginLoader.cs" />
|
<Compile Include="Plugin\CSharpPluginLoader.cs" />
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ namespace Wox.Infrastructure
|
|||||||
{
|
{
|
||||||
public static void WriteLine(string msg)
|
public static void WriteLine(string msg)
|
||||||
{
|
{
|
||||||
|
return;
|
||||||
Debug.WriteLine(msg);
|
Debug.WriteLine(msg);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,8 +5,8 @@ using System.Text;
|
|||||||
|
|
||||||
namespace Wox.Plugin.Features
|
namespace Wox.Plugin.Features
|
||||||
{
|
{
|
||||||
public interface IExclusiveSearch
|
public interface IExclusiveQuery
|
||||||
{
|
{
|
||||||
bool IsExclusiveSearch(Query query);
|
bool IsExclusiveQuery(Query query);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
7
Wox.Plugin/Features/IInstantQuery.cs
Normal file
7
Wox.Plugin/Features/IInstantQuery.cs
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
namespace Wox.Plugin.Features
|
||||||
|
{
|
||||||
|
public interface IInstantQuery
|
||||||
|
{
|
||||||
|
bool IsInstantQuery(string query);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,13 +0,0 @@
|
|||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Text;
|
|
||||||
using Wox.Plugin.Features;
|
|
||||||
|
|
||||||
namespace Wox.Plugin
|
|
||||||
{
|
|
||||||
public interface IInstantSearch
|
|
||||||
{
|
|
||||||
bool IsInstantSearch(string query);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -24,10 +24,10 @@ namespace Wox.Plugin
|
|||||||
}
|
}
|
||||||
|
|
||||||
public string ExecuteFileName { get; set; }
|
public string ExecuteFileName { get; set; }
|
||||||
|
|
||||||
public string PluginDirectory { get; set; }
|
public string PluginDirectory { get; set; }
|
||||||
|
|
||||||
public string ActionKeyword { get; set; }
|
public string ActionKeyword { get; set; }
|
||||||
public PluginType PluginType { get; set; }
|
|
||||||
|
|
||||||
public string IcoPath { get; set; }
|
public string IcoPath { get; set; }
|
||||||
|
|
||||||
|
|||||||
@@ -1,13 +0,0 @@
|
|||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Text;
|
|
||||||
|
|
||||||
namespace Wox.Plugin
|
|
||||||
{
|
|
||||||
public enum PluginType
|
|
||||||
{
|
|
||||||
System,
|
|
||||||
User
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -46,8 +46,8 @@
|
|||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Compile Include="AllowedLanguage.cs" />
|
<Compile Include="AllowedLanguage.cs" />
|
||||||
<Compile Include="EventHandler.cs" />
|
<Compile Include="EventHandler.cs" />
|
||||||
<Compile Include="Features\IExclusiveSearch.cs" />
|
<Compile Include="Features\IExclusiveQuery.cs" />
|
||||||
<Compile Include="IInstantSearch.cs" />
|
<Compile Include="Features\IInstantQuery.cs" />
|
||||||
<Compile Include="IHttpProxy.cs" />
|
<Compile Include="IHttpProxy.cs" />
|
||||||
<Compile Include="IPluginI18n.cs" />
|
<Compile Include="IPluginI18n.cs" />
|
||||||
<Compile Include="IPlugin.cs" />
|
<Compile Include="IPlugin.cs" />
|
||||||
@@ -56,7 +56,6 @@
|
|||||||
<Compile Include="PluginPair.cs" />
|
<Compile Include="PluginPair.cs" />
|
||||||
<Compile Include="PluginInitContext.cs" />
|
<Compile Include="PluginInitContext.cs" />
|
||||||
<Compile Include="PluginMetadata.cs" />
|
<Compile Include="PluginMetadata.cs" />
|
||||||
<Compile Include="PluginType.cs" />
|
|
||||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||||
<Compile Include="Query.cs" />
|
<Compile Include="Query.cs" />
|
||||||
<Compile Include="Result.cs" />
|
<Compile Include="Result.cs" />
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ namespace Wox.Test
|
|||||||
public class QueryTest
|
public class QueryTest
|
||||||
{
|
{
|
||||||
[Test]
|
[Test]
|
||||||
public void UserPluginQueryTest()
|
public void ExclusivePluginQueryTest()
|
||||||
{
|
{
|
||||||
Query q = new Query("f file.txt file2 file3");
|
Query q = new Query("f file.txt file2 file3");
|
||||||
q.Search = "file.txt file2 file3";
|
q.Search = "file.txt file2 file3";
|
||||||
@@ -23,7 +23,7 @@ namespace Wox.Test
|
|||||||
}
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
public void SystemPluginQueryTest()
|
public void GenericPluginQueryTest()
|
||||||
{
|
{
|
||||||
Query q = new Query("file.txt file2 file3");
|
Query q = new Query("file.txt file2 file3");
|
||||||
q.Search = q.RawQuery;
|
q.Search = q.RawQuery;
|
||||||
|
|||||||
@@ -416,7 +416,7 @@ namespace Wox
|
|||||||
|
|
||||||
private int GetSearchDelay(string query)
|
private int GetSearchDelay(string query)
|
||||||
{
|
{
|
||||||
if (!string.IsNullOrEmpty(query) && PluginManager.IsInstantSearch(query))
|
if (!string.IsNullOrEmpty(query) && PluginManager.IsInstantQuery(query))
|
||||||
{
|
{
|
||||||
DebugHelper.WriteLine("execute query without delay");
|
DebugHelper.WriteLine("execute query without delay");
|
||||||
return 0;
|
return 0;
|
||||||
|
|||||||
Reference in New Issue
Block a user