mirror of
https://github.com/microsoft/PowerToys.git
synced 2026-04-06 19:26:39 +02:00
Refactoring.
This commit is contained in:
7
Wox.Core/Plugin/QueryDispatcher/IQueryDispatcher.cs
Normal file
7
Wox.Core/Plugin/QueryDispatcher/IQueryDispatcher.cs
Normal file
@@ -0,0 +1,7 @@
|
||||
namespace Wox.Core.Plugin.QueryDispatcher
|
||||
{
|
||||
internal interface IQueryDispatcher
|
||||
{
|
||||
void Dispatch(Wox.Plugin.Query query);
|
||||
}
|
||||
}
|
||||
21
Wox.Core/Plugin/QueryDispatcher/QueryDispatcher.cs
Normal file
21
Wox.Core/Plugin/QueryDispatcher/QueryDispatcher.cs
Normal file
@@ -0,0 +1,21 @@
|
||||
|
||||
namespace Wox.Core.Plugin.QueryDispatcher
|
||||
{
|
||||
internal static class QueryDispatcher
|
||||
{
|
||||
private static IQueryDispatcher pluginCmd = new UserPluginQueryDispatcher();
|
||||
private static IQueryDispatcher systemCmd = new SystemPluginQueryDispatcher();
|
||||
|
||||
public static void Dispatch(Wox.Plugin.Query query)
|
||||
{
|
||||
if (PluginManager.IsUserPluginQuery(query))
|
||||
{
|
||||
pluginCmd.Dispatch(query);
|
||||
}
|
||||
else
|
||||
{
|
||||
systemCmd.Dispatch(query);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading;
|
||||
using Wox.Infrastructure.Storage.UserSettings;
|
||||
using Wox.Plugin;
|
||||
using Wox.Plugin.SystemPlugins;
|
||||
|
||||
namespace Wox.Core.Plugin.QueryDispatcher
|
||||
{
|
||||
public class SystemPluginQueryDispatcher : IQueryDispatcher
|
||||
{
|
||||
private IEnumerable<PluginPair> allSytemPlugins = PluginManager.AllPlugins.Where(o => o.Metadata.PluginType == PluginType.System);
|
||||
|
||||
public void Dispatch(Query query)
|
||||
{
|
||||
var queryPlugins = allSytemPlugins;
|
||||
if (UserSettingStorage.Instance.WebSearches.Exists(o => o.ActionWord == query.ActionName && o.Enabled))
|
||||
{
|
||||
//websearch mode
|
||||
queryPlugins = new List<PluginPair>()
|
||||
{
|
||||
allSytemPlugins.First(o => ((ISystemPlugin)o.Plugin).ID == "565B73353DBF4806919830B9202EE3BF")
|
||||
};
|
||||
}
|
||||
|
||||
foreach (PluginPair pair in queryPlugins)
|
||||
{
|
||||
PluginPair pair1 = pair;
|
||||
ThreadPool.QueueUserWorkItem(state =>
|
||||
{
|
||||
List<Result> results = pair1.Plugin.Query(query);
|
||||
results.ForEach(o => { o.AutoAjustScore = true; });
|
||||
|
||||
PluginManager.API.PushResults(query, pair1.Metadata, results);
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
47
Wox.Core/Plugin/QueryDispatcher/UserPluginQueryDispatcher.cs
Normal file
47
Wox.Core/Plugin/QueryDispatcher/UserPluginQueryDispatcher.cs
Normal file
@@ -0,0 +1,47 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading;
|
||||
using Wox.Infrastructure.Logger;
|
||||
using Wox.Infrastructure.Storage.UserSettings;
|
||||
using Wox.Plugin;
|
||||
|
||||
namespace Wox.Core.Plugin.QueryDispatcher
|
||||
{
|
||||
public class UserPluginQueryDispatcher : IQueryDispatcher
|
||||
{
|
||||
public void Dispatch(Query query)
|
||||
{
|
||||
PluginPair userPlugin = PluginManager.AllPlugins.FirstOrDefault(o => o.Metadata.ActionKeyword == query.ActionName);
|
||||
if (userPlugin != null && !string.IsNullOrEmpty(userPlugin.Metadata.ActionKeyword))
|
||||
{
|
||||
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();
|
||||
return;
|
||||
}
|
||||
|
||||
ThreadPool.QueueUserWorkItem(t =>
|
||||
{
|
||||
try
|
||||
{
|
||||
List<Result> results = userPlugin.Plugin.Query(query) ?? new List<Result>();
|
||||
PluginManager.API.PushResults(query,userPlugin.Metadata,results);
|
||||
}
|
||||
catch (Exception queryException)
|
||||
{
|
||||
Log.Error(string.Format("Plugin {0} query failed: {1}", userPlugin.Metadata.Name,
|
||||
queryException.Message));
|
||||
#if (DEBUG)
|
||||
{
|
||||
throw;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user