From de12208d4afe843ce0bc214d2041d2158085bc81 Mon Sep 17 00:00:00 2001 From: Michael Eichhorn Date: Tue, 11 Apr 2017 14:25:25 +0100 Subject: [PATCH 1/7] ContextMenu 1: Rename #1366 --- Wox.Core/Plugin/JsonPRCModel.cs | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/Wox.Core/Plugin/JsonPRCModel.cs b/Wox.Core/Plugin/JsonPRCModel.cs index e513f3d307..3a0253e559 100644 --- a/Wox.Core/Plugin/JsonPRCModel.cs +++ b/Wox.Core/Plugin/JsonPRCModel.cs @@ -56,7 +56,7 @@ namespace Wox.Core.Plugin string rpc = string.Empty; if (Parameters != null && Parameters.Length > 0) { - string parameters = Parameters.Aggregate("[", (current, o) => current + (GetParamterByType(o) + ",")); + string parameters = Parameters.Aggregate("[", (current, o) => current + (GetParameterByType(o) + ",")); parameters = parameters.Substring(0, parameters.Length - 1) + "]"; rpc = string.Format(@"{{\""method\"":\""{0}\"",\""parameters\"":{1}", Method, parameters); } @@ -69,25 +69,27 @@ namespace Wox.Core.Plugin } - private string GetParamterByType(object paramter) + private string GetParameterByType(object parameter) { - - if (paramter is string) - { - return string.Format(@"\""{0}\""", RepalceEscapes(paramter.ToString())); + if (parameter == null) { + return "null"; } - if (paramter is int || paramter is float || paramter is double) + if (parameter is string) { - return string.Format(@"{0}", paramter); + return string.Format(@"\""{0}\""", ReplaceEscapes(parameter.ToString())); } - if (paramter is bool) + if (parameter is int || parameter is float || parameter is double) { - return string.Format(@"{0}", paramter.ToString().ToLower()); + return string.Format(@"{0}", parameter); } - return paramter.ToString(); + if (parameter is bool) + { + return string.Format(@"{0}", parameter.ToString().ToLower()); + } + return parameter.ToString(); } - private string RepalceEscapes(string str) + private string ReplaceEscapes(string str) { return str.Replace(@"\", @"\\") //Escapes in ProcessStartInfo .Replace(@"\", @"\\") //Escapes itself when passed to client From 5198f70ebf5f6cf994585c78220b0517c393dc03 Mon Sep 17 00:00:00 2001 From: Michael Eichhorn Date: Tue, 11 Apr 2017 14:31:50 +0100 Subject: [PATCH 2/7] ContextMenu 2: Extract DeserializedResult #1366 --- Wox.Core/Plugin/JsonRPCPlugin.cs | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/Wox.Core/Plugin/JsonRPCPlugin.cs b/Wox.Core/Plugin/JsonRPCPlugin.cs index 2855fa1d1c..8ba7db5c1e 100644 --- a/Wox.Core/Plugin/JsonRPCPlugin.cs +++ b/Wox.Core/Plugin/JsonRPCPlugin.cs @@ -33,10 +33,21 @@ namespace Wox.Core.Plugin public List Query(Query query) { string output = ExecuteQuery(query); + try + { + return DeserializedResult(output); + } + catch (Exception e) + { + Log.Exception($"|JsonRPCPlugin.Query|Exception when query <{query}>", e); + return null; + } + } + + public List DeserializedResult(string output) + { if (!String.IsNullOrEmpty(output)) { - try - { List results = new List(); JsonRPCQueryResponseModel queryResponseModel = JsonConvert.DeserializeObject(output); @@ -72,15 +83,11 @@ namespace Wox.Core.Plugin results.Add(result); } return results; - } - catch (Exception e) - { - Log.Exception($"|JsonRPCPlugin.Query|Exception when query <{query}>", e); - } } return null; } + private void ExecuteWoxAPI(string method, object[] parameters) { MethodInfo methodInfo = PluginManager.API.GetType().GetMethod(method); From f3d79d906e0e9c0383029efdd557228f8997e7a6 Mon Sep 17 00:00:00 2001 From: Michael Eichhorn Date: Tue, 11 Apr 2017 14:32:51 +0100 Subject: [PATCH 3/7] ContextMenu 3: Format #1366 --- Wox.Core/Plugin/JsonRPCPlugin.cs | 56 ++++++++++++++++---------------- 1 file changed, 28 insertions(+), 28 deletions(-) diff --git a/Wox.Core/Plugin/JsonRPCPlugin.cs b/Wox.Core/Plugin/JsonRPCPlugin.cs index 8ba7db5c1e..7dec0084f5 100644 --- a/Wox.Core/Plugin/JsonRPCPlugin.cs +++ b/Wox.Core/Plugin/JsonRPCPlugin.cs @@ -48,41 +48,41 @@ namespace Wox.Core.Plugin { if (!String.IsNullOrEmpty(output)) { - List results = new List(); + List results = new List(); - JsonRPCQueryResponseModel queryResponseModel = JsonConvert.DeserializeObject(output); - if (queryResponseModel.Result == null) return null; + JsonRPCQueryResponseModel queryResponseModel = JsonConvert.DeserializeObject(output); + if (queryResponseModel.Result == null) return null; - foreach (JsonRPCResult result in queryResponseModel.Result) + foreach (JsonRPCResult result in queryResponseModel.Result) + { + JsonRPCResult result1 = result; + result.Action = c => { - JsonRPCResult result1 = result; - result.Action = c => - { - if (result1.JsonRPCAction == null) return false; + if (result1.JsonRPCAction == null) return false; - if (!String.IsNullOrEmpty(result1.JsonRPCAction.Method)) + if (!String.IsNullOrEmpty(result1.JsonRPCAction.Method)) + { + if (result1.JsonRPCAction.Method.StartsWith("Wox.")) { - if (result1.JsonRPCAction.Method.StartsWith("Wox.")) + ExecuteWoxAPI(result1.JsonRPCAction.Method.Substring(4), result1.JsonRPCAction.Parameters); + } + else + { + string actionReponse = ExecuteCallback(result1.JsonRPCAction); + JsonRPCRequestModel jsonRpcRequestModel = JsonConvert.DeserializeObject(actionReponse); + if (jsonRpcRequestModel != null + && !String.IsNullOrEmpty(jsonRpcRequestModel.Method) + && jsonRpcRequestModel.Method.StartsWith("Wox.")) { - ExecuteWoxAPI(result1.JsonRPCAction.Method.Substring(4), result1.JsonRPCAction.Parameters); - } - else - { - string actionReponse = ExecuteCallback(result1.JsonRPCAction); - JsonRPCRequestModel jsonRpcRequestModel = JsonConvert.DeserializeObject(actionReponse); - if (jsonRpcRequestModel != null - && !String.IsNullOrEmpty(jsonRpcRequestModel.Method) - && jsonRpcRequestModel.Method.StartsWith("Wox.")) - { - ExecuteWoxAPI(jsonRpcRequestModel.Method.Substring(4), jsonRpcRequestModel.Parameters); - } + ExecuteWoxAPI(jsonRpcRequestModel.Method.Substring(4), jsonRpcRequestModel.Parameters); } } - return !result1.JsonRPCAction.DontHideAfterAction; - }; - results.Add(result); - } - return results; + } + return !result1.JsonRPCAction.DontHideAfterAction; + }; + results.Add(result); + } + return results; } return null; } @@ -156,7 +156,7 @@ namespace Wox.Core.Plugin } else if (result.StartsWith("DEBUG:")) { - MessageBox.Show(new Form {TopMost = true}, result.Substring(6)); + MessageBox.Show(new Form { TopMost = true }, result.Substring(6)); return string.Empty; } else From 5640b2157f2789cfeb226905a4b5312fe48ae358 Mon Sep 17 00:00:00 2001 From: Michael Eichhorn Date: Tue, 11 Apr 2017 14:34:04 +0100 Subject: [PATCH 4/7] ContextMenu 4: for non c# plugin #1366 --- JsonRPC/wox.py | 11 +++++++++-- Plugins/HelloWorldPython/main.py | 12 +++++++++++- Wox.Core/Plugin/ExecutablePlugin.cs | 11 +++++++++++ Wox.Core/Plugin/JsonRPCPlugin.cs | 27 ++++++++++++++++++++++----- Wox.Core/Plugin/PythonPlugin.cs | 11 +++++++++++ 5 files changed, 64 insertions(+), 8 deletions(-) diff --git a/JsonRPC/wox.py b/JsonRPC/wox.py index f6f3c9eb87..2e65a629d6 100644 --- a/JsonRPC/wox.py +++ b/JsonRPC/wox.py @@ -12,14 +12,15 @@ class Wox(object): def __init__(self): rpc_request = json.loads(sys.argv[1]) # proxy is not working now - self.proxy = rpc_request.get("proxy",{}) + 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": + + if request_method_name == "query" or request_method_name == "context_menu": print(json.dumps({"result": results})) def query(self,query): @@ -28,6 +29,12 @@ class Wox(object): """ return [] + def context_menu(self, data): + """ + optional context menu entries for a result + """ + return [] + def debug(self,msg): """ alert msg diff --git a/Plugins/HelloWorldPython/main.py b/Plugins/HelloWorldPython/main.py index e2f54050a7..e7b7edfc24 100644 --- a/Plugins/HelloWorldPython/main.py +++ b/Plugins/HelloWorldPython/main.py @@ -8,7 +8,17 @@ class HelloWorld(Wox): results = [] results.append({ "Title": "Hello World", - "SubTitle": "Query: {}".format(query), + "SubTitle": "Query: {}".format(query), + "IcoPath":"Images/app.ico", + "ContextData": "ctxData" + }) + return results + + def context_menu(self, data): + results = [] + results.append({ + "Title": "Context menu entry", + "SubTitle": "Data: {}".format(data), "IcoPath":"Images/app.ico" }) return results diff --git a/Wox.Core/Plugin/ExecutablePlugin.cs b/Wox.Core/Plugin/ExecutablePlugin.cs index 43992095eb..2753b00b3a 100644 --- a/Wox.Core/Plugin/ExecutablePlugin.cs +++ b/Wox.Core/Plugin/ExecutablePlugin.cs @@ -39,5 +39,16 @@ namespace Wox.Core.Plugin _startInfo.Arguments = $"\"{rpcRequest}\""; return Execute(_startInfo); } + + protected override string ExecuteContextMenu(Result selectedResult) { + JsonRPCServerRequestModel request = new JsonRPCServerRequestModel { + Method = "contextmenu", + Parameters = new object[] { selectedResult.ContextData }, + }; + + _startInfo.Arguments = $"\"{request}\""; + + return Execute(_startInfo); + } } } \ No newline at end of file diff --git a/Wox.Core/Plugin/JsonRPCPlugin.cs b/Wox.Core/Plugin/JsonRPCPlugin.cs index 7dec0084f5..5057ae472b 100644 --- a/Wox.Core/Plugin/JsonRPCPlugin.cs +++ b/Wox.Core/Plugin/JsonRPCPlugin.cs @@ -17,7 +17,7 @@ namespace Wox.Core.Plugin /// Represent the plugin that using JsonPRC /// every JsonRPC plugin should has its own plugin instance /// - internal abstract class JsonRPCPlugin : IPlugin + internal abstract class JsonRPCPlugin : IPlugin, IContextMenu { protected PluginInitContext context; public const string JsonRPC = "JsonRPC"; @@ -29,6 +29,7 @@ namespace Wox.Core.Plugin protected abstract string ExecuteQuery(Query query); protected abstract string ExecuteCallback(JsonRPCRequestModel rpcRequest); + protected abstract string ExecuteContextMenu(Result selectedResult); public List Query(Query query) { @@ -44,7 +45,21 @@ namespace Wox.Core.Plugin } } - public List DeserializedResult(string output) + public List LoadContextMenus(Result selectedResult) + { + string output = ExecuteContextMenu(selectedResult); + try + { + return DeserializedResult(output); + } + catch (Exception e) + { + Log.Exception($"|JsonRPCPlugin.LoadContextMenus|Exception on result <{selectedResult}>", e); + return null; + } + } + + private List DeserializedResult(string output) { if (!String.IsNullOrEmpty(output)) { @@ -84,10 +99,12 @@ namespace Wox.Core.Plugin } return results; } - return null; + else + { + return null; + } } - private void ExecuteWoxAPI(string method, object[] parameters) { MethodInfo methodInfo = PluginManager.API.GetType().GetMethod(method); @@ -184,4 +201,4 @@ namespace Wox.Core.Plugin context = ctx; } } -} +} \ No newline at end of file diff --git a/Wox.Core/Plugin/PythonPlugin.cs b/Wox.Core/Plugin/PythonPlugin.cs index 5664d354ce..95a7d863e6 100644 --- a/Wox.Core/Plugin/PythonPlugin.cs +++ b/Wox.Core/Plugin/PythonPlugin.cs @@ -49,5 +49,16 @@ namespace Wox.Core.Plugin _startInfo.WorkingDirectory = context.CurrentPluginMetadata.PluginDirectory; return Execute(_startInfo); } + + protected override string ExecuteContextMenu(Result selectedResult) { + JsonRPCServerRequestModel request = new JsonRPCServerRequestModel { + Method = "context_menu", + Parameters = new object[] { selectedResult.ContextData }, + }; + _startInfo.Arguments = $"-B \"{context.CurrentPluginMetadata.ExecuteFilePath}\" \"{request}\""; + _startInfo.WorkingDirectory = context.CurrentPluginMetadata.PluginDirectory; + + return Execute(_startInfo); + } } } \ No newline at end of file From 808523b814ddbb82c6ac13f1da697342bc29b6a0 Mon Sep 17 00:00:00 2001 From: LiuJianhua Date: Wed, 8 Mar 2017 09:44:04 +0800 Subject: [PATCH 5/7] Fix folder UnauthorizedAccessException #1282 #1357 --- Plugins/Wox.Plugin.Program/Programs/Win32.cs | 29 ++++++++++++-------- 1 file changed, 17 insertions(+), 12 deletions(-) diff --git a/Plugins/Wox.Plugin.Program/Programs/Win32.cs b/Plugins/Wox.Plugin.Program/Programs/Win32.cs index 3a3414500c..1c4fd09e7a 100644 --- a/Plugins/Wox.Plugin.Program/Programs/Win32.cs +++ b/Plugins/Wox.Plugin.Program/Programs/Win32.cs @@ -204,25 +204,30 @@ namespace Wox.Plugin.Program.Programs private static IEnumerable ProgramPaths(string directory, string[] suffixes) { - if (Directory.Exists(directory)) + if (!Directory.Exists(directory)) + return new string[] { }; + + var ds = Directory.GetDirectories(directory); + + var paths = ds.SelectMany(d => { - IEnumerable files; try { - files = Directory.EnumerateFiles(directory, "*", SearchOption.AllDirectories); + var paths_for_suffixes = suffixes.SelectMany(s => + { + var pattern = $"*.{s}"; + var ps = Directory.EnumerateFiles(d, pattern, SearchOption.AllDirectories); + return ps; + }); + return paths_for_suffixes; } catch (Exception e) when (e is SecurityException || e is UnauthorizedAccessException) { - Log.Exception($"|Program.Win32.ProgramPaths|Can't parse directory <{directory}>", e); - return new string[] { }; + Log.Exception($"|Program.Win32.ProgramPaths|Don't have permission on <{directory}>", e); + return new List(); } - files = files.Where(f => suffixes.Contains(Extension(f))); - return files; - } - else - { - return new string[] { }; - } + }); + return paths; } private static string Extension(string path) From fd4fec534030142180d5effad8859994a5fcdc57 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?H=C3=BCseyin=20T=C3=BCfek=C3=A7ilerli?= Date: Tue, 11 Apr 2017 17:43:10 +0300 Subject: [PATCH 6/7] Removed extra leading space char (#1368) --- Wox.Core/Plugin/PluginInstaller.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Wox.Core/Plugin/PluginInstaller.cs b/Wox.Core/Plugin/PluginInstaller.cs index 5f17fc3b55..ffdb0aa758 100644 --- a/Wox.Core/Plugin/PluginInstaller.cs +++ b/Wox.Core/Plugin/PluginInstaller.cs @@ -83,7 +83,7 @@ namespace Wox.Core.Plugin // Plugins.Initialize(); //} if (MessageBox.Show($"You have installed plugin {plugin.Name} successfully.{Environment.NewLine}" + - " Restart Wox to take effect?", + "Restart Wox to take effect?", "Install plugin", MessageBoxButton.YesNo, MessageBoxImage.Question) == MessageBoxResult.Yes) { PluginManager.API.RestarApp(); From 8a0f80181e92c9e71a687d27df53d6cd9649b633 Mon Sep 17 00:00:00 2001 From: bao-qian Date: Sun, 23 Apr 2017 23:33:53 +0100 Subject: [PATCH 7/7] Notes for maintenance --- README.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/README.md b/README.md index 79a7b382f3..2fdc874fac 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,7 @@ +NOTE +==== +This project will not be maintained by @happlebao for about 2 month due to personal reason. + WoX ===