Skip to content

Using IPC (Inter Process Communication)

Sim edited this page Dec 26, 2021 · 3 revisions

Electron applications are divided into two parts: the main process and the renderer process(es).

Renderer Processes

The renderer processes run our BrowserWindows, i.e. our client code (HTML, CSS and client JavaScript).

Renderer processes do not have access to Node.js APIs, but can run JavaScript just like any other real browser, and can fetch data from external APIs, for example.

The launcher client code is contained in the src/fsolauncher_ui folder, mainly in the fsolauncher_ui/client.js file.

Main Process

The main process, however, does have access to Node.js, and is essentially the Node.js backend for these renderer processes. All filesystem operations and anything needing Node.js APIs (and Node.js module dependencies) will be done here.

The launcher main code starts in main.js, and the rest is in the src/fsolauncher folder.

Using IPC

Renderer and main processes communicate with each other using IPC (Inter-process Communication), with JavaScript object payloads.

Sending from main to renderer

  • In the launcher’s main process, the src/fsolauncher/library/ipc-bridge.js file is used to send messages to the renderer (client).
  • In the launcher’s renderer process (client.js), the onMessage function is used to receive these messages.

Sending from renderer to main

  • In the launcher’s renderer process (client.js), the sendToMain function is used to send messages to the main process.
  • In the launcher’s main process, the src/fsolauncher/event-handlers.js file is used to receive these messages.