PowerToys/Wox.Core/Plugin/QueryDispatcher/UserPluginQueryDispatcher.cs

43 lines
1.5 KiB
C#
Raw Normal View History

2014-01-03 18:16:05 +08:00
using System;
using System.Collections.Generic;
using System.Linq;
2014-01-03 23:52:36 +08:00
using System.Threading;
2015-01-16 23:42:12 +08:00
using Wox.Core.Exception;
using Wox.Core.UserSettings;
2014-09-19 16:57:48 +08:00
using Wox.Infrastructure.Logger;
2014-01-29 18:33:24 +08:00
using Wox.Plugin;
2014-01-03 18:16:05 +08:00
2014-12-26 22:51:04 +08:00
namespace Wox.Core.Plugin.QueryDispatcher
2014-01-03 18:16:05 +08:00
{
2014-12-26 22:51:04 +08:00
public class UserPluginQueryDispatcher : IQueryDispatcher
2014-01-03 18:16:05 +08:00
{
2014-12-26 22:51:04 +08:00
public void Dispatch(Query query)
2014-01-03 23:52:36 +08:00
{
2014-12-26 22:51:04 +08:00
PluginPair userPlugin = PluginManager.AllPlugins.FirstOrDefault(o => o.Metadata.ActionKeyword == query.ActionName);
if (userPlugin != null && !string.IsNullOrEmpty(userPlugin.Metadata.ActionKeyword))
2014-01-03 18:16:05 +08:00
{
2014-12-26 22:51:04 +08:00
var customizedPluginConfig = UserSettingStorage.Instance.CustomizedPluginConfigs.FirstOrDefault(o => o.ID == userPlugin.Metadata.ID);
if (customizedPluginConfig != null && customizedPluginConfig.Disabled)
{
2014-07-05 23:10:34 +08:00
//need to stop the loading animation
2014-12-26 22:51:04 +08:00
PluginManager.API.StopLoadingBar();
return;
}
ThreadPool.QueueUserWorkItem(t =>
{
try
2014-01-03 18:16:05 +08:00
{
2014-12-26 22:51:04 +08:00
List<Result> results = userPlugin.Plugin.Query(query) ?? new List<Result>();
PluginManager.API.PushResults(query,userPlugin.Metadata,results);
}
2015-01-16 23:42:12 +08:00
catch (System.Exception e)
{
2015-01-16 23:42:12 +08:00
throw new WoxPluginException(userPlugin.Metadata.Name, e);
}
});
}
}
2014-01-03 18:16:05 +08:00
}
}