From 48f007ee70a5afaa1170869314d2b50ea6765ba6 Mon Sep 17 00:00:00 2001 From: williamkbentley <38542573+williamkbentley@users.noreply.github.com> Date: Fri, 14 May 2021 13:10:43 -0400 Subject: [PATCH] Snap launch (#58) * Added debugging configuration * WIP * Auto open bim when passed as arg --- .vscode/launch.json | 48 +++++++++++------------- .vscode/tasks.json | 35 +++++++++++++++++ README.md | 5 +++ package.json | 5 ++- src/backend/main.ts | 4 +- src/frontend/components/AppComponent.tsx | 2 +- 6 files changed, 67 insertions(+), 32 deletions(-) create mode 100644 .vscode/tasks.json diff --git a/.vscode/launch.json b/.vscode/launch.json index cb67098..8f3377d 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -3,49 +3,43 @@ // Hover to view descriptions of existing attributes. // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 "version": "0.2.0", - "compounds": [ - { - "name": "Electron", - "configurations": [ - "Main", - "Renderer" - ] - } - ], "configurations": [ { - "name": "Main", - "presentation": { - "hidden": true - }, + "name": "Electron: Main", "type": "pwa-node", "request": "launch", + "cwd": "${workspaceFolder}", + "console": "internalConsole", + "outputCapture": "std", "runtimeExecutable": "${workspaceFolder}/node_modules/.bin/electron", "runtimeArgs": [ - "${workspaceFolder}/lib/backend/main.js", + "lib/backend/main.js", "--remote-debugging-port=9223" ], "env": { "NODE_ENV": "development" }, - "autoAttachChildProcesses": false, - "attachSimplePort": 0, - "outputCapture": "std", - "cascadeTerminateToConfigurations": [ - "Renderer" - ] - }, - { - "name": "Renderer", "presentation": { - "hidden": true + "group": "desktop-starter" }, + }, + { + "name": "Electron: Renderer", "type": "pwa-chrome", "request": "attach", "port": 9223, - "webRoot": "${workspaceFolder}/build/", - "cascadeTerminateToConfigurations": [ - "Main" + "timeout": 30000, + "presentation": { + "group": "desktop-starter" + }, + }, + ], + "compounds": [ + { + "name": "Electron: All", + "configurations": [ + "Electron: Main", + "Electron: Renderer" ] } ] diff --git a/.vscode/tasks.json b/.vscode/tasks.json new file mode 100644 index 0000000..44e9eed --- /dev/null +++ b/.vscode/tasks.json @@ -0,0 +1,35 @@ +{ + "version": "2.0.0", + "tasks": [ + { + "type": "npm", + "script": "watch:backend", + "problemMatcher": [ + "$tsc-watch" + ], + "presentation": { + "group": "desktop-starter" + }, + "label": "watch:backend", + }, + { + "type": "npm", + "script": "start:frontend", + "problemMatcher": [ + "$tsc" + ], + "presentation": { + "group": "desktop-starter" + }, + "label": "start:frontend", + }, + { + "label": "Watch All", + "dependsOn": [ + "watch:backend", + "start:frontend" + ], + "problemMatcher": [] + }, + ] +} diff --git a/README.md b/README.md index 2672f1f..dfe17f7 100644 --- a/README.md +++ b/README.md @@ -12,6 +12,11 @@ See for comprehensive documentation on the iTwin.js API an To build and run this application, just follow our [step-by-step tutorial.](https://www.itwinjs.org/learning/tutorials/develop-desktop-viewer/) +## Debugging + +1. In VS Code, select Terminal -> Run Task..., and pick "Watch All" +1. Launch the VS Code debugger with configuration "Electron: All" + ## Contributing [Contributing to iTwin.js](https://github.com/imodeljs/imodeljs/blob/master/CONTRIBUTING.md) diff --git a/package.json b/package.json index e279225..aa520d4 100644 --- a/package.json +++ b/package.json @@ -19,6 +19,7 @@ "scripts": { "build": "run-p build:backend build:frontend copy", "build:backend": "tsc -p tsconfig.backend.json", + "watch:backend": "tsc -p tsconfig.backend.json --watch", "build:frontend": "cross-env DISABLE_ESLINT=true GENERATE_SOURCEMAP=false USE_FAST_SASS=true TRANSPILE_DEPS=false DISABLE_TERSER=true react-scripts build", "clean": "rimraf lib build dist", "copy": "npm run copy:assets && npm run copy:enUS", @@ -27,8 +28,8 @@ "electron": "electron lib/backend/main.js", "electron:debug": "cross-env NODE_ENV=development electron lib/backend/main.js", "lint": "eslint --config package.json --no-eslintrc \"./src/**/*.{ts,tsx}\" 1>&2", - "start": "npm run build:backend && run-p \"start:frontend\" \"electron\"", - "start:frontend": "cross-env BROWSER=none DISABLE_ESLINT=true USE_FAST_SASS=true TRANSPILE_DEPS=false react-scripts start", + "start": "npm run build:backend && run-p \"start:frontend\" \"electron:debug\"", + "start:frontend": "cross-env USE_FULL_SOURCEMAPS=true USE_FAST_SASS=true BROWSER=none react-scripts start", "build:pack": "electron-builder --dir", "build:dist": "electron-builder" }, diff --git a/src/backend/main.ts b/src/backend/main.ts index 0fa5e4d..aaf67a7 100644 --- a/src/backend/main.ts +++ b/src/backend/main.ts @@ -22,9 +22,9 @@ const getAppEnvVar = (varName: string): string | undefined => process.env[`${app class DesktopStarterHandler extends IpcHandler implements DesktopStarterInterface { public get channelName() { return desktopStarterChannel; } public async getConfig(): Promise { - // first two arguments are .exe name and the path to ViewerMain.js. Skip them. + // first two arguments are .exe name and the path to main.js. Skip them. const parsedArgs = process.env.NODE_ENV === "development" - ? minimist(process.argv.slice(2 + process.argv.findIndex((a: string) => a.includes("main.js")))) + ? minimist(process.argv.slice(1 + process.argv.findIndex((a: string) => a.includes("main.js")))) : minimist(process.argv.slice(1)); const samplePath = ElectronHost.app.isPackaged diff --git a/src/frontend/components/AppComponent.tsx b/src/frontend/components/AppComponent.tsx index 97d32fd..4e0e5f7 100644 --- a/src/frontend/components/AppComponent.tsx +++ b/src/frontend/components/AppComponent.tsx @@ -68,7 +68,7 @@ export default class AppComponent extends React.Component<{}, AppState> { isOpening: false, }; - this._autoOpenConfig = { snapshotName: null, contextId: null, imodelId: null }; + this._autoOpenConfig = { snapshotName: App.config.snapshotName ?? null, contextId: null, imodelId: null }; this._isAutoOpen = true; this._wantSnapshot = true;