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

[Feature] Hook into electron main master process #3364

Closed
bogthe opened this issue Nov 1, 2018 · 7 comments · Fixed by #7964
Closed

[Feature] Hook into electron main master process #3364

bogthe opened this issue Nov 1, 2018 · 7 comments · Fixed by #7964
Labels
electron issues related to the electron target

Comments

@bogthe
Copy link
Contributor

bogthe commented Nov 1, 2018

Hi everyone!

I'm looking into adding updates through electron-updater into Theia and for this I need the code which checks for the updates to be running on electron's main master process.
As it currently is, all backend modules are loaded on Electron's main worker process which causes the electron-updater module to break. There's a possibility other modules / packages / features will need to have code running from the same location so I wanted to make the hook (binding) into the master process as reusable as possible.

I was thinking of:

  • modifying the bit in theia cli which auto generates the electron files to either check for a custom property in the package.json file of packages (plugins) like the ones for frontend, backend etc. and then require them in the master process;
  • or have an option which allows the user to specify which packages to be required when the master process is being ran;

What do you think?

@paul-marechal
Copy link
Member

As it currently is, all backend modules are loaded on Electron's main worker process [...]

I am not so sure... The startup sequence is really confusing, so maybe I'm wrong, but unless you specify --no-cluster when starting electron, Theia's backend is ran inside a separate process from which the entry point electron-main.js was started in.

What files were you thinking about modifying in particular? (the generated ones)

@kittaakos
Copy link
Contributor

FYI: only the bundled electron application has real forked processes. I am happy you are working on this, @bogthe. Make sure your electron-updater contribution works in production mode too ;)

https://github.com/theia-ide/theia/blob/accdbd7c440f96ce4b0e1b40b56a0cf78be83f37/dev-packages/application-manager/src/generator/frontend-generator.ts#L168-L186

@kittaakos kittaakos added the electron issues related to the electron target label Nov 1, 2018
@paul-marechal
Copy link
Member

paul-marechal commented Nov 1, 2018

@kittaakos but in the dev mode, we do require main.js, which in turn will go in cluster/main.js and do funny forks on server.js (where backend modules are loaded)?

https://github.com/theia-ide/theia/blob/accdbd7c440f96ce4b0e1b40b56a0cf78be83f37/dev-packages/application-manager/src/generator/backend-generator.ts#L81

@kittaakos
Copy link
Contributor

funny forks

That is a different fork. We have the main electron process, we fork the backend from it, and the backend will fork cluster workers.

@paul-marechal
Copy link
Member

paul-marechal commented Nov 1, 2018

So the backend is in fact forked away from the main process? (in dev mode)

@paul-marechal
Copy link
Member

paul-marechal commented Nov 1, 2018

@bogthe on the topic of customizing the start up sequence somehow, I would agree that it is a good idea.

We already drive the generators with infos in the package.json, sounds like a good idea to continue :)

But again, what kind of flow would you expect to see happening? (what to define, how is it triggered and executed?)

@bogthe
Copy link
Contributor Author

bogthe commented Nov 4, 2018

@marechal-p @kittaakos thanks for replying so quickly!

I was thinking of having an entra option in the package.json file under theiaExtensions called electronMaster (or something similar) for a theia package which tells the generator to require this module (and any other modules which have that option) inside this stamement here by doing something like:

require('../backend/masterElectron.js`);

(Also that require is present only if there are packages with that option available as to not cram the code too much)

Inside of masterElectron.js I only see the required modules as such:

\\ masterElectron.js
require('@theia/electron-updates');
require('@theia/some-random-master-package');

This in turn gives control to the packages to manage their messaging through ipcRenderer, ipcMain between the frontend and this new backend.

Maybe there is a more elegant way of doing this but for a first implementation I think the code is mostly there for generating the file + code, and handling updates it's a good first step.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
electron issues related to the electron target
Projects
None yet
3 participants