electron-window-manager icon indicating copy to clipboard operation
electron-window-manager copied to clipboard

How to handle duplicate ipcMain.on methods after multiple Windows of the same instance?

Open yyccQQu opened this issue 2 years ago • 0 comments

at renderer code

let { dialog, app } = remote;
ipcRenderer.send("close-win", "111");

at main code

ipcMain.on("close-win", (e, arg) => {
  console.log('win: ', arg)
})

when i use this method create more windows, There are four Windows, and as soon as the close-win of one of them is triggered, the close-win receive of the main process is repeated four times

function createWindow(mainWindow, devPath = "", prodPath = "index.html", winNum) {
   winNum++
   mainWindow = windowManager.createNew(
        multipleName,
        multipleName,
        winURL,
        false,
        winObj,
        isDev
    );
  mainWindow.create();
}


let mainWindowF;
createWindow(mainWindowF)

Result the main code result is

win:  111
win:  111
win:  111
win:  111

But I only want to trigger it once.

yyccQQu avatar Jun 13 '22 13:06 yyccQQu