import { app, Menu } from 'electron';

export default win => {
  const viewMenu = () => ({
    label: 'View',
    submenu: [
      { role: 'togglefullscreen' },
      ...(process.env.NODE_ENV === 'development' ? [
        { role: 'reload' },
        { role: 'toggledevtools' },
      ] : []),
    ],
  });

  const goMenu = () => ({
    label: 'Go',
    submenu: [
      {
        label: 'Back',
        accelerator: 'Alt+Left',
        click: () => win.webContents.goBack(),
      },
      {
        label: 'Forward',
        accelerator: 'Alt+Right',
        click: () => win.webContents.goForward(),
      },
    ],
  });

  const template = [
    { role: 'editMenu' },
    viewMenu(),
    ...(process.env.NODE_ENV === 'development' ? [goMenu()] : []),
    { role: 'windowMenu' },
  ];

  if (process.platform === 'darwin') {
    template.unshift({
      label: app.getName(),
      submenu: [
        { role: 'about' },
        { type: 'separator' },
        { role: 'hide' },
        { role: 'hideothers' },
        { role: 'unhide' },
        { type: 'separator' },
        { role: 'quit' },
      ],
    });
  }

  const menu = Menu.buildFromTemplate(template);

  return menu;
};

@@ -11,16 +11,26 @@
 pp, Menu
+, MenuItem
  %7D from 
@@ -46,58 +46,472 @@
 ';%0A%0A
-export default win =%3E %7B%0A  const viewMenu = () =%3E (
+function getDefaultSubmenu(role) %7B%0A  return new MenuItem(%7B role %7D).submenu.items%0A    .map(menuItem =%3E (%7B role: menuItem.role, type: menuItem.type %7D));%0A%7D%0A%0Aexport default win =%3E %7B%0A  const template = %5B%5D;%0A%0A  if (process.platform === 'darwin') %7B%0A    const appMenu = %7B%0A      label: app.getName(),%0A      submenu: getDefaultSubmenu('appMenu'),%0A    %7D;%0A    template.push(appMenu);%0A  %7D%0A%0A  const editMenu = %7B role: 'editMenu' %7D;%0A  template.push(editMenu);%0A%0A  const viewMenu = 
 %7B%0A  
@@ -712,36 +712,112 @@
  %5B%5D),%0A    %5D,%0A  %7D
-);%0A%0A
+;%0A  template.push(viewMenu);%0A%0A  if (process.env.NODE_ENV === 'development') %7B%0A  
   const goMenu =
@@ -821,17 +821,12 @@
 u = 
-() =%3E (
 %7B%0A
+  
     
@@ -838,24 +838,26 @@
 : 'Go',%0A    
+  
 submenu: %5B%0A 
@@ -857,26 +857,30 @@
 nu: %5B%0A      
+ 
+ 
 %7B%0A
+  
         labe
@@ -890,32 +890,34 @@
 'Back',%0A        
+  
 accelerator: 'Al
@@ -921,24 +921,26 @@
 'Alt+Left',%0A
+  
         clic
@@ -976,27 +976,31 @@
 ck(),%0A      
+  
 %7D,%0A
+  
       %7B%0A    
@@ -995,32 +995,34 @@
       %7B%0A        
+  
 label: 'Forward'
@@ -1023,16 +1023,18 @@
 rward',%0A
+  
         
@@ -1059,32 +1059,34 @@
 Right',%0A        
+  
 click: () =%3E win
@@ -1113,27 +1113,31 @@
 rd(),%0A      
+ 
+ 
 %7D,%0A
+  
     %5D,%0A  %7D);
@@ -1137,20 +1137,16 @@
 ,%0A  
+ 
+ 
 %7D
-)
 ;%0A
-%0A
+ 
   
-const
  tem
@@ -1154,484 +1154,101 @@
 late
- = %5B%0A    %7B role: 'editMenu' %7D,%0A    viewMenu(),%0A    ...(process.env.NODE_ENV === 'development' ? %5BgoMenu()%5D : %5B%5D),%0A    %7B role: 'windowMenu' %7D,%0A  %5D;%0A%0A  if (process.platform === 'darwin') %7B%0A    template.unshift(%7B%0A      label: app.getName(),%0A      submenu: %5B%0A        %7B role: 'about' %7D,%0A        %7B type: 'separator' %7D,%0A        %7B role: 'hide' %7D,%0A        %7B role: 'hideothers' %7D,%0A        %7B role: 'unhide' %7D,%0A        %7B type: 'separator' %7D,%0A        %7B role: 'quit' %7D,%0A      %5D,%0A    %7D);%0A  %7D
+.push(goMenu);%0A  %7D%0A%0A  const windowMenu = %7B role: 'windowMenu' %7D;%0A  template.push(windowMenu);
 %0A%0A  

Refactor menu template