In electronJS, I have created a custom application menu in which I'm sending the event from main process to renderer process, but now what happening is where I'm listening this event is running multiple times. So, if anyone could help me to find and resolve the error. Thanks. Here's my code:
label: test,
click: function (item, focusedWindow, event) {
mainWindow.webContents.send('test')
}
ipcRenderer.on('test', (event, action) => {
console.log('called')
})
Now this console.log is printed multiple times.
original code:
{
label: constants.APPLICATION_MENU.ARTICLE.MENU.KEYWORD.LABEL,
accelerator: constants.APPLICATION_MENU.ARTICLE.MENU.KEYWORD.ACCELERATOR,
click: function (item, focusedWindow, event) {
contents.send(constants.APPLICATION_MENU.ARTICLE.MENU.KEYWORD.EVENT)
}
}
created: function () {
ipcRenderer.on(constants.APPLICATION_MENU.ARTICLE.MENU.KEYWORD.EVENT, () => {
console.log('clicked')
})
},
Try using
ipc.removeAllListeners('your_name_channel')
in your closed window function: