76 lines
1.7 KiB
Markdown
76 lines
1.7 KiB
Markdown
---
|
||
title: Electron
|
||
tags:
|
||
- electron
|
||
- desktop
|
||
---
|
||
|
||
# Electron
|
||
|
||
## Overview
|
||
|
||
Electron 34 wraps the Showy backend + frontend into a standalone desktop application for Windows.
|
||
|
||
## Architecture
|
||
|
||
```mermaid
|
||
graph TD
|
||
E[Electron Main Process] --> |child_process.spawn| B[Node.js Backend]
|
||
E --> |BrowserWindow.loadFile| FE[Frontend Build]
|
||
FE --> |HTTP requests| B
|
||
E --> |IPC: backend-ready| FE
|
||
```
|
||
|
||
## Main Process — `electron/main.js`
|
||
|
||
1. Spawns backend as a **child process**: `node backend/server.js`
|
||
2. Sets `PARENT_PROCESS` env var pointing to Electron user data path
|
||
3. Backend auto-restarts if it crashes
|
||
4. Creates `BrowserWindow` (1200×720) loading `frontend_build/browser/index.html`
|
||
5. Sends `backend-ready` IPC event when backend starts listening
|
||
6. On window close → kills backend child process
|
||
|
||
### Window Configuration
|
||
|
||
| Setting | Value |
|
||
|---|---|
|
||
| Width | 1200 |
|
||
| Height | 720 |
|
||
| Context Isolation | `true` |
|
||
| Sandbox | `true` |
|
||
| Node Integration | `true` |
|
||
|
||
## Preload Script — `electron/preload.js`
|
||
|
||
Exposes `electron.ipcRenderer` to the renderer process via `contextBridge.exposeInMainWorld`:
|
||
|
||
- `send(channel, data)` — send to main
|
||
- `on(channel, callback)` — listen from main
|
||
|
||
## Build Configuration
|
||
|
||
| Field | Value |
|
||
|---|---|
|
||
| `appId` | `x4lo.showy` |
|
||
| Target | Windows x64 directory output |
|
||
| Icon | From Angular frontend assets |
|
||
|
||
## Package Dependencies
|
||
|
||
- `electron` 34
|
||
- `electron-builder` 25
|
||
- All backend dependencies (bundled)
|
||
|
||
## Important Files
|
||
|
||
| File | Role |
|
||
|---|---|
|
||
| `electron/main.js` | Main process entry |
|
||
| `electron/preload.js` | Context bridge for IPC |
|
||
| `electron/package.json` | Electron + backend deps |
|
||
|
||
## See Also
|
||
|
||
- [[Architecture]] — System overview
|
||
- [[Deployment]] — Docker alternative
|