From a8869c46b8af0f120a1f86dc309bee6eb7b30e50 Mon Sep 17 00:00:00 2001 From: bao-qian Date: Wed, 22 Jun 2016 00:42:24 +0100 Subject: [PATCH] Temp fix for #667 by add wox.py to PYTHONPATH --- Plugins/HelloWorldPython/wox.py | 107 ----------------------------- Wox.Core/Plugin/JsonRPCPlugin.cs | 1 + Wox.Core/Plugin/PluginInstaller.cs | 2 +- Wox.Core/Plugin/PluginManager.cs | 23 +++++-- Wox.Core/Plugin/PythonPlugin.cs | 12 +++- Wox.Infrastructure/Wox.cs | 2 +- Wox/Wox.csproj | 3 +- 7 files changed, 35 insertions(+), 115 deletions(-) delete mode 100644 Plugins/HelloWorldPython/wox.py diff --git a/Plugins/HelloWorldPython/wox.py b/Plugins/HelloWorldPython/wox.py deleted file mode 100644 index 084eac8eb2..0000000000 --- a/Plugins/HelloWorldPython/wox.py +++ /dev/null @@ -1,107 +0,0 @@ -# -*- coding: utf-8 -*- -from __future__ import print_function -import json -import sys -import inspect - -class Wox(object): - """ - Wox python plugin base - """ - - def __init__(self): - rpc_request = json.loads(sys.argv[1]) - self.proxy = rpc_request.get("proxy",{}) - request_method_name = rpc_request.get("method") - request_parameters = rpc_request.get("parameters") - methods = inspect.getmembers(self, predicate=inspect.ismethod) - - request_method = dict(methods)[request_method_name] - results = request_method(*request_parameters) - if request_method_name == "query": - print(json.dumps({"result": results})) - - def query(self,query): - """ - sub class need to override this method - """ - return [] - - def debug(self,msg): - """ - alert msg - """ - print("DEBUG:{}".format(msg)) - sys.exit() - -class WoxAPI(object): - - @classmethod - def change_query(cls,query,requery = False): - """ - change wox query - """ - print(json.dumps({"method": "Wox.ChangeQuery","parameters":[query,requery]})) - - @classmethod - def shell_run(cls,cmd): - """ - run shell commands - """ - print(json.dumps({"method": "Wox.ShellRun","parameters":[cmd]})) - - @classmethod - def close_app(cls): - """ - close wox - """ - print(json.dumps({"method": "Wox.CloseApp","parameters":[]})) - - @classmethod - def hide_app(cls): - """ - hide wox - """ - print(json.dumps({"method": "Wox.HideApp","parameters":[]})) - - @classmethod - def show_app(cls): - """ - show wox - """ - print(json.dumps({"method": "Wox.ShowApp","parameters":[]})) - - @classmethod - def show_msg(cls,title,sub_title,ico_path=""): - """ - show messagebox - """ - print(json.dumps({"method": "Wox.ShowMsg","parameters":[title,sub_title,ico_path]})) - - @classmethod - def open_setting_dialog(cls): - """ - open setting dialog - """ - print(json.dumps({"method": "Wox.OpenSettingDialog","parameters":[]})) - - @classmethod - def start_loadingbar(cls): - """ - start loading animation in wox - """ - print(json.dumps({"method": "Wox.StartLoadingBar","parameters":[]})) - - @classmethod - def stop_loadingbar(cls): - """ - stop loading animation in wox - """ - print(json.dumps({"method": "Wox.StopLoadingBar","parameters":[]})) - - @classmethod - def reload_plugins(cls): - """ - reload all wox plugins - """ - print(json.dumps({"method": "Wox.ReloadPlugins","parameters":[]})) diff --git a/Wox.Core/Plugin/JsonRPCPlugin.cs b/Wox.Core/Plugin/JsonRPCPlugin.cs index 3d7fb006f6..f83278940c 100644 --- a/Wox.Core/Plugin/JsonRPCPlugin.cs +++ b/Wox.Core/Plugin/JsonRPCPlugin.cs @@ -20,6 +20,7 @@ namespace Wox.Core.Plugin internal abstract class JsonRPCPlugin : IPlugin { protected PluginInitContext context; + public const string JsonRPC = "JsonRPC"; /// /// The language this JsonRPCPlugin support diff --git a/Wox.Core/Plugin/PluginInstaller.cs b/Wox.Core/Plugin/PluginInstaller.cs index f16a4556fa..5f17fc3b55 100644 --- a/Wox.Core/Plugin/PluginInstaller.cs +++ b/Wox.Core/Plugin/PluginInstaller.cs @@ -34,7 +34,7 @@ namespace Wox.Core.Plugin return; } - string pluginFolerPath = Infrastructure.Constant.UserDirectory; + string pluginFolerPath = Infrastructure.Constant.PluginsDirectory; string newPluginName = plugin.Name .Replace("/", "_") diff --git a/Wox.Core/Plugin/PluginManager.cs b/Wox.Core/Plugin/PluginManager.cs index 3685efa612..f71d625a38 100644 --- a/Wox.Core/Plugin/PluginManager.cs +++ b/Wox.Core/Plugin/PluginManager.cs @@ -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 _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(); } /// diff --git a/Wox.Core/Plugin/PythonPlugin.cs b/Wox.Core/Plugin/PythonPlugin.cs index e8b1ba20d6..5664d354ce 100644 --- a/Wox.Core/Plugin/PythonPlugin.cs +++ b/Wox.Core/Plugin/PythonPlugin.cs @@ -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); } } diff --git a/Wox.Infrastructure/Wox.cs b/Wox.Infrastructure/Wox.cs index 796ed1e524..4e73c94703 100644 --- a/Wox.Infrastructure/Wox.cs +++ b/Wox.Infrastructure/Wox.cs @@ -15,7 +15,7 @@ namespace Wox.Infrastructure public static readonly string ProgramDirectory = Directory.GetParent(Assembly.Location).ToString(); public static readonly string ExecutablePath = Path.Combine(ProgramDirectory, Wox + ".exe"); public static readonly string DataDirectory = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), Wox); - public static readonly string UserDirectory = Path.Combine(DataDirectory, Plugins); + public static readonly string PluginsDirectory = Path.Combine(DataDirectory, Plugins); public static readonly string PreinstalledDirectory = Path.Combine(ProgramDirectory, Plugins); public static readonly string SettingsPath = Path.Combine(DataDirectory, Settings); public const string Github = "https://github.com/Wox-launcher/Wox"; diff --git a/Wox/Wox.csproj b/Wox/Wox.csproj index 9e89eb61da..4f394fe140 100644 --- a/Wox/Wox.csproj +++ b/Wox/Wox.csproj @@ -422,9 +422,10 @@ -xcopy /Y $(ProjectDir)Themes\* $(TargetDir)Themes\ +xcopy /Y /E $(ProjectDir)Themes\* $(TargetDir)Themes\ xcopy /Y /E $(ProjectDir)Images\* $(TargetDir)Images\ xcopy /Y /D /E $(SolutionDir)Plugins\HelloWorldPython\* $(TargetDir)Plugins\HelloWorldPython\* +xcopy /Y /E $(SolutionDir)JsonRPC\* $(TargetDir)JsonRPC\ cd $(SolutionDir)packages\squirrel*\tools copy /Y Squirrel.exe $(TargetDir)..\Update.exe