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

GH-3254: Fixed the incomplete logic when checking if running in Electron #3264

Merged
merged 2 commits into from
Oct 28, 2018

Conversation

kittaakos
Copy link
Contributor

@kittaakos kittaakos commented Oct 24, 2018

  • is-electron checks only the process.versions.electron in Node.js.
  • process.versions is not set/inherited when calling:
    • child_process.fork or
    • cluster.fork.
  • Extended the is-electron logic to verify process.env as well.

Closes: #3254.
Closes: #2992.

Signed-off-by: Akos Kitta kittaakos@typefox.io

@kittaakos kittaakos force-pushed the GH-3254 branch 2 times, most recently from 409ca6e to 64d9adc Compare October 24, 2018 10:51
@kittaakos
Copy link
Contributor Author

Reviewers, please do not do anything until my next notice. It is still in development, I had to create the PR. Thanks!

@kittaakos kittaakos changed the title GH-3254: Fixed the incomplete logic when checking if running in Electron [WIP] GH-3254: Fixed the incomplete logic when checking if running in Electron Oct 24, 2018
@kittaakos kittaakos changed the title [WIP] GH-3254: Fixed the incomplete logic when checking if running in Electron GH-3254: Fixed the incomplete logic when checking if running in Electron Oct 24, 2018
 - `is-electron` checks only the `process.versions.electron` in Node.js.
 - `process.versions` is not set/inherited when calling:
   - `child_process.fork` or
   - `cluster.fork`.
 - Extended the `is-electron` logic to verify `process.env` as well.

Closes: #3254.

Signed-off-by: Akos Kitta <kittaakos@typefox.io>
@kittaakos
Copy link
Contributor Author

It is ready for the review. I am doing another verification cycle:

  • build an electron application from the published next Theia.
  • start and verify that it's failing.
  • compile the Theia source from this branch.
  • copy the compiled code from @theia/core, @theia/workspace, and @theia/application-package into the bundled electron application.
  • start and verify that it works.

@kittaakos
Copy link
Contributor Author

verification cycle

👍 Done. It works nicely.

Before:

c:\Program Files\TypeFox\MyApp>
Starting the master backend process without a timeout.
Starting server worker...
Server worker has been started. [ID: 1 | PID: 4760]
Error: @postConstruct error in class TypeScriptContribution: EPERM: operation not permitted, open 'c:\Program Files\TypeFox\MyApp\.application-module-loader.js'
    at _postConstruct (c:\Program Files\TypeFox\MyApp\resources\app\node_modules\inversify\lib\resolution\instantiation.js:30:19)
    at Object.resolveInstance (c:\Program Files\TypeFox\MyApp\resources\app\node_modules\inversify\lib\resolution\instantiation.js:47:5)
    at c:\Program Files\TypeFox\MyApp\resources\app\node_modules\inversify\lib\resolution\resolver.js:72:42
    at c:\Program Files\TypeFox\MyApp\resources\app\node_modules\inversify\lib\resolution\resolver.js:34:24
    at Array.map (native)
    at c:\Program Files\TypeFox\MyApp\resources\app\node_modules\inversify\lib\resolution\resolver.js:32:34
    at Object.resolve (c:\Program Files\TypeFox\MyApp\resources\app\node_modules\inversify\lib\resolution\resolver.js:96:12)
    at c:\Program Files\TypeFox\MyApp\resources\app\node_modules\inversify\lib\container\container.js:319:37
    at Container._get (c:\Program Files\TypeFox\MyApp\resources\app\node_modules\inversify\lib\container\container.js:310:44)
    at Container.getAll (c:\Program Files\TypeFox\MyApp\resources\app\node_modules\inversify\lib\container\container.js:239:21)
Server worker is ready to accept messages. [ID: 1 | PID: 4760]
root INFO Theia app listening on http://localhost:3000.
Received message which is neither a response nor a notification message:
"3000"
root ERROR Request getApplicationInfo failed with error: ENOENT: no such file or directory, open 'c:\Program Files\TypeFox\MyApp\package.json' Error: ENOENT: no such file or directory, open 'c:\Program Files\TypeFox\MyApp\package.json'
    at Object.fs.openSync (fs.js:652:18)
    at Object.module.(anonymous function) [as openSync] (ELECTRON_ASAR.js:172:20)
    at Object.fs.readFileSync (fs.js:553:33)
    at Object.fs.readFileSync (ELECTRON_ASAR.js:508:29)
    at Object.readJsonFile (c:\Program Files\TypeFox\MyApp\resources\app\node_modules\@theia\application-package\lib\json-file.js:22:26)
    at ApplicationPackage.get [as pck] (c:\Program Files\TypeFox\MyApp\resources\app\node_modules\@theia\application-package\lib\application-package.js:147:44)
    at ApplicationServerImpl.getApplicationInfo (c:\Program Files\TypeFox\MyApp\resources\app\node_modules\@theia\core\lib\node\application-server.js:38:42)
    at JsonRpcProxyFactory.<anonymous> (c:\Program Files\TypeFox\MyApp\resources\app\node_modules\@theia\core\lib\common\messaging\proxy-factory.js:216:73)
    at step (c:\Program Files\TypeFox\MyApp\resources\app\node_modules\@theia\core\lib\common\messaging\proxy-factory.js:47:23)
    at Object.next (c:\Program Files\TypeFox\MyApp\resources\app\node_modules\@theia\core\lib\common\messaging\proxy-factory.js:28:53)
root WARN Collided keybinding is ignored;  {"command":"monaco.editor.action.wordHighlight.next","keybinding":"f7","context":"editorTextFocus"}  collided with  {"command":"monaco.editor.action.diffReview.next","keybinding":"f7","context":"editorTextFocus"}
root WARN Could not register keybinding:
  {"command":"monaco.editor.action.wordHighlight.next","keybinding":"f7","context":"editorTextFocus"}
Error: "f7" is in collision with something else [scope:0]
root WARN Collided keybinding is ignored;  {"command":"monaco.editor.action.wordHighlight.prev","keybinding":"shift+f7","context":"editorTextFocus"}  collided with  {"command":"monaco.editor.action.diffReview.prev","keybinding":"shift+f7","context":"editorTextFocus"}
root WARN Could not register keybinding:
  {"command":"monaco.editor.action.wordHighlight.prev","keybinding":"shift+f7","context":"editorTextFocus"}
Error: "shift+f7" is in collision with something else [scope:0]
root WARN Shadowing keybinding is ignored;  {"command":"terminal:clear","keybinding":"ctrlcmd+k"}  shadows  {"command":"workspace:openFolder","keybinding":"ctrl+k ctrl+o"}
root WARN Could not register keybinding:
  {"command":"terminal:clear","keybinding":"ctrlcmd+k"}
Error: "ctrlcmd+k" is in collision with something else [scope:0]
root INFO [nsfw-watcher: 7712] Started watching: c:\Users\kittaakos\.theia
root INFO [nsfw-watcher: 7712] Started watching: c:\Users\kittaakos\dev\Something_MyApp_Examples\Examples\MyApp
root INFO [nsfw-watcher: 7712] Started watching: c:\Users\kittaakos\dev\Something_MyApp_Examples\Examples\MyApp
root INFO Started watching the git repository: file:///c%3A/Users/kittaakos/dev/Something_MyApp_Examples
root INFO Checking whether '--no-optional-locks' can be used with the current Git executable. Minimum required version is '2.15.0'.
root INFO [nsfw-watcher: 7712] Started watching: c:\Users\kittaakos\dev\Something_MyApp_Examples\Examples\MyApp\Business\Batch\Batch.bmodel
root ERROR Cannot find a service for the path: /services/languages/bmodel
root INFO '--no-optional-locks' is a valid Git option for the current Git version: '2.17.1.windows.2'.

After:

c:\Program Files\TypeFox\MyApp>
Starting the master backend process without a timeout.
Starting server worker...
Server worker has been started. [ID: 1 | PID: 5204]
Server worker is ready to accept messages. [ID: 1 | PID: 5204]
root INFO Theia app listening on http://localhost:54769.
Received message which is neither a response nor a notification message:
"54769"
root WARN Collided keybinding is ignored;  {"command":"monaco.editor.action.wordHighlight.next","keybinding":"f7","context":"editorTextFocus"}  collided with  {"command":"monaco.editor.action.diffReview.next","keybinding":"f7","context":"editorTextFocus"}
root WARN Could not register keybinding:
  {"command":"monaco.editor.action.wordHighlight.next","keybinding":"f7","context":"editorTextFocus"}
Error: "f7" is in collision with something else [scope:0]
root WARN Collided keybinding is ignored;  {"command":"monaco.editor.action.wordHighlight.prev","keybinding":"shift+f7","context":"editorTextFocus"}  collided with  {"command":"monaco.editor.action.diffReview.prev","keybinding":"shift+f7","context":"editorTextFocus"}
root WARN Could not register keybinding:
  {"command":"monaco.editor.action.wordHighlight.prev","keybinding":"shift+f7","context":"editorTextFocus"}
Error: "shift+f7" is in collision with something else [scope:0]
root WARN Shadowing keybinding is ignored;  {"command":"terminal:clear","keybinding":"ctrlcmd+k"}  shadows  {"command":"workspace:openFolder","keybinding":"ctrl+k ctrl+o"}
root WARN Could not register keybinding:
  {"command":"terminal:clear","keybinding":"ctrlcmd+k"}
Error: "ctrlcmd+k" is in collision with something else [scope:0]
root INFO [nsfw-watcher: 7892] Started watching: c:\Users\kittaakos\.theia
root INFO [nsfw-watcher: 7892] Started watching: c:\Users\kittaakos\dev\Something_MyApp_Examples\Examples\MyApp
root INFO [nsfw-watcher: 7892] Started watching: c:\Users\kittaakos\dev\Something_MyApp_Examples\Examples\MyApp
root INFO Started watching the git repository: file:///c%3A/Users/kittaakos/dev/Something_MyApp_Examples
root INFO Checking whether '--no-optional-locks' can be used with the current Git executable. Minimum required version is '2.15.0'.
root INFO [nsfw-watcher: 7892] Started watching: c:\Users\kittaakos\dev\Something_MyApp_Examples\Examples\MyApp\Business\Batch\Batch.bmodel
root INFO Starting language server c:\Program Files\TypeFox\MyApp\resources\app\node_modules\MyApp-theia-extension\MyApp-language-server\bin\MyApp-language-server.bat
root INFO '--no-optional-locks' is a valid Git option for the current Git version: '2.17.1.windows.2'.
root ERROR BModel: Oct 24, 2018 2:51:39 PM org.eclipse.lsp4j.jsonrpc.RemoteEndpoint handleCancellation

@elaihau
Copy link
Contributor

elaihau commented Oct 24, 2018

I am getting the following errors when starting electron in my local env:

root ERROR Could not start contribution Error: Could not call remote function ''. Check that the function signature is correct. Underlying error: Error processing argument at index 1, conversion failure from fa fa-play
Error: Could not call remote function ''. Check that the function signature is correct. Underlying error: Error processing argument at index 1, conversion failure from fa fa-play
    at callFunction (/home/elaihau/theia/node_modules/electron/dist/resources/electron.asar/browser/rpc-server.js:257:11)
    at EventEmitter.<anonymous> (/home/elaihau/theia/node_modules/electron/dist/resources/electron.asar/browser/rpc-server.js:357:5)
    at emitMany (events.js:146:13)
    at EventEmitter.emit (events.js:223:7)
    at WebContents.<anonymous> (/home/elaihau/theia/node_modules/electron/dist/resources/electron.asar/browser/api/web-contents.js:275:13)
    at emitTwo (events.js:125:13)
    at WebContents.emit (events.js:213:7)
    at Object.exception (/home/elaihau/theia/node_modules/electron/dist/resources/electron.asar/renderer/api/remote.js:209:30)
    at metaToValue (/home/elaihau/theia/node_modules/electron/dist/resources/electron.asar/renderer/api/remote.js:213:28)
    at Function.remoteMemberFunction (/home/elaihau/theia/node_modules/electron/dist/resources/electron.asar/renderer/api/remote.js:113:16)
    at ElectronMainMenuFactory.push.../../packages/core/lib/electron-browser/menu/electron-main-menu-factory.js.ElectronMainMenuFactory.createMenuBar (file:///home/elaihau/theia/examples/electron/lib/37.bundle.js:183:41)
    at ElectronMenuContribution.push.../../packages/core/lib/electron-browser/menu/electron-menu-contribution.js.ElectronMenuContribution.onStart (file:///home/elaihau/theia/examples/electron/lib/37.bundle.js:501:43)
    at FrontendApplication.<anonymous> (file:///home/elaihau/theia/examples/electron/lib/bundle.js:75176:59)
    at step (file:///home/elaihau/theia/examples/electron/lib/bundle.js:74870:23)
    at Object.next (file:///home/elaihau/theia/examples/electron/lib/bundle.js:74851:53)
    at fulfilled (file:///home/elaihau/theia/examples/electron/lib/bundle.js:74842:58)
    at <anonymous>
root ERROR TypeError: Cannot read property 'getMenuItemById' of undefined
    at file:///home/elaihau/theia/examples/electron/lib/37.bundle.js:164:32
    at CallbackList.../../packages/core/lib/common/event.js.CallbackList.invoke (file:///home/elaihau/theia/examples/electron/lib/bundle.js:90260:39)
    at Emitter.../../packages/core/lib/common/event.js.Emitter.fire (file:///home/elaihau/theia/examples/electron/lib/bundle.js:90340:36)
    at PreferenceServiceImpl.../../packages/core/lib/browser/preferences/preference-service.js.PreferenceServiceImpl.reconcilePreferences (file:///home/elaihau/theia/examples/electron/lib/bundle.js:78525:45)
    at PreferenceServiceImpl.<anonymous> (file:///home/elaihau/theia/examples/electron/lib/bundle.js:78468:30)
    at step (file:///home/elaihau/theia/examples/electron/lib/bundle.js:78355:23)
    at Object.next (file:///home/elaihau/theia/examples/electron/lib/bundle.js:78336:53)
    at fulfilled (file:///home/elaihau/theia/examples/electron/lib/bundle.js:78327:58)
    at <anonymous>

It could just be me. I asked @vince-fugnitto to check if it happens in his env.
btw, I ran the test on Ubuntu.

@vince-fugnitto
Copy link
Member

I am getting the following errors when starting electron in my local env:
It could just be me. I asked @vince-fugnitto to check if it happens in his env.

I'm confirming that it's happening on my side as well @elaihau

@kittaakos
Copy link
Contributor Author

@elaihau, @vince-fugnitto, thank you for checking. It happens on the master too. Can you please verify it? Just guessing, but I would say, there was a preference related change on the master, and the listener in the constructor is fired before the createMenuBar is called. What do you think?

@vince-fugnitto
Copy link
Member

@elaihau, @vince-fugnitto, thank you for checking. It happens on the master too. Can you please verify it? Just guessing, but I would say, there was a preference related change on the master, and the listener in the constructor is fired before the createMenuBar is called. What do you think?

I'll build master and verify if the error is there too and what the reason is.

@kittaakos
Copy link
Contributor Author

You can work around it (in debug mode) if you drop (splice) the Debug menu from the electron menu template before calling

https://github.com/theia-ide/theia/blob/233802d755d3ccfadc963fc701d7b9d7994967e1/packages/core/src/electron-browser/menu/electron-main-menu-factory.ts#L51

Perhaps this commit broke it: 64b0b02

CC: @akosyakov

@vince-fugnitto
Copy link
Member

@elaihau @kittaakos I confirmed it occurs in master, and I believe you're right @kittaakos about why the issue occurs, I'll investigate further as well.

@kittaakos
Copy link
Contributor Author

Wild guess: it is related to the icons. From the error message: fa fa-play.

@vince-fugnitto
Copy link
Member

Wild guess: it is related to the icons. From the error message: fa fa-play.

Maybe its the reason since the debug menu are using icons from within the menu, but those icons from font-awesome aren't ready from the time electron builds its menus.

@kittaakos
Copy link
Contributor Author

ready from the time electron builds its menus.

As I see, it should be the FS path to the actual icon and the not the CSS class name of the icon. I will disable it:

diff --git a/packages/core/src/electron-browser/menu/electron-main-menu-factory.ts b/packages/core/src/electron-browser/menu/electron-main-menu-factory.ts
index ea14dbdc..e105ff3e 100644
--- a/packages/core/src/electron-browser/menu/electron-main-menu-factory.ts
+++ b/packages/core/src/electron-browser/menu/electron-main-menu-factory.ts
@@ -100,7 +100,6 @@ export class ElectronMainMenuFactory {
                 items.push({
                     id: menu.id,
                     label: menu.label,
-                    icon: menu.icon,
                     type: this.commandRegistry.getToggledHandler(commandId) ? 'checkbox' : 'normal',
                     checked: this.commandRegistry.isToggled(commandId),
                     enabled: true, // https://github.com/theia-ide/theia/issues/446

@kittaakos
Copy link
Contributor Author

I will disable it

Follow-up: #3268

We cannot use the CSS class name of the `font-awesome` icons.

Signed-off-by: Akos Kitta <kittaakos@typefox.io>
@vince-fugnitto
Copy link
Member

I will disable it

Follow-up: #3268

your patch for the icons works well !

@elaihau
Copy link
Contributor

elaihau commented Oct 25, 2018

UI test failed

root INFO ERROR: %s session not created exception
from disconnected: Unable to receive message from renderer
root INFO chrome
root INFO     at new RuntimeError (C:\projects\theia\node_modules\webdriverio\build\lib\utils\ErrorHandler.js:144:12)
    at Request._callback (C:\projects\theia\node_modules\webdriverio\build\lib\utils\RequestHandler.js:301:39)
    at Request.self.callback (C:\projects\theia\node_modules\webdriverio\node_modules\request\request.js:186:22)
    at emitTwo (events.js:126:13)
    at Request.emit (events.js:214:7)
    at Request.<anonymous> (C:\projects\theia\node_modules\webdriverio\node_modules\request\request.js:1163:10)
    at emitOne (events.js:116:13)
    at Request.emit (events.js:211:7)
    at IncomingMessage.<anonymous> (C:\projects\theia\node_modules\webdriverio\node_modules\request\request.js:1085:12)
    at Object.onceWrapper (events.js:313:30)
root INFO ERROR: %s session not created exception
from disconnected: unable to connect to renderer
root INFO chrome
root INFO     at new RuntimeError (C:\projects\theia\node_modules\webdriverio\build\lib\utils\ErrorHandler.js:144:12)

looks like it is not related to this change

@elaihau
Copy link
Contributor

elaihau commented Oct 25, 2018

Akos I stole your 2nd commit #3280 @kittaakos

@kittaakos
Copy link
Contributor Author

looks like it is not related to this change

Yes, a restart helped. Thanks for the review, I am merging this.

@kittaakos kittaakos merged commit 874a9ed into master Oct 28, 2018
@kittaakos kittaakos deleted the GH-3254 branch October 28, 2018 15:20
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.

3 participants