Temp fix for #667 by add wox.py to PYTHONPATH

This commit is contained in:
bao-qian
2016-06-22 00:42:24 +01:00
parent 4b31f40026
commit a8869c46b8
7 changed files with 35 additions and 115 deletions

View File

@@ -20,6 +20,7 @@ namespace Wox.Core.Plugin
internal abstract class JsonRPCPlugin : IPlugin
{
protected PluginInitContext context;
public const string JsonRPC = "JsonRPC";
/// <summary>
/// The language this JsonRPCPlugin support

View File

@@ -34,7 +34,7 @@ namespace Wox.Core.Plugin
return;
}
string pluginFolerPath = Infrastructure.Constant.UserDirectory;
string pluginFolerPath = Infrastructure.Constant.PluginsDirectory;
string newPluginName = plugin.Name
.Replace("/", "_")

View File

@@ -33,13 +33,27 @@ namespace Wox.Core.Plugin
// todo happlebao, this should not be public, the indicator function should be embeded
public static PluginsSettings Settings;
private static List<PluginMetadata> _metadatas;
private static readonly string[] Directories = { Constant.PreinstalledDirectory, Constant.UserDirectory };
private static readonly string[] Directories = { Constant.PreinstalledDirectory, Constant.PluginsDirectory };
private static void ValidateUserDirectory()
{
if (!Directory.Exists(Constant.UserDirectory))
if (!Directory.Exists(Constant.PluginsDirectory))
{
Directory.CreateDirectory(Constant.UserDirectory);
Directory.CreateDirectory(Constant.PluginsDirectory);
}
}
private static void DeletePythonBinding()
{
const string binding = "wox.py";
var directory = Constant.PluginsDirectory;
foreach (var subDirectory in Directory.GetDirectories(directory))
{
var path = Path.Combine(subDirectory, binding);
if (File.Exists(path))
{
File.Delete(path);
}
}
}
@@ -55,7 +69,8 @@ namespace Wox.Core.Plugin
static PluginManager()
{
ValidateUserDirectory();
// force old plugins use new python binding
DeletePythonBinding();
}
/// <summary>

View File

@@ -1,5 +1,7 @@
using System;
using System.Diagnostics;
using System.IO;
using Wox.Infrastructure;
using Wox.Plugin;
namespace Wox.Core.Plugin
@@ -17,8 +19,13 @@ namespace Wox.Core.Plugin
UseShellExecute = false,
CreateNoWindow = true,
RedirectStandardOutput = true,
RedirectStandardError = true
RedirectStandardError = true,
};
// temp fix for issue #667
var path = Path.Combine(Constant.ProgramDirectory, JsonRPC);
_startInfo.EnvironmentVariables["PYTHONPATH"] = path;
}
protected override string ExecuteQuery(Query query)
@@ -30,6 +37,8 @@ namespace Wox.Core.Plugin
};
//Add -B flag to tell python don't write .py[co] files. Because .pyc contains location infos which will prevent python portable
_startInfo.Arguments = $"-B \"{context.CurrentPluginMetadata.ExecuteFilePath}\" \"{request}\"";
// todo happlebao why context can't be used in constructor
_startInfo.WorkingDirectory = context.CurrentPluginMetadata.PluginDirectory;
return Execute(_startInfo);
}
@@ -37,6 +46,7 @@ namespace Wox.Core.Plugin
protected override string ExecuteCallback(JsonRPCRequestModel rpcRequest)
{
_startInfo.Arguments = $"-B \"{context.CurrentPluginMetadata.ExecuteFilePath}\" \"{rpcRequest}\"";
_startInfo.WorkingDirectory = context.CurrentPluginMetadata.PluginDirectory;
return Execute(_startInfo);
}
}