Electron .ipcRenderer received message twice


#1

I’m creating (for the first time) a small Mac only app using Electron. I am trying to use ipcRenderer to communicate between my app menu and the content in the main BrowserWindow.

I have the menu set up as follows to send the message ‘select-active’:

const {Menu} = require('electron')
const electron = require('electron')
const app = electron.app
const BrowserWindow = electron.BrowserWindow

const template = [
{
label: 'Fonts',
submenu: [
    {
        label: 'Select All Acitve Fonts',
        accelerator: 'Command+A',
        click (item, focusedWindow) { if(focusedWindow) focusedWindow.webContents.send('select-active') }
    },...

which I am then receiving as follows:

const ipcRenderer = require('electron').ipcRenderer;

ipcRenderer.on('select-active', function () {
    console.log('SELECTED');
})

The problem I have is that every time the menu command is selected the message is logged twice in the console. Where am I going wrong? Any help would be appreciated.


#2

What happens when you use this click handler instead? Do you see clicked printed once or twice in the console?