Skip to content
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

Support Electron 11 + other refactorings #8

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

beorn
Copy link

@beorn beorn commented Nov 18, 2020

Hi!

I really liked your approach in this example program - I think it's a really neat way to set up IPC between electron processes. I'm not sure if you're open for PRs for this, but as part of me going over your code and understanding your approach I thought of some ways to make it (I think) even better. I apologize that these are not split up into separate PRs - I figured that the code base is so small maybe it wouldn't be too hard to review together. If you don't agree with these changes that's fine too - I mostly did it for my own learnings anyways. That said, I really hope we can work together on best practices for Electron multi-process setups.

Here's a summary of the changes:

  1. Upgraded to work with latest versions of all packages (including Electron 11).

  2. Rely on ipc.config.appspace with app-name+PID to provide a unique namespace for the socketIds - so no need to check if the socket is in-use as it's guaranteed to be a dead socket if it's there. Also remove socket after use. This also makes it easier to pass around more socketIds - as long as they're unique within the app the appspace prefix will ensure they're unique across the entire system. (Also make the naming more consistent with the IPC module: socketName => socketId.)

  3. Pass IPC appspace and socketId as command line arguments to both renderer and process versions instead of passing them through electron IPC and through CLI for subprocess version. I quite liked how this unified the code and approach for bootstrapping both the subprocess and renderer versions. This also means you can connect immediately, simplifying initialization. (The parseArgs utility function is currently duplicated in the client and server - it's only 7 lines, and I couldn't figure out how to share code without adding a lot of JS tooling.)

  4. As an example, also pass appVersion and isDev as through command line, which also makes it easy to remove the (unsafe - and setting a bad example) remote module in the renderer.

  5. Set up CSP for both HTML files.

I'd like to continue expanding on this to see how to support multiple services/servers, each with different webpack builds, perhaps more microservices type features such as discovery, and how to support observables across these connections.

1) Upgrade to work with latest versions of all packages (including Electron 11).

2) Rely on ipc.config.appspace with app-name+PID to provide a unique namespace for the socketIds - so no need to check if the socket is in-use as it's guaranteed to be a dead socket if it's there.  Also remove socket after use.  This also makes it easier to pass around other socketIds - as long as they're unique within the app the appspace prefix will ensure they're unique across the entire system.

3) Pass IPC appspace and socketId as command line arguments to both renderer and process versions instead of passing them through electron IPC.  This means you can connect immediately, simplifying init.  (The `parseArgs` utility function is currently duplicated in the client and server - it's only 7 lines, and I couldn't figure out how to share code without adding a lot of JS tooling.)

4) As an example, also pass appVersion and isDev as through command line, which also makes it easy to remove the (unsafe) remote module in the renderer.
@beorn beorn changed the title Feat/electron11 modern Support Electron 11 + other refactorings Nov 18, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant