mirror of
https://github.com/microsoft/PowerToys.git
synced 2024-12-13 19:19:23 +08:00
ContextMenu 4: for non c# plugin #1366
This commit is contained in:
parent
f3d79d906e
commit
5640b2157f
@ -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
|
||||
|
@ -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
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
@ -17,7 +17,7 @@ namespace Wox.Core.Plugin
|
||||
/// Represent the plugin that using JsonPRC
|
||||
/// every JsonRPC plugin should has its own plugin instance
|
||||
/// </summary>
|
||||
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<Result> Query(Query query)
|
||||
{
|
||||
@ -44,7 +45,21 @@ namespace Wox.Core.Plugin
|
||||
}
|
||||
}
|
||||
|
||||
public List<Result> DeserializedResult(string output)
|
||||
public List<Result> 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<Result> 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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user