Multiple window ipc architecture

I am planing to build a software with electron which should have many different windows. I already read in a book and the documentation to get familiar with the ipc module and how it works.

This concept works for me, with a manageable number of windows but even more windows my application gets even more confusing it becomes.

I am also new to javascript and Prototype-based object-oriented programming

I am trying to image how could i build a large software without loosing the overview.

Here is one ipc example from my main.js, preload.js and renderer.js
to show how i build up a simple IPC example:


ipc.on('open-directory-dialog', function (event) {
  dialog.showOpenDialog(mainWindow, {
    title: 'Select a image...',
    properties: ['openFile'],
    defaultPath: '/home',
    buttonLabel: "Select...",
    filters: [
    { name: 'Images', extensions: ['jpg', 'png', 'gif'] }
    }, function (files) {
      if (files) event.sender.send('selectedItem', files)


window.ipcFiledialog = function (channel) {

ipcRenderer.on('selectedItem', function (event, path) {


selectDirBtn.addEventListener('click', function (event) {

function setSelectedItem (files) {
    document.getElementById('selectedItem').innerHTML = files

With this approach i have to create every window in main.js (this will grow the main.js) and make sure i call a specific ipc method for the right window.
The callback method needs to call also a specific method for every window.

So i would need many methods and this construct does not look very flexible.

Is there any best practice to prevent main.js and preload.js to grow into the “infinite” and get more flexible ipc methods ?