|
| 1 | +## Electron - Main Process (desktop/main-app) |
| 2 | + |
| 3 | +To facilitate debugging, we set the reserved _Debug_ configuration with: `--enable-logging` and `--inspect=5859` |
| 4 | + |
| 5 | +* `--enable-logging`: This option will be passed to _Electron_, which will then print its own `debug` logs to the current console |
| 6 | +* `--inspect=5859`: If you prefer to use _Chrome DevTools_ for debugging, then you can listen to this port at `chrome://inspect` for debugging |
| 7 | + |
| 8 | +### WebStorm |
| 9 | + |
| 10 | +We've set up the _Debug Main_ Configurations in _WebStorm_ for you, and you can use it directly to do the _Debug_ |
| 11 | + |
| 12 | +> Note that you should select the `Debug` button, not the `Run` button, as shown in the image below: |
| 13 | +
|
| 14 | +>  |
| 15 | +
|
| 16 | +### vscode |
| 17 | + |
| 18 | +We also set aside configured _Debug Main_ configurations for _vscode_, which you can do in the _Debug_ sidebar of _vscode_. |
| 19 | + |
| 20 | +As shown in the picture: |
| 21 | + |
| 22 | + |
| 23 | + |
| 24 | +### Additional Notes |
| 25 | + |
| 26 | +### `--enable-logging` param |
| 27 | + |
| 28 | +The version of `Electron` we are currently using does not support setting the output location of logs, as this feature was not supported until `Electron v14.0.0`, for which see: [electron/electron#25089](https://github.com/electron/electron/pull/25089) |
| 29 | + |
| 30 | +In the future, when _Flat_ upgrades `Electron` to _14.0.0_ or higher, we will support |
| 31 | + |
| 32 | +### `--inspect=5859` param |
| 33 | + |
| 34 | +If you want to use `Chrome DevTools` for debugging, you can refer to the following procedure: |
| 35 | + |
| 36 | +First you have to make sure you have started _Debug_ and also set a breakpoint before starting it. |
| 37 | + |
| 38 | +When _Debug_ starts, _Node.js_ will listen to port `5859`. In this case, open: `chrome://inspect` in the `Chrome` address bar, like this |
| 39 | + |
| 40 | + |
| 41 | + |
| 42 | +Click: _Open dedicated DevTools for Node_, a `DevTools` window will appear |
| 43 | + |
| 44 | + |
| 45 | + |
| 46 | +Your page may not match mine at this point, please don't worry. Click _Add connection_, enter: `localhost:5859` in the input box, then click _Add_ and you are ready to debug. It looks like the following: |
| 47 | + |
| 48 | + |
| 49 | + |
| 50 | +### `Watch` inconsistency issues |
| 51 | + |
| 52 | +We often need to use the `Watch` function during debugging, but it should be noted that what you _Watch_ The variable may not exist. Because the code executed by _Debug_ is compiled, it is possible that variable names will be overwritten. |
| 53 | + |
| 54 | +But the good news is that it has been found that such variable overrides only affect: `import` statements such as : |
| 55 | + |
| 56 | +* `import runtime from "./Runtime"` => `Runtime_1` |
| 57 | +* `import { app } from "electron""` => `electron_1` |
| 58 | + |
| 59 | +A screenshot can describe the problem more clearly: |
| 60 | + |
| 61 | + |
| 62 | + |
| 63 | +This problem is caused by the compilation of `tsc`', at present, there is no better way to solve it. We can only pay attention to it during operation. |
| 64 | + |
| 65 | +> This is true even if you use `ts-node` as a runtime. Because `ts-node` is essentially a dynamic way to do `tsc` as well. |
0 commit comments