2014-01-03 18:16:05 +08:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
2014-01-11 15:02:17 +08:00
|
|
|
|
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;
|
2014-07-01 22:19:46 +08:00
|
|
|
|
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);
|
2014-01-11 15:02:17 +08:00
|
|
|
|
if (thirdPlugin != null && !string.IsNullOrEmpty(thirdPlugin.Metadata.ActionKeyword))
|
2014-01-03 18:16:05 +08:00
|
|
|
|
{
|
2014-07-01 22:19:46 +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
|
2014-07-01 22:19:46 +08:00
|
|
|
|
UpdateResultView(null);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2014-01-11 15:02:17 +08:00
|
|
|
|
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);
|
2014-01-11 15:02:17 +08:00
|
|
|
|
}
|
|
|
|
|
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)
|
2014-01-11 15:02:17 +08:00
|
|
|
|
{
|
|
|
|
|
throw;
|
2014-01-03 23:52:36 +08:00
|
|
|
|
}
|
2014-01-11 15:02:17 +08:00
|
|
|
|
#endif
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
2014-01-03 18:16:05 +08:00
|
|
|
|
}
|
|
|
|
|
}
|