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

New @theia/example-hybrid application #2340

Closed
wants to merge 1 commit into from
Closed

Conversation

paul-marechal
Copy link
Member

@paul-marechal paul-marechal commented Jul 11, 2018

This PR adds support for an electron client to connect to an hybrid backend.

Currently done:

  • New @theia/example-hybrid package that can serve both web browsers and electron apps.
  • Modified the generators to autogen @theia/example-hybrid.
  • New Electron-specific commands to choose a remote host to connect to.
    • Basic host connection history.
    • Host polling to see status (online/offline).
  • Some issues when actually loading remote content in Electron.
    • It seems to come from the AMD loader importing the monaco editor.
  • Security options are not yet set to accommodate for remote content loading
    • Such as disabling node integration and such...

How to test this PR:

  • Use node v8.2.1, it should be the same as the one used by Electron, so that you don't have to rebuild native modules when starting @theia/example-electron and @theia/example-hybrid
nvm install 8.2.1
nvm alias electron 8.2.1
nvm alias default electron
nvm use electron
  • Start both @theia/example-electron and @theia/example-hybrid so that you have a server to connect to.
  • Open the command palette (F1) and use Remote: Connect to a server.

@paul-marechal paul-marechal changed the title mp/example hybrid [wip] mp/example hybrid Jul 11, 2018
@paul-marechal paul-marechal changed the title [wip] mp/example hybrid [wip] New @theia/example-hybrid application Jul 11, 2018
@paul-marechal paul-marechal changed the title [wip] New @theia/example-hybrid application [wip] New @theia/example-hybrid application Jul 11, 2018
@paul-marechal
Copy link
Member Author

paul-marechal commented Jul 11, 2018

Currently having an issue when the electron client connects to the hybrid backend:

The correct bundle.js seems to be sent/received, but the AMD loader seems to having troubles loading the monaco editor. I might need some help here @akosyakov if you don't mind...

It looks like the AMD loader is assuming a node environment, but cannot find some resource, I am a bit confused.

Copy link
Member

@akosyakov akosyakov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The generator part looks good already :)

examples/hybrid/package.json Show resolved Hide resolved
examples/hybrid/package.json Outdated Show resolved Hide resolved
packages/core/package.json Show resolved Hide resolved
packages/core/src/common/promise-util.ts Outdated Show resolved Hide resolved
.gitignore Outdated Show resolved Hide resolved
@akosyakov
Copy link
Member

Could you elaborate on:

Host polling to see status (online/offline).

@paul-marechal
Copy link
Member Author

Host polling to see status

When typing a URL to connect to, the QuickOpenItems will show the state of the server at the targeted address, so that you can know which server is worth connecting to. It will display the state of the request as a description for the URL. The message can be improved later, for now it does what it is meant for: knowing the state of an endpoint (online/offline).

@paul-marechal paul-marechal force-pushed the mp/example-hybrid branch 2 times, most recently from 5e92052 to e28d4fa Compare July 12, 2018 13:48
@paul-marechal
Copy link
Member Author

paul-marechal commented Jul 12, 2018

I just realized that the issue I am having when trying to run the Electron Frontend from http seems to be unrelated to my changes.

If you start an electron application, and then try to open index.html over http instead of reading it directly from disk, it will throw the exact same error. The server will answer you, it will send you the page and the bundle.js, but you will have this error:

loader.js:256 Error: ENOENT, renderer/vs/editor/editor.main.js not found in /home/emaapur/projects/theia/node_modules/electron/dist/resources/electron.asar
    at notFoundError (ELECTRON_ASAR.js:114:19)
    at Object.fs.readFile (ELECTRON_ASAR.js:481:16)
    at NodeScriptLoader.load (http://localhost:3000/vs/loader.js:750:26)
    at OnlyOnceScriptLoader.load (http://localhost:3000/vs/loader.js:585:32)
    at loadNextPath (http://localhost:3000/vs/loader.js:1433:41)
    at ModuleManager._loadModule (http://localhost:3000/vs/loader.js:1445:13)
    at ModuleManager._resolve (http://localhost:3000/vs/loader.js:1524:22)
    at ModuleManager.defineModule (http://localhost:3000/vs/loader.js:1192:18)
    at RequireFunc (http://localhost:3000/vs/loader.js:1640:31)
    at http://localhost:3000/12.bundle.js:2053:9
defaultOnError @ loader.js:256

I currently don't really understand how to fix this.

@paul-marechal paul-marechal force-pushed the mp/example-hybrid branch 2 times, most recently from 18286dd to 9a79a02 Compare July 13, 2018 13:37
@paul-marechal
Copy link
Member Author

@paul-marechal
Copy link
Member Author

Loader issues fixed by monkey patching what was failing \o/

@paul-marechal paul-marechal force-pushed the mp/example-hybrid branch 6 times, most recently from 0044994 to 616b07a Compare July 19, 2018 21:20
@paul-marechal
Copy link
Member Author

@akosyakov I think I have made good progress, if you want to check now and see if anything looks wrong.

Last bit that bothers me is that www.google.com is a valid URL, so the user can open a new Electron window when inputting it... My idea would be to add some kind of localhost:3000/are-you-theia that would respond with {"answer": "yes"}. What do you think ?

@simark cc in case

@paul-marechal paul-marechal force-pushed the mp/example-hybrid branch 2 times, most recently from 57ffb75 to 4d07884 Compare July 24, 2018 11:56
@paul-marechal
Copy link
Member Author

Current state of the PR is that I am fighting with webpack/electron/packages in order to enable appropriate security settings (such as nodeIntegration: false).

Packages often try to guess the environment, and when they detect Electron they just try to use every NodeJS API they can, when we don't want that.

@paul-marechal paul-marechal changed the title [wip] New @theia/example-hybrid application New @theia/example-hybrid application Jul 26, 2018
@paul-marechal
Copy link
Member Author

@akosyakov I will consider this feature done, even though some security concerns are not fully taken into account. This doesn't add more security issues than before, as I am still using the mechanics already in place.

My idea is that this is a feature that people could test for themselves and improve upon if they find it useful for their workflow.

@thegecko pinging you in case you want to secure the feature. We could discuss about the technical details if you are interested in this problem.

IMO connecting the Electron application to a remote server is an awesome use case, although my biggest issue right now would be the current instability of the client (the whole app sometimes shutdowns). Point is, for people that prefer native clients like me, being able to connect to workspace servers is very nice.

@thegecko
Copy link
Member

Thanks for the heads up, I'm away until September when I will be available to revisit security of Theia. In the meantime don't wait on me to merge.

Copy link
Contributor

@marcdumais-work marcdumais-work left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi Paul,

I did a first pass and have a few comments.

const loadMainWindow = (port) => {
mainWindow.loadURL('file://' + join(__dirname, '../../lib/index.html') + '?port=' + port);
const loadMainWindow = (uri) => {
// mainWindow.loadURL(\`http://localhost:\${port}\`);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

left-over code or example of mainWindow.loadURL() usage?

{
"private": true,
"name": "@theia/example-hybrid",
"version": "0.3.11",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

reminder: specific package and dependencies versions will need to be updated to whatever is applicable, at the time we merge.

"target": "hybrid"
},
"dependencies": {
"@theia/callhierarchy": "^0.3.11",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

also we will need to update the dependencies, that might have changed in the other example applications, in the meantime

packages/core/package.json Show resolved Hide resolved
@paul-marechal paul-marechal force-pushed the mp/example-hybrid branch 2 times, most recently from c08a613 to cc62402 Compare September 4, 2018 15:39
@paul-marechal
Copy link
Member Author

@marcdumais-work updated.

@marcdumais-work marcdumais-work dismissed their stale review September 19, 2018 15:38

comments addressed, thanks.

@marcdumais-work
Copy link
Contributor

@marechal-p when you have time, it would be good to rebase this PR.

Add a new example package serving both web browsers and electron clients.
Add new commands for electron to connect to remote servers.

`electron.remote.connect` command to open a QuickOpenMenu and input an URL.
`electron.remote.history.clear` command to clear the local URL history.
`electron.remote.disconnect` to close the window in case you are connected to a server.

Adds an endpoint to tell if it is a Theia application or not.

Signed-off-by: Paul Maréchal <paul.marechal@ericsson.com>
@paul-marechal
Copy link
Member Author

Based on new discussions and considerations, the following PR is considered as a POC instead, and more thinking would be required before proceeding.

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.

4 participants