Run javascript in `main` process
Naatan opened this issue · 6 comments
I can only find ways to run custom javascript in the renderer process, is there a way to run it in the main process?
Reason being; Electron versions after version 13 no longer support the remote
module, so if you want to use dialogs you have to do something like this: https://www.christianengvall.se/electron-showopendialog-tutorial/
I can't find how I would achieve this with go-astilectron.
You can't run custom JS in the main process with go-astilectron
as of now. I'm not sure including it in the lib would be a good idea 🤔 Including dialog handling directly in the lib is not really easy to maintain.
Your best option would be to use Electron version 11, but I guess there's a good reason if you're using version 13.
Curious; what issue do you foresee with including it in the lib?
People may need to run custom JS in the main process in a lot of places : when app is read, when app is about to quit, when a window is created, etc. and they could even need several custom JS at several places to interoperate. I feel this would open Pandora's box and would be a pain to maintain.
Also we would need to use eval()
and I don't really like the idea of that.
Got it. Would you mind instead providing some pointers on what someone would need to do if they wanted to implement this in a fork meant for their own use?
Got it. Would you mind instead providing some pointers on what someone would need to do if they wanted to implement this in a fork meant for their own use?
Sure. If I were you and only needed the dialog feature, I would only update the JS part of astilectron
. I would add the listeners, described in the link you've shared, in this function. Then all you'd need to do is call dialog.showOpenDialog()
in the renderer
process.
Awesome, thank you!