mirror of
https://github.com/microsoft/PowerToys.git
synced 2026-04-06 19:26:39 +02:00
Add IExclusivePlugin
This commit is contained in:
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
|
||||
{
|
||||
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)
|
||||
{
|
||||
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
|
||||
{
|
||||
private static readonly IQueryDispatcher UserPluginDispatcher = new UserPluginQueryDispatcher();
|
||||
private static readonly IQueryDispatcher SystemPluginDispatcher = new SystemPluginQueryDispatcher();
|
||||
private static readonly IQueryDispatcher exclusivePluginDispatcher = new ExclusiveQueryDispatcher();
|
||||
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 (exclusiveSearchPlugin != null)
|
||||
if (PluginManager.IsExclusivePluginQuery(query))
|
||||
{
|
||||
ThreadPool.QueueUserWorkItem(state =>
|
||||
{
|
||||
PluginManager.ExecutePluginQuery(exclusiveSearchPlugin, query);
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
if (PluginManager.IsUserPluginQuery(query))
|
||||
{
|
||||
UserPluginDispatcher.Dispatch(query);
|
||||
exclusivePluginDispatcher.Dispatch(query);
|
||||
}
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user