|
| 1 | +--- |
| 2 | +# SPDX-FileCopyrightText: Simon Schneegans <[email protected]> |
| 3 | +# SPDX-License-Identifier: CC-BY-4.0 |
| 4 | + |
| 5 | +title: Debugging |
| 6 | +description: How to debug Kando. |
| 7 | +sidebar: |
| 8 | + order: 4 |
| 9 | +--- |
| 10 | + |
| 11 | +import { LinkButton } from '@astrojs/starlight/components'; |
| 12 | +import Intro from '../../components/Intro.astro'; |
| 13 | +import CustomAside from '../../components/CustomAside.astro'; |
| 14 | +import {Image} from 'astro:assets'; |
| 15 | + |
| 16 | +import vscodeDebugging from '../../assets/img/debugging.png'; |
| 17 | + |
| 18 | + |
| 19 | + |
| 20 | +<Intro> |
| 21 | +If you want to 💡 **understand Kando's code base** or fix an especially 🐛 **nasty bug**, using a debugger is a great idea. |
| 22 | +</Intro> |
| 23 | + |
| 24 | +However, debugging an Electron application is not exactly straightforward. |
| 25 | +This is because Electron applications consist of two parts: the main process and the renderer processes. |
| 26 | + |
| 27 | +The main process is responsible for managing the application lifecycle and has access to the operating system. |
| 28 | +The renderer processes are responsible for rendering the user interface and are more or less isolated from the operating system. |
| 29 | +Kando has one main process and two renderer processes: one for the menu and one for the settings dialog. |
| 30 | + |
| 31 | +## Debugging in VSCode |
| 32 | + |
| 33 | +If you are using [Visual Studio Code](https://code.visualstudio.com/), you can set up debugging by creating a `.vscode/launch.json` file in your project directory. |
| 34 | +Put the following content into that file: |
| 35 | + |
| 36 | +```json5 title=".vscode/launch.json" |
| 37 | +{ |
| 38 | + "configurations": [ |
| 39 | + { |
| 40 | + "type": "node", |
| 41 | + "request": "launch", |
| 42 | + "name": "Kando: Main Process", |
| 43 | + "runtimeExecutable": "${workspaceRoot}/node_modules/.bin/tsx", |
| 44 | + "runtimeArgs": [ |
| 45 | + "node_modules/@electron-forge/cli/src/electron-forge-start", |
| 46 | + "--", |
| 47 | + "--remote-debugging-port=9223" |
| 48 | + ], |
| 49 | + "autoAttachChildProcesses": true, |
| 50 | + "internalConsoleOptions": "openOnFirstSessionStart", |
| 51 | + "console": "integratedTerminal" |
| 52 | + }, |
| 53 | + { |
| 54 | + "name": "Kando: Renderer Processes", |
| 55 | + "type": "chrome", |
| 56 | + "request": "attach", |
| 57 | + "port": 9223, |
| 58 | + "webRoot": "${workspaceFolder}", |
| 59 | + "timeout": 30000 |
| 60 | + } |
| 61 | + ], |
| 62 | + "compounds": [ |
| 63 | + { |
| 64 | + "name": "Kando: All", |
| 65 | + "configurations": ["Kando: Main Process", "Kando: Renderer Processes"] |
| 66 | + } |
| 67 | + ] |
| 68 | +} |
| 69 | +``` |
| 70 | + |
| 71 | +Once this is in place, you can start debugging Kando by selecting the "Kando: All" configuration in the debug panel and clicking the green play button. |
| 72 | +This will start the main process and attach the debugger to both the main process and the renderer processes. |
| 73 | +You can then set breakpoints in your code and inspect variables! |
| 74 | + |
| 75 | +<center> |
| 76 | +<Image src={vscodeDebugging} alt="debugging in VSCode" class="shadow"/> |
| 77 | +</center> |
| 78 | + |
| 79 | +## Other IDEs |
| 80 | + |
| 81 | +Have you successfully set up debugging in another IDE? |
| 82 | +Let us know by editing this page! |
| 83 | +You can also join our [Discord server](https://discord.gg/hZwbVSDkhy) and discuss it there. |
0 commit comments