问题
Problem description:
I have an electron application and I need to add the application to user environment variables after users install my application, so that they can run commands like this my-electron-app <command> [<args>]
in the terminal to start my electron application.
I could not find a way to do this programmatically using nodejs. VSCode, hyper and atom are the three electron apps ( that I know of ) who add the application path to user environment variables after users install the application.
I'm using electron builder to build an NSIS installer. I couldn't find any options there either that serve the purpose.
Question:
How can I add my electron application to user environment variables after users install my application on their system, so that they can launch my electron app from terminal by running commands like this my-electron-app start
?
回答1:
I am blindly guessing here since I have simply browsed through the code for a couple of minutes: There seems to be a post install step which is maybe also used in Hyper here somehow. This script places a file in a folder that is probably in the user's PATH
. More about the PATH environment variable here.
回答2:
I cannot asked just yet so will reply as answer.
If you just want to start the application with 'start' param or any, you can actually parse those as parameter when running the .exe file.
See my comment here: https://stackoverflow.com/a/53092600/10546462
来源:https://stackoverflow.com/questions/53412841/adding-electron-application-path-to-user-environment-variables-after-install