mirror of
https://github.com/microsoft/PowerToys.git
synced 2026-04-06 03:07:04 +02:00
Add v2ex python plugin demo.
This commit is contained in:
@@ -5,8 +5,8 @@ using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using Newtonsoft.Json;
|
||||
using Wox.JsonRPC;
|
||||
using Wox.Plugin;
|
||||
using Wox.RPC;
|
||||
|
||||
namespace Wox.PluginLoader
|
||||
{
|
||||
@@ -14,7 +14,7 @@ namespace Wox.PluginLoader
|
||||
{
|
||||
protected PluginInitContext context;
|
||||
|
||||
public abstract List<string> GetAllowedLanguages();
|
||||
public abstract string SupportedLanguage { get; }
|
||||
|
||||
protected abstract string ExecuteQuery(Query query);
|
||||
protected abstract string ExecuteAction(JsonRPCRequestModel rpcRequest);
|
||||
|
||||
@@ -3,7 +3,6 @@ using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using Wox.Plugin;
|
||||
using Wox.RPC;
|
||||
|
||||
namespace Wox.PluginLoader
|
||||
{
|
||||
@@ -11,22 +10,14 @@ namespace Wox.PluginLoader
|
||||
{
|
||||
public virtual List<PluginPair> LoadPlugin(List<PluginMetadata> pluginMetadatas)
|
||||
{
|
||||
List<PluginPair> plugins = new List<PluginPair>();
|
||||
|
||||
T pluginWrapper = new T();
|
||||
List<string> allowedLanguages = pluginWrapper.GetAllowedLanguages();
|
||||
List<PluginMetadata> metadatas = pluginMetadatas.Where(o => allowedLanguages.Contains(o.Language.ToUpper())).ToList();
|
||||
foreach (PluginMetadata metadata in metadatas)
|
||||
{
|
||||
PluginPair pair = new PluginPair()
|
||||
{
|
||||
Plugin = pluginWrapper,
|
||||
Metadata = metadata
|
||||
};
|
||||
plugins.Add(pair);
|
||||
}
|
||||
List<PluginMetadata> metadatas = pluginMetadatas.Where(o => pluginWrapper.SupportedLanguage.ToUpper() == o.Language.ToUpper()).ToList();
|
||||
|
||||
return plugins;
|
||||
return metadatas.Select(metadata => new PluginPair()
|
||||
{
|
||||
Plugin = pluginWrapper,
|
||||
Metadata = metadata
|
||||
}).ToList();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using Wox.JsonRPC;
|
||||
using Wox.Plugin;
|
||||
using Wox.RPC;
|
||||
|
||||
namespace Wox.PluginLoader
|
||||
{
|
||||
@@ -9,27 +9,24 @@ namespace Wox.PluginLoader
|
||||
{
|
||||
private static string woxDirectory = Path.GetDirectoryName(System.Windows.Forms.Application.ExecutablePath);
|
||||
|
||||
public override List<string> GetAllowedLanguages()
|
||||
public override string SupportedLanguage
|
||||
{
|
||||
return new List<string>()
|
||||
{
|
||||
AllowedLanguage.Python
|
||||
};
|
||||
get { return AllowedLanguage.Python; }
|
||||
}
|
||||
|
||||
protected override string ExecuteQuery(Query query)
|
||||
{
|
||||
string fileName = Path.Combine(woxDirectory, "PythonHome\\pythonw.exe");
|
||||
string parameters = string.Format("{0} \"{1}\"", context.CurrentPluginMetadata.ExecuteFilePath,
|
||||
JsonRPC.Send("query", query.GetAllRemainingParameter()));
|
||||
string.Format(@"{{\""method\"": \""query\"", \""parameters\"": \""{0}\""}}",query.GetAllRemainingParameter()));
|
||||
|
||||
return Execute(fileName, parameters);
|
||||
}
|
||||
|
||||
protected override string ExecuteAction(JsonRPCRequestModel rpcRequest)
|
||||
{
|
||||
string fileName = Path.Combine(woxDirectory, "PythonHome\\pythonw.exe");
|
||||
string parameters = string.Format("{0} \"{1}\"", context.CurrentPluginMetadata.ExecuteFilePath,
|
||||
rpcRequest.ToString());
|
||||
string parameters = string.Format("{0} \"{1}\"", context.CurrentPluginMetadata.ExecuteFilePath,rpcRequest);
|
||||
return Execute(fileName, parameters);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user