Guidance on extending Go <-> Electron Interop
Hi there,
I'm looking into adding some functionality to astilectron and am unfortunately running into barriers due to my unfamiliarity with the codebase. Hoping to get some guidance via this ticket, and will be happy to open up PRs for the enhancements I'm looking to make.
I'm looking to expose electron features like:
- Creating custom context menu's -- https://www.electronjs.org/docs/latest/api/menu/
- Retrieving File Icons: https://www.electronjs.org/docs/latest/api/app#appgetfileiconpath-options
- Dialogs: https://www.electronjs.org/docs/latest/api/dialog/
I've been experimenting with index.js to try and add the functionality I need but it's slow going. Namely I can't seem to figure out how to send and receive messages between Go and electron. The code that exists for this is so low level that it's hard to follow along with without educating myself on the entirety of the codebase.
Any chance someone could provide some pointers on how I would go above adding more interop between Go and electron? A simple "hello world" example for sending messages to/from electron would be tremendously helpful.
Thank you!
First off thanks for taking an interest in this project.
Regarding menus, it should already be possible to create them using this GO function. Or is your use case missing in this lib?
As for dialogs it's a little bit more complex since one need to mix code both in the main and renderer process 🤔
Here's how to send a message to go :
client.write(targetId, eventName, payload)
Here's how to send a message to js :
synchronousEvent(ctx, object, writer, payload, eventName)
You can check out the Blur function to see how it works.
Thanks! I was able to put something together; https://github.com/asticode/astilectron/pull/63
For the menu's - I'm not certain yet whether I will need to add something. From what I gather electron only facilitates the menubar and not context menu's, but I've seen some node.js packages that add this functionality. I assumed I would have to do something similar.