From 42b73d5a84f7335b722c7decad24d8069dfc3722 Mon Sep 17 00:00:00 2001 From: Matthew Gordon Date: Wed, 26 Feb 2020 14:17:20 +0000 Subject: [PATCH] Set product name for Electron example app. - Added main and productName entries to the example package.json. - When starting the app with `theia start` or from the vscode launch configurations, pass the example directory rather than the electron-main script if possible. This means that an IDE developer can work on multiple Theia applications on the same machine without them sharing local storage. Signed-off-by: Matthew Gordon --- .vscode/launch.json | 3 ++- .../src/application-package-manager.ts | 16 +++++++++++++++- examples/electron/package.json | 2 ++ 3 files changed, 19 insertions(+), 2 deletions(-) diff --git a/.vscode/launch.json b/.vscode/launch.json index 825f002eca906..5a5a5af3b346e 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -24,9 +24,10 @@ "windows": { "runtimeExecutable": "${workspaceRoot}/node_modules/.bin/electron.cmd" }, - "program": "${workspaceRoot}/examples/electron/src-gen/frontend/electron-main.js", + "cwd": "${workspaceRoot}/examples/electron", "protocol": "inspector", "args": [ + ".", "--log-level=debug", "--hostname=localhost", "--no-cluster", diff --git a/dev-packages/application-manager/src/application-package-manager.ts b/dev-packages/application-manager/src/application-package-manager.ts index 318ea866e313f..976fd127f6cc2 100644 --- a/dev-packages/application-manager/src/application-package-manager.ts +++ b/dev-packages/application-manager/src/application-package-manager.ts @@ -78,7 +78,21 @@ export class ApplicationPackageManager { } startElectron(args: string[]): cp.ChildProcess { - const { mainArgs, options } = this.adjustArgs([this.pck.frontend('electron-main.js'), ...args]); + // If possible, pass the project root directory to electron rather than the script file so that Electron + // can determine the app name. This requires that the package.json has a main field. + let appPath = this.pck.projectPath; + + if (!this.pck.pck.main) { + appPath = this.pck.frontend('electron-main.js'); + + console.warn( + `WARNING: ${this.pck.packagePath} does not have a "main" entry.\n` + + 'Please add the following line:\n' + + ' "main": "src-gen/frontend/electron-main.js"' + ); + } + + const { mainArgs, options } = this.adjustArgs([ appPath, ...args ]); const electronCli = require.resolve('electron/cli.js', { paths: [this.pck.projectPath] }); return this.__process.fork(electronCli, mainArgs, options); } diff --git a/examples/electron/package.json b/examples/electron/package.json index c322cac083846..3ca6031654259 100644 --- a/examples/electron/package.json +++ b/examples/electron/package.json @@ -1,7 +1,9 @@ { "private": true, "name": "@theia/example-electron", + "productName": "Theia Electron Example", "version": "0.16.0", + "main": "src-gen/frontend/electron-main.js", "license": "EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0", "theia": { "target": "electron",