-
-
Notifications
You must be signed in to change notification settings - Fork 448
add initial ShellRun support for JsonRPC #742
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Thanks for pull request! It is a missed api. I also agree with we shouldn't have window displayed here. |
Hmm, maybe I'm misunderstanding the Flow -> Plugin interaction, but doesn't the plugin only receive a single string? Or is there a way for Python plugins to receive an event when the user selects/activates one of the results? The For context, the plugin I'm working on that required it is similar to file search, where I want the result opened with the default file handler when the user activates it, so it would be just as easy to launch from Python if those events can be received. |
You can actually. Flow will query again when user click the result, and this time it will go to the method registered in the callback message, and pass the ContextData of the result to the method.
It is just as easy to launch from python actually 🤣 |
I know our document is not quite clear, so if you have encountered any issue, feel free to open a discussion for help. |
Actually I am wondering why we need this method, which is just a wrapper. Why can't plugin just manager the shell method in their own code? @Flow-Launcher/team thoughts? |
So to clarify this PR, I repeat again. This PR does: This PR aims to let flow run cmd, then let this cmd.exe run other plugins since we have Before there did: flow run other plugins, so there had to need to know where the path of the interpreter. Flow.Launcher/Flow.Launcher.Core/Plugin/PythonPlugin.cs Lines 35 to 40 in f6f306e
Flow.Launcher/Flow.Launcher.Core/Plugin/ExecutablePlugin.cs Lines 27 to 31 in f6f306e
Flow.Launcher/Flow.Launcher.Core/Plugin/PythonPlugin.cs Lines 28 to 29 in f6f306e
|
Sorry I don't quite get your point. Python plugin can run those command in cmd easily as well, because cmd.exe is in environments path, which can be accessed anywhere. |
Correct, this PR only seeks to implement a JsonRPC method that is specified in the docs (here). This method call only has two parts, the method name ( It also makes sense for some other languages that aren't really designed for interacting with the OS, like a JS plugin. Much easier to just have Flow Launcher handle that execution once people start making plugins there. |
Does this launch the shell as a separate process? Could help with some niche issues Python/shell has with Flow. |
For example # cmd.py
import os
os.system("python hello.py") # hello.py
print("hello") result as following > python cmd.py
hello For C#, it could do in some way. |
Yes, I see two RPC methods in the docs that seem to be getters, so presumably there's a way to receive input back from an RPC method, but I haven't seen it described anywhere. |
There is. Just type he method name in the method property in the response for the result. If the method is not started with |
I think this is ok to add in for:
You can run os cmd in any language but i think the intention here is to allow running of the cmd when the user selects the result, which is tied to the method registered in the callback message.
yep. Any additional concerns @taooceros @Zeroto521 @Garulf ? |
Flow.Launcher/PublicAPIInstance.cs
Outdated
startInfo.FileName = "cmd.exe"; | ||
startInfo.Arguments = $"/C {cmd}"; | ||
startInfo.CreateNoWindow = true; | ||
process.Start(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@spedrickson have you tested this with your plugin? the method is not returning the result from the command
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes it works for my plugin, but I'm only using it to launch files (identical to Browser plugin), not receive data back on the plugin side.
One concern with returning results: right now the commands are launched in a separate process to prevent locking up the Flow UI, so even long-running commands won't impact user experience. Maintaining a list of running processes is easy enough, but then we get into design decisions like whether return order should be maintained.
Might be worth adding a separate function like GetShellRun
,that works the same way but keeps the process and regularly polls it for output?
I havent been able to test this as I was busy debugging a plugin. I'll take a look tonight. |
hey @spedrickson your changes are good, no issues. I just took the opportunity to do a quick mini refactor so we can remove duplicate command execute code, hope it's ok :) @taooceros when you get a chance please review and merge in if ok. |
ok, I am thinking about custom terminal host (like the windows terminal, powershell, etc). Probably it will be better to have this command executed in a place that can access setting? |
Other things look great for me, so after checking the place to place the command, we can merge it. |
I exposed filename, so now you can pass in the shell program you want to run with, i.e. powershell.exe for running with powershell instead of cmd.exe |
One concern with this change as-is, the Not sure what the best solution is, just pointing out a potential bug. |
Powershell and cmd both accept |
good pickup, i have added a condition to append |
outdated, no longer using the code block
Saw here #244 (comment) that ShellRun (among other JsonRPC methods) wasn't supported yet.
Didn't see it being worked on elsewhere, so here's a very basic attempt at supporting it.
I went with no window creation just because it fits the plugin I'm building, but that can easily be changed/exposed as a parameter.