https://github.com/gbenm/ipc-shell
A wrapper for IPC objects
https://github.com/gbenm/ipc-shell
electron electronjs ipc
Last synced: 4 months ago
JSON representation
A wrapper for IPC objects
- Host: GitHub
- URL: https://github.com/gbenm/ipc-shell
- Owner: gbenm
- License: mit
- Created: 2021-10-20T17:19:05.000Z (over 4 years ago)
- Default Branch: main
- Last Pushed: 2022-02-07T01:17:36.000Z (over 4 years ago)
- Last Synced: 2026-02-27T04:34:14.096Z (4 months ago)
- Topics: electron, electronjs, ipc
- Language: TypeScript
- Homepage: https://gbenm.github.io/ipc-shell/
- Size: 31.2 MB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# IPC Shell
Vea la [página](https://gbenm.github.io/ipc-shell/) para más información.
Es una envoltura para objetos que realizan la comunicación
entre procesos, en el estado inicial, está configurado para
funcionar con los IPC de [electron](https://www.electronjs.org/),
este comportamiento puede cambiar sobreescribiendo las funciones
`_getArgsFromOn` e `_ipcNodeSend`.
## Como usar
Importe `IPCNodeRegister` y registre el IPC:
```typescript
import { ipcMain } from "electron";
import { IPCNodeRegister } from "ipc-shell"
const ipc = IPCNodeRegister.register("main", ipcMain)
```
**Nota: se usará `IpcMain` como el tipo de IPC, si
fuera para el `ipcRenderer` debería usar `IpcRenderer`,
para el ipc de `win.webContents` debería usar `WebContents`,
hablando en términos de electronjs, en general usar
la clase del IPC que registra.**
Note que ahora `ipc` fue extendido. Colocando el tipo sería
de la siguiente forma (por la inferencia de tipos lo de arriba
está bien):
```typescript
import { IpcMain, ipcMain } from "electron";
import { IPCNode, IPCNodeRegister } from "ipc-shell"
const ipc: IPCNode = IPCNodeRegister.register("main", ipcMain)
```
A partir de ahora puede acceder en el mismo proceso a este
IPC mediante su nombre:
```typescript
// somewhere else
import { IpcMain } from "electron";
import { IPCNodeRegister } from "ipc-shell"
// using generic type (recommended)
const ipc = IPCNodeRegister.get("main");
// using IPCNode type (import from ipc-shell)
const ipc: IPCNode = IPCNodeRegister.get("main");
```
El hecho de que se agregue `IpcMain` es para que pueda
seguir utilizando todos lo métodos y variables que este
contenga más los extras, si no agrega el tipo únicamente
podrá usar los de `IPCNode`.
## Disclaimer
- This package use `Object.assign()`.
- All in the `IPCBaseNode` interface is overwritten when it extends.