mirror of
https://github.com/microsoft/PowerToys.git
synced 2026-04-07 19:57:07 +02:00
some API changes for Query class and renames.
This commit is contained in:
@@ -19,7 +19,7 @@ namespace Wox.Core.Plugin
|
||||
/// </summary>
|
||||
public static class PluginManager
|
||||
{
|
||||
public const string ActionKeywordWildcard = "*";
|
||||
public const string ActionKeywordWildcardSign = "*";
|
||||
|
||||
public static String DebuggerMode { get; private set; }
|
||||
public static IPublicAPI API { get; private set; }
|
||||
@@ -104,7 +104,10 @@ namespace Wox.Core.Plugin
|
||||
|
||||
public static void Query(Query query)
|
||||
{
|
||||
QueryDispatcher.QueryDispatcher.Dispatch(query);
|
||||
if (!string.IsNullOrEmpty(query.RawQuery.Trim()))
|
||||
{
|
||||
QueryDispatcher.QueryDispatcher.Dispatch(query);
|
||||
}
|
||||
}
|
||||
|
||||
public static List<PluginPair> AllPlugins
|
||||
@@ -115,16 +118,24 @@ namespace Wox.Core.Plugin
|
||||
}
|
||||
}
|
||||
|
||||
public static bool IsRegularPluginQuery(Query query)
|
||||
public static bool IsUserPluginQuery(Query query)
|
||||
{
|
||||
if (string.IsNullOrEmpty(query.ActionName)) return false;
|
||||
if (string.IsNullOrEmpty(query.RawQuery)) return false;
|
||||
|
||||
return plugins.Any(o => o.Metadata.PluginType == PluginType.User && o.Metadata.ActionKeyword == query.ActionName);
|
||||
var strings = query.RawQuery.Split(' ');
|
||||
var actionKeyword = string.Empty;
|
||||
if (strings.Length > 0)
|
||||
{
|
||||
actionKeyword = strings[0].Trim();
|
||||
}
|
||||
if (string.IsNullOrEmpty(actionKeyword)) return false;
|
||||
|
||||
return plugins.Any(o => o.Metadata.PluginType == PluginType.User && o.Metadata.ActionKeyword == actionKeyword);
|
||||
}
|
||||
|
||||
public static bool IsWildcardPlugin(PluginMetadata metadata)
|
||||
public static bool IsSystemPlugin(PluginMetadata metadata)
|
||||
{
|
||||
return metadata.ActionKeyword == ActionKeywordWildcard;
|
||||
return metadata.ActionKeyword == ActionKeywordWildcardSign;
|
||||
}
|
||||
|
||||
public static void ActivatePluginDebugger(string path)
|
||||
|
||||
@@ -3,18 +3,20 @@ namespace Wox.Core.Plugin.QueryDispatcher
|
||||
{
|
||||
internal static class QueryDispatcher
|
||||
{
|
||||
private static IQueryDispatcher regularDispatcher = new RegularPluginQueryDispatcher();
|
||||
private static IQueryDispatcher wildcardDispatcher = new WildcardPluginQueryDispatcher();
|
||||
private static readonly IQueryDispatcher UserPluginDispatcher = new UserPluginQueryDispatcher();
|
||||
private static readonly IQueryDispatcher SystemPluginDispatcher = new SystemPluginQueryDispatcher();
|
||||
|
||||
public static void Dispatch(Wox.Plugin.Query query)
|
||||
{
|
||||
if (PluginManager.IsRegularPluginQuery(query))
|
||||
if (PluginManager.IsUserPluginQuery(query))
|
||||
{
|
||||
regularDispatcher.Dispatch(query);
|
||||
query.Search = query.RawQuery.Substring(query.RawQuery.IndexOf(' ') + 1);
|
||||
UserPluginDispatcher.Dispatch(query);
|
||||
}
|
||||
else
|
||||
{
|
||||
wildcardDispatcher.Dispatch(query);
|
||||
query.Search = query.RawQuery;
|
||||
SystemPluginDispatcher.Dispatch(query);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,9 +8,9 @@ using Wox.Plugin;
|
||||
|
||||
namespace Wox.Core.Plugin.QueryDispatcher
|
||||
{
|
||||
public class WildcardPluginQueryDispatcher : IQueryDispatcher
|
||||
public class SystemPluginQueryDispatcher : IQueryDispatcher
|
||||
{
|
||||
private IEnumerable<PluginPair> allSytemPlugins = PluginManager.AllPlugins.Where(o => PluginManager.IsWildcardPlugin(o.Metadata));
|
||||
private IEnumerable<PluginPair> allSytemPlugins = PluginManager.AllPlugins.Where(o => PluginManager.IsSystemPlugin(o.Metadata));
|
||||
|
||||
public void Dispatch(Query query)
|
||||
{
|
||||
@@ -9,14 +9,14 @@ using Wox.Plugin;
|
||||
|
||||
namespace Wox.Core.Plugin.QueryDispatcher
|
||||
{
|
||||
public class RegularPluginQueryDispatcher : IQueryDispatcher
|
||||
public class UserPluginQueryDispatcher : IQueryDispatcher
|
||||
{
|
||||
public void Dispatch(Query query)
|
||||
{
|
||||
PluginPair regularPlugin = PluginManager.AllPlugins.FirstOrDefault(o => o.Metadata.ActionKeyword == query.ActionName);
|
||||
if (regularPlugin != null && !string.IsNullOrEmpty(regularPlugin.Metadata.ActionKeyword))
|
||||
PluginPair userPlugin = PluginManager.AllPlugins.FirstOrDefault(o => o.Metadata.ActionKeyword == query.GetActionKeyword());
|
||||
if (userPlugin != null && !string.IsNullOrEmpty(userPlugin.Metadata.ActionKeyword))
|
||||
{
|
||||
var customizedPluginConfig = UserSettingStorage.Instance.CustomizedPluginConfigs.FirstOrDefault(o => o.ID == regularPlugin.Metadata.ID);
|
||||
var customizedPluginConfig = UserSettingStorage.Instance.CustomizedPluginConfigs.FirstOrDefault(o => o.ID == userPlugin.Metadata.ID);
|
||||
if (customizedPluginConfig != null && customizedPluginConfig.Disabled)
|
||||
{
|
||||
//need to stop the loading animation
|
||||
@@ -28,16 +28,16 @@ namespace Wox.Core.Plugin.QueryDispatcher
|
||||
{
|
||||
try
|
||||
{
|
||||
List<Result> results = regularPlugin.Plugin.Query(query) ?? new List<Result>();
|
||||
List<Result> results = userPlugin.Plugin.Query(query) ?? new List<Result>();
|
||||
results.ForEach(o =>
|
||||
{
|
||||
o.PluginID = regularPlugin.Metadata.ID;
|
||||
o.PluginID = userPlugin.Metadata.ID;
|
||||
});
|
||||
PluginManager.API.PushResults(query, regularPlugin.Metadata, results);
|
||||
PluginManager.API.PushResults(query, userPlugin.Metadata, results);
|
||||
}
|
||||
catch (System.Exception e)
|
||||
{
|
||||
throw new WoxPluginException(regularPlugin.Metadata.Name, e);
|
||||
throw new WoxPluginException(userPlugin.Metadata.Name, e);
|
||||
}
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user