go-astilectron
go-astilectron copied to clipboard
Prompt to run with root privilege
Hi,
First of all thank you so much for this project. It's been really helpful. I'm currently working on a go program and planning to embed it with go-astilectron. One problem I encountered was that to run my program properly I need to execute the program with root privilege using sudo. But when I bundle the program and run the application it doesn't automatically grant the permission. I'm wondering whether there is a good way with astilectron to allow the program to be executed with root privilege, maybe with a prompt for users to confirm or something like that. I noticed that using a Manifest file usually provides what I needed, so just wondering whether astilectron has some similar support.
Thank you very much.
Unfortunately this is not possible as of right now. Out of curiosity, is it a cmd you're spawning that requires sudo
privileges? If so, are you spawning it using GO or JS?
@asticode Thanks! The main reason is that my program will try to bind port number 53 with functions like net.ListenUDP which requires root privilege. I would really appreciate any suggestions for this type of scenario.
Thank you very much!
Unfortunately I don't see any solution for this. I've found this NodeJS package that allows executing scripts needing sudo from JS but that would defeat the purpose of udp listening in GO in your case...
Thanks for your comment. I also tried to separate the program into two separate program, and the front end will execute command line "sudo ./backend_binary" to ask user to input sudo password at run time. But apparently I wasn't able to successfully package multiple binaries using asticode bundler. I know that on Windows system using the Manifest file specifying something like:
<security>
<requestedPrivileges>
<requestedExecutionLevel level="requireAdministrator" uiAccess="false"/>
</requestedPrivileges>
</security>
Not sure whether MacOS and Linux would have something similar, but I feel like that could be very helpful if asticode bundler supports this as well (or maybe it already does, just I didn't figure out)
But thank you anyways.
Hi, I sort of figured out a way to work around that. But that requires me to manually bundle and package my app. I'm kind of wondering what would be a good practice to turn the electron UI into an asset, or where I should put the html files in the .app/Contents, for bundling without using the provided bundler (which btw is an awesome project, thanks). Thanks!
Out of curiosity, why do you need to manually bundle to make your solution work ?
Basically I had to use a helper script or helper program to run sudo ./actual_program. I actually figured that using Info.plist I was able to run the program with sudo, but I haven't seen any similar documentation support of asticode-bundler for Windows (for example, customized Windows manifest file).
Hi @asticode On a side note, I'm wondering whether it supports loading other npm packages (just like doing npm install Package-Name) Thank you very much
I actually figured that using Info.plist I was able to run the program with sudo, but I haven't seen any similar documentation support of asticode-bundler for Windows (for example, customized Windows manifest file).
For now there's not because I'm not really familiar with Windows manifest. However, if you find how to properly edit the Windows manifest in order to fix your problem for Windows and feel like it, I'm welcoming PRs. My guess is that changes would occur here
On a side note, I'm wondering whether it supports loading other npm packages (just like doing npm install Package-Name)
There are 2 places I see where loading npm packages make sense:
-
in astilectron - that would be useful if someone wanted to add behavior(s) in Electron main process. My guess is that it would be doable in the bundler by adding "path to npm" + "path to .js files to add to astilectron source files" in the bundler configuration. Then, during the bundle, after downloading astilectron source files, additionnal source files would be copied next to them, "npm install" would be ran and voilà. Changes would surely occur here
-
in the .js of your app - In that case, you can do it during the building of your app files.
If adding this is useful to you, I'm welcoming PRs.