The application uses Electron's ipcMain to facilitate communication between the main process and the renderer processes (the main window and background windows).
Background Task Orchestration
To manage heavy computations or background tasks, the main process listens for specific events to route messages between the UI (mainWindow) and worker windows (backgroundWindows):
background-start: Receives a payload and sends it to the first available (not busy) background window using webContents.send('background-start', payload). The background window is marked as isBusy = true.background-response: When a background window responds, the main process forwards the payload to the mainWindow via webContents.send('background-response', payload) and marks the background window as isBusy = false.background-progress: Forwards progress updates from background windows directly to the mainWindow via webContents.send('background-progress', payload).background-stop: Destroys all current background windows and restarts the background window creation cycle.
Application State Events
login-success: Forwards login payloads from the renderer to the mainWindow.purchase-success: Forwards a purchase confirmation signal to the mainWindow.
// Example of how the main process handles background task starts
ipcMain.on('background-start', function(event, payload){
for(var i=0; i<backgroundWindows.length; i++){
if(backgroundWindows[i] && !backgroundWindows[i].isBusy){
backgroundWindows[i].isBusy = true;
backgroundWindows[i].webContents.send('background-start', payload);
break;
}
}
});