Getting reference to main window from imported module


#1

I have my menu template defined in a separate menu.js file that gets imported into main.js as a module

However the click functionality of some of the menu items require calling methods directly on the window object (mainWindow is the name of my BrowserWindow object):

{
    label: 'Maximize',
    accelerator: 'CmdOrCtrl+Shift+M',
    click: function () {
        mainWindow.maximize();
    }
}

These menu items given an error when clicked because mainWindow is not defined anywhere in the module. How do I get a reference to the window object from within an imported module like this?


#2

The click handler is called with two arguments; the MenuItem and the BrowserWindow; e.g.

click: function (menuItem, mainWindow) {
  mainWindow.maximize();
}