Skip to content

Commit

Permalink
Set product name for Electron example app.
Browse files Browse the repository at this point in the history
- 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 <[email protected]>
  • Loading branch information
mcgordonite authored and thegecko committed Mar 5, 2020
1 parent 3d5e4f9 commit 42b73d5
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 2 deletions.
3 changes: 2 additions & 1 deletion .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
2 changes: 2 additions & 0 deletions examples/electron/package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down

0 comments on commit 42b73d5

Please sign in to comment.