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

Unable to access electron features #2162

Closed
thegecko opened this issue Jun 22, 2018 · 8 comments
Closed

Unable to access electron features #2162

thegecko opened this issue Jun 22, 2018 · 8 comments
Labels
electron issues related to the electron target question user / developer questions

Comments

@thegecko
Copy link
Member

We have a need to access the execution path of Theia when running in electron using the following method:

    import { app } from 'electron';
    console.log(app.getAppPath());

The expectation is that the electron environment is available to an electron backend as mentioned in the extension README.

This works as expected in a debug scenario, however fails to work when running the application standalone.

Investigation has shown this is due to the use of the Node.js cluster module which is disabled when debugging.

Short of disabling clustering in the target application, is there a recommended way of achieving electron environment access? I was expecting to see something using IPC, but can't see any example of this in the codebase.

Thanks!

@kittaakos kittaakos added the electron issues related to the electron target label Jun 22, 2018
@kittaakos
Copy link
Contributor

I am aware of one single IPC message between the backend and the client; please check your generated /theia/examples/electron/src-gen/backend/main.js:

// ...
address.then(function (address) {
    if (process && process.send) {
        process.send(address.port.toString());
    }
});
// ...

and the generated /theia/examples/electron/src-gen/frontend/electron-main.js module:

// ...
const cp = fork(mainPath);
cp.on('message', (message) => {
    loadMainWindow(message);
});
// ...

@thegecko
Copy link
Member Author

Thanks.

OK, so the inability to access electron from the backend of an electron extension is expected?

Forgive me if I'm missing something, but I'm having difficulty creating a mental map of this.

It would be really useful if the architecture docs could reflect these models.

@akosyakov
Copy link
Member

akosyakov commented Jun 25, 2018

Hi, ideally we would allow it, but while working on the dynamic extension system we had to separate (via the cluster module) the server code to allow install/uninstall extensions at runtime, for example that we don't kill the existing server if a new is not good. Unfortunately, a forked process does not have an access to electron APIs, it is plain node process with some flags.

My mental map looks like that: electron (cluster) main process (manages server workers) --> server worker process (run actual server code)

There is a possible solution to the issue to spawn a new electron process for each server worker instead of using the cluster module but it will involve reimplementation of things already done by the cluster module.

For now if you are not interested in the dynamic extensions you can indeed use --no-cluster mode. Or you can try to spawn a new electron process from an extension. It is a way, for example, how vscode extensions try to access electron apis: microsoft/vscode#3011 (comment)

We have a need to access the execution path of Theia when running in electron using the following method:

If you can share what you are trying to achieve specifically we could come up with more specific suggestions :)

@akosyakov akosyakov added the question user / developer questions label Jun 25, 2018
@thegecko
Copy link
Member Author

Thanks for the explanation.

In this specific case, we need to know where electron is being executed from so that we can run other installed binaries installed with our application.

I can see the need to access the other electron app methods, too. Perhaps this object needs to be exposed to the worker processes?

@thegecko
Copy link
Member Author

thegecko commented Jul 3, 2018

Ironically it seems electron app methods are available in frontend modules via electron.remote.app, however it seems non-sensical to pull data through to the frontend only to send it back to the backend!

@thegecko
Copy link
Member Author

thegecko commented Jun 4, 2019

@kittaakos

@tsmaeder
Copy link
Contributor

@thegecko does __dirname or __filename not let you find out where your extension is installed?

@thegecko
Copy link
Member Author

Probably, but we got round this somehow years ago ;)

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 question user / developer questions
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants