PowerToys/Wox/Commands/PluginCommand.cs

49 lines
1.7 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;
2014-01-29 18:33:24 +08:00
using Wox.Helper;
using Wox.Infrastructure.Storage.UserSettings;
2014-01-29 18:33:24 +08:00
using Wox.Plugin;
using Wox.PluginLoader;
2014-01-03 18:16:05 +08:00
2014-01-29 18:33:24 +08:00
namespace Wox.Commands
2014-01-03 18:16:05 +08:00
{
2014-01-03 23:52:36 +08:00
public class PluginCommand : BaseCommand
2014-01-03 18:16:05 +08:00
{
2014-07-05 23:10:34 +08:00
public override void Dispatch(Query query)
2014-01-03 23:52:36 +08:00
{
2014-07-05 23:10:34 +08:00
PluginPair thirdPlugin = Plugins.AllPlugins.FirstOrDefault(o => o.Metadata.ActionKeyword == query.ActionName);
if (thirdPlugin != null && !string.IsNullOrEmpty(thirdPlugin.Metadata.ActionKeyword))
2014-01-03 18:16:05 +08:00
{
var customizedPluginConfig = UserSettingStorage.Instance.CustomizedPluginConfigs.FirstOrDefault(o => o.ID == thirdPlugin.Metadata.ID);
if (customizedPluginConfig != null && customizedPluginConfig.Disabled)
{
2014-07-05 23:10:34 +08:00
//need to stop the loading animation
UpdateResultView(null);
return;
}
ThreadPool.QueueUserWorkItem(t =>
{
try
2014-01-03 18:16:05 +08:00
{
2014-07-05 23:10:34 +08:00
List<Result> results = thirdPlugin.Plugin.Query(query) ?? new List<Result>();
App.Window.PushResults(query,thirdPlugin.Metadata,results);
}
catch (Exception queryException)
{
Log.Error(string.Format("Plugin {0} query failed: {1}", thirdPlugin.Metadata.Name,
queryException.Message));
2014-01-03 23:52:36 +08:00
#if (DEBUG)
{
throw;
2014-01-03 23:52:36 +08:00
}
#endif
}
});
}
}
2014-01-03 18:16:05 +08:00
}
}