## Notes
- Each Electron app has a single *main process*
- The *main process*' primary purpose is to create and manage application windows with `BrowserModule`
- Each instance of the `BrowserWindow` class creates an application window that loads a web page in a separate renderer process
- Also has *Native APIs* to interact with the operating system
### Preload Scripts
- Preload scripts contain code that executes in a renderer process before its web content begins loading
- A preload script can be attached to the main process in the `BrowserWindow` constructor's `webPreferences` option.
```JavaScript
const { BrowserWindow } = require('electron')
// ...
const win = new BrowserWindow({
webPreferences: {
preload: 'path/to/preload.js'
}
})
// ...
```
- There's context isolation
- Use `contextBridge`
## IPC Patterns
### Pattern 1 - Renderer to Main (one way)
### ## Pattern 2 - Renderer to Main (two-way)
- [`ipcRenderer.invoke`](https://www.electronjs.org/docs/latest/api/ipc-renderer#ipcrendererinvokechannel-args) paired with [`ipcMain.handle`](https://www.electronjs.org/docs/latest/api/ipc-main#ipcmainhandlechannel-listener).
- In the following example, we'll be opening a native file dialog from the renderer process and returning the selected file's path.