mirror of
https://github.com/microsoft/PowerToys.git
synced 2026-04-06 03:07:04 +02:00
Refactoring [WIP]
This commit is contained in:
@@ -7,9 +7,9 @@ using Wox.RPC;
|
||||
|
||||
namespace Wox.PluginLoader
|
||||
{
|
||||
public class BasePluginLoader<T> where T :BasePluginWrapper,new()
|
||||
public class BasePluginLoader<T> : IPluginLoader where T : BasePluginWrapper, new()
|
||||
{
|
||||
public List<PluginPair> LoadPlugin(List<PluginMetadata> pluginMetadatas)
|
||||
public virtual List<PluginPair> LoadPlugin(List<PluginMetadata> pluginMetadatas)
|
||||
{
|
||||
List<PluginPair> plugins = new List<PluginPair>();
|
||||
|
||||
|
||||
@@ -15,33 +15,27 @@ namespace Wox.PluginLoader
|
||||
protected PluginInitContext context;
|
||||
|
||||
public abstract List<string> GetAllowedLanguages();
|
||||
protected abstract string GetFileName();
|
||||
|
||||
protected abstract string GetQueryArguments(Query query);
|
||||
|
||||
protected abstract string GetActionJsonRPCArguments(ActionJsonRPCResult result);
|
||||
protected abstract string ExecuteQuery(Query query);
|
||||
protected abstract string ExecuteAction(string rpcRequest);
|
||||
|
||||
public List<Result> Query(Query query)
|
||||
{
|
||||
string fileName = GetFileName();
|
||||
string arguments = GetQueryArguments(query);
|
||||
string output = Execute(fileName, arguments);
|
||||
string output = ExecuteQuery(query);
|
||||
if (!string.IsNullOrEmpty(output))
|
||||
{
|
||||
try
|
||||
{
|
||||
JsonPRCModel rpc = JsonConvert.DeserializeObject<JsonPRCModel>(output);
|
||||
List<ActionJsonRPCResult> rpcresults =
|
||||
JsonConvert.DeserializeObject<List<ActionJsonRPCResult>>(rpc.result);
|
||||
List<Result> results = new List<Result>();
|
||||
foreach (ActionJsonRPCResult result in rpcresults)
|
||||
|
||||
JsonRPCQueryResponseModel queryResponseModel = JsonConvert.DeserializeObject<JsonRPCQueryResponseModel>(output);
|
||||
foreach (JsonRPCResult result in queryResponseModel.QueryResults)
|
||||
{
|
||||
if (!string.IsNullOrEmpty(result.ActionJSONRPC))
|
||||
if (result.JSONRPCActionModel != null)
|
||||
{
|
||||
ActionJsonRPCResult resultCopy = result;
|
||||
result.Action = (c) =>
|
||||
{
|
||||
Execute(fileName, GetActionJsonRPCArguments(resultCopy));
|
||||
ExecuteAction(result.JSONRPCAction);
|
||||
return true;
|
||||
};
|
||||
}
|
||||
@@ -56,7 +50,13 @@ namespace Wox.PluginLoader
|
||||
return null;
|
||||
}
|
||||
|
||||
private string Execute(string fileName, string arguments)
|
||||
/// <summary>
|
||||
/// Execute external program and return the output
|
||||
/// </summary>
|
||||
/// <param name="fileName"></param>
|
||||
/// <param name="arguments"></param>
|
||||
/// <returns></returns>
|
||||
protected string Execute(string fileName, string arguments)
|
||||
{
|
||||
try
|
||||
{
|
||||
|
||||
@@ -8,7 +8,7 @@ using Wox.Plugin.SystemPlugins;
|
||||
|
||||
namespace Wox.PluginLoader {
|
||||
|
||||
public class CSharpPluginConfigLoader
|
||||
public class CSharpPluginConfigLoader : IPluginLoader
|
||||
{
|
||||
public List<PluginPair> LoadPlugin(List<PluginMetadata> pluginMetadatas)
|
||||
{
|
||||
|
||||
13
Wox/PluginLoader/IPluginLoader.cs
Normal file
13
Wox/PluginLoader/IPluginLoader.cs
Normal file
@@ -0,0 +1,13 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using Wox.Plugin;
|
||||
|
||||
namespace Wox.PluginLoader
|
||||
{
|
||||
public interface IPluginLoader
|
||||
{
|
||||
List<PluginPair> LoadPlugin(List<PluginMetadata> pluginMetadatas);
|
||||
}
|
||||
}
|
||||
@@ -1,11 +1,6 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Threading;
|
||||
using Python.Runtime;
|
||||
using Wox.Plugin;
|
||||
using Wox.Helper;
|
||||
using Wox.RPC;
|
||||
|
||||
namespace Wox.PluginLoader
|
||||
@@ -22,22 +17,20 @@ namespace Wox.PluginLoader
|
||||
};
|
||||
}
|
||||
|
||||
protected override string GetFileName()
|
||||
protected override string ExecuteQuery(Query query)
|
||||
{
|
||||
return Path.Combine(woxDirectory, "PYTHONTHOME\\Scripts\\python.exe");
|
||||
string fileName = Path.Combine(woxDirectory, "PYTHONTHOME\\Scripts\\python.exe");
|
||||
string parameters = string.Format("{0} \"{1}\"", context.CurrentPluginMetadata.ExecuteFilePath,
|
||||
JsonRPC.Send("query", query.GetAllRemainingParameter()));
|
||||
return Execute(fileName, parameters);
|
||||
}
|
||||
|
||||
protected override string GetQueryArguments(Query query)
|
||||
protected override string ExecuteAction(string rpcRequest)
|
||||
{
|
||||
return string.Format("{0} \"{1}\"",
|
||||
context.CurrentPluginMetadata.ExecuteFilePath,
|
||||
JsonRPC.GetRPC("query", query.GetAllRemainingParameter()));
|
||||
}
|
||||
|
||||
protected override string GetActionJsonRPCArguments(ActionJsonRPCResult result)
|
||||
{
|
||||
return string.Format("{0} \"{1}\"", context.CurrentPluginMetadata.ExecuteFilePath,
|
||||
result.ActionJSONRPC);
|
||||
string fileName = Path.Combine(woxDirectory, "PYTHONTHOME\\Scripts\\python.exe");
|
||||
string parameters = string.Format("{0} \"{1}\"", context.CurrentPluginMetadata.ExecuteFilePath,
|
||||
rpcRequest);
|
||||
return Execute(fileName, parameters);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user