var Menu = require('menu');
var MenuItem = require('menu-item');

module.exports = {
  setup: function (app, host) {
    var name = app.getName();
    var template = [{
      label: name,
      submenu: [
        {
          label: 'About ' + name,
          role: 'about'
        },
        {
          type: 'separator'
        },
        {
          label: 'Services',
          role: 'services',
          submenu: []
        },
        {
          type: 'separator'
        },
        {
          label: 'Hide ' + name,
          accelerator: 'Command+H',
          role: 'hide'
        },
        {
          label: 'Hide Others',
          accelerator: 'Command+Alt+H',
          role: 'hideothers'
        },
        {
          label: 'Show All',
          role: 'unhide'
        },
        {
          type: 'separator'
        },
        {
          label: 'Quit',
          accelerator: 'Command+Q',
          click: function() { app.quit(); }
        },
      ]
    },
    {
      label: 'Edit',
      submenu: [
        {
          label: 'Undo',
          accelerator: 'CmdOrCtrl+Z',
          role: 'undo'
        },
        {
          label: 'Redo',
          accelerator: 'Shift+CmdOrCtrl+Z',
          role: 'redo'
        },
        {
          type: 'separator'
        },
        {
          label: 'Cut',
          accelerator: 'CmdOrCtrl+X',
          role: 'cut'
        },
        {
          label: 'Copy',
          accelerator: 'CmdOrCtrl+C',
          role: 'copy'
        },
        {
          label: 'Paste',
          accelerator: 'CmdOrCtrl+V',
          role: 'paste'
        },
        {
          label: 'Select All',
          accelerator: 'CmdOrCtrl+A',
          role: 'selectall'
        },
      ]
    },
    {
      label: 'View',
      submenu: [
        {
          label: 'Reload',
          accelerator: 'CmdOrCtrl+R',
          click: function(item, focusedWindow) {
            focusedWindow.webContents.reloadIgnoringCache();
          }
        },
        {
          label: 'Toggle Full Screen',
          accelerator: (function() {
            if (process.platform == 'darwin') {
              return 'Ctrl+Command+F';
            } else {
              return 'F11';
            }
          })(),
          click: function(item, focusedWindow) {
            if (focusedWindow) {
              focusedWindow.setFullScreen(!focusedWindow.isFullScreen());
            }
          }
        },
        {
          label: 'Toggle Developer Tools',
          accelerator: (function() {
            if (process.platform == 'darwin') {
              return 'Command+Alt+I';
            } else {
              return 'Ctrl+Shift+I';
            }
          })(),
          click: function(item, focusedWindow) {
            if (focusedWindow) {
              focusedWindow.toggleDevTools();
            }
          }
        },
      ]
    },
    {
      label: 'History',
      id: 'history',
      submenu: [
        {
          label: 'Back',
          accelerator: 'CmdOrCtrl+[',
          enabled: false,
          id: 'backMenu',
          click: function (item, focusedWindow) {
            focusedWindow.webContents.goBack();
          }
        },
        {
          label: 'Forward',
          accelerator: 'CmdOrCtrl+]',
          enabled: false,
          id: 'fwdMenu',
          click: function (item, focusedWindow) {
            focusedWindow.webContents.goForward();
          }
        },
      ]
    },
    {
      label: 'Window',
      role: 'window',
      submenu: [
        {
          label: 'Minimize',
          accelerator: 'CmdOrCtrl+M',
          role: 'minimize'
        },
        {
          label: 'Close',
          accelerator: 'CmdOrCtrl+W',
          role: 'close'
        },
        {
          type: 'separator'
        },
        {
          label: 'Bring All to Front',
          role: 'front'
        },
      ]
    },
    {
      label: 'Help',
      role: 'help',
      submenu: [
        {
          label: 'Github Repository',
          click: function() {
            require('electron').shell.openExternal('https://github.com/irccloud/irccloud-desktop');
          }
        },
      ]
    }];

    var menu = Menu.buildFromTemplate(template);
    Menu.setApplicationMenu(menu);
    return menu;
  }
};

@@ -279,32 +279,288 @@
    %7D,%0A        %7B%0A
+          label: 'Open in Browser',%0A          click: function(item, focusedWindow) %7B%0A            var url = focusedWindow ? focusedWindow.webContents.getURL() : host;%0A            require('electron').shell.openExternal(url);%0A          %7D%0A        %7D,%0A        %7B%0A
           type: 
@@ -563,32 +563,32 @@
 pe: 'separator'%0A
-
         %7D,%0A     
@@ -1187,19 +1187,50 @@
 unction(
-) %7B
+item, focusedWindow) %7B%0A           
  app.qui
@@ -1233,16 +1233,26 @@
 .quit();
+%0A         
  %7D%0A     
@@ -2199,32 +2199,67 @@
 ocusedWindow) %7B%0A
+            if (focusedWindow) %7B%0A  
             focu
@@ -2299,24 +2299,38 @@
 ingCache();%0A
+            %7D%0A
           %7D%0A
@@ -3464,32 +3464,67 @@
 ocusedWindow) %7B%0A
+            if (focusedWindow) %7B%0A  
             focu
@@ -3551,24 +3551,38 @@
 s.goBack();%0A
+            %7D%0A
           %7D%0A
@@ -3761,32 +3761,67 @@
 ocusedWindow) %7B%0A
+            if (focusedWindow) %7B%0A  
             focu
@@ -3851,24 +3851,38 @@
 oForward();%0A
+            %7D%0A
           %7D%0A
@@ -4455,24 +4455,24 @@
 epository',%0A
-
           cl
@@ -4477,32 +4477,51 @@
 click: function(
+item, focusedWindow
 ) %7B%0A            

Add Open in browser menu item