text: const electron = require('electron')
  const url = require('url')
  const path = require('path')
  
  const { app, BrowserWindow, Menu, ipcMain } = electron;
  
  let mainWindow;
  let addWindow;
  
  app.on('ready', function () {
      mainWindow = new BrowserWindow({});
      mainWindow.loadURL(url.format({
          pathname: path.join(__dirname, 'index.html'),
          protocol: 'file:',
          slashes: true
      }));
  
      //Build menu from templdate
      const mainMenu = Menu.buildFromTemplate(mainMenuTemplate);
      Menu.setApplicationMenu(mainMenu);
  
      //Quit app when close
      mainWindow.on('close', function () {
          app.quit();
      })
  })
  
  // Catch item:add
  ipcMain.on('item:add',function(e,item){
      console.log(item);
      mainWindow.webContents.send('item:add',item);
      addWindow.close();
  })
  
  // Handle create add window
  function createAddWindow() {
      addWindow = new BrowserWindow({
          width: 300,
          height: 200
      });
  
      addWindow.loadURL(url.format({
          pathname: path.join(__dirname, 'addWindow.html'),
          protocol: 'file:',
          slashes: true
      }));
  
      addWindow.on('close', function () {
          addWindow = null;
      })
  }
  
  // Create Menu Template
  const mainMenuTemplate = [
      {
          label: 'File',
          submenu: [
              {
                  label: 'Add Item',
                  click() {
                      createAddWindow();
                  }
              },
              {
                  label: 'Clear Items',
                  click(){
                      mainWindow.webContents.send('item:clear')
                  }
              },
              {
                  label: 'Quit',
                  // shortcut
                  accelerator: process.platform == 'darwin' ? 'Command+Q' : 'Ctrl+Q',
                  click() {
                      app.quit();
                  }
              }
          ]
      }
  ];
  
  //if mac, add empty object to menu?
  if (process.platform == 'darwin') {
      mainMenuTemplate.unshift({});
  }
  
  //Add developer tools item if not in prod
  if (process.env.NODE_ENV !== 'production') {
      mainMenuTemplate.push({
          label: 'Developer Tools',
          submenu: [
              {
                  label: 'Toggle DevTools',
                  accelerator: process.platform == 'darwin' ? 'Command+I' : 'Ctrl+I',
                  click(item, focusedWindow) {
                      focusedWindow.toggleDevTools();
                  }
              },
              {
                  role: 'reload'
              }
          ]
      });
  }