Change dark mode using main.js electron

Building a simple electron application following a beginners tutorial and trying to control dark mode appearance through a menu checkbox using the main process.

const template = [{
  label: 'Préférences',
  submenu: [{
      label: 'Mode nuit',
      id: 'mode',
      type: 'checkbox',
      click: () => function(menuItem) {
        if (menuItem.checked) {
          mainWindow.setBackgroundColor('black');
          mainWindow.setColor('white');
        } else {
          mainWindow.setBackgroundColor('white');
          mainWindow.setColor('black');
        }
      }
    },
    {
      type: 'separator'
    },
    {
      label: 'Police',
      submenu: [{
          label: 'Petit',
          type: 'radio'
        },
        {
          label: 'Moyen',
          type: 'radio'
        },
        {
          label: 'Grand',
          type: 'radio'
        }

      ]
    }
  ]
}];

It is not working. Is it possible to do it this way or should I modify the renderer process?