text: import R from 'ramda'
  import { app, BrowserWindow, Menu, shell, dialog } from 'electron';
  
  let menu;
  let template;
  let mainWindow = null;
  
  global.dirty = {
    catalog:   false,
    whitelist: false
  };
  
  if (process.env.NODE_ENV === 'development') {
    require('electron-debug')(); // eslint-disable-line global-require
  }
  
  
  app.on('window-all-closed', () => {
    // if (process.platform !== 'darwin')
    app.quit();
  });
  
  
  const installExtensions = async () => {
    if (process.env.NODE_ENV === 'development') {
      const installer = require('electron-devtools-installer'); // eslint-disable-line global-require
  
      const extensions = [
        'REACT_DEVELOPER_TOOLS',
        'REDUX_DEVTOOLS'
      ];
      const forceDownload = !!process.env.UPGRADE_EXTENSIONS;
      for (const name of extensions) {
        try {
          await installer.default(installer[name], forceDownload);
        } catch (e) {} // eslint-disable-line
      }
    }
  };
  
  app.on('ready', async () => {
    await installExtensions();
  
    mainWindow = new BrowserWindow({
      show: false,
      width: 1024,
      height: 728
    });
  
    mainWindow.loadURL(`file://${__dirname}/app/app.html`);
  
    mainWindow.webContents.on('did-finish-load', () => {
      mainWindow.show();
      mainWindow.focus();
    });
  
    // Validate close if dirty
    mainWindow.on('close', (e) => {
      const isDirty   = R.pipe(
        R.values,
        R.any(R.identity)
      )(global.dirty)
      if (!isDirty) return
  
      e.preventDefault()
      dialog.showMessageBox(mainWindow, {
        type: "question",
        buttons: ["Cancel", "OK"],
        message: "Close without saving ?",
        detail: "Unsaved changes will be lost."
      }, function(res) {
        if (res == 1) {
          global.dirty = R.map( v => (false), global.dirty)
          mainWindow.destroy()
        }
      })
    })
  
    mainWindow.on('closed', () => {
      mainWindow = null;
    });
  
    if (process.env.NODE_ENV === 'development') {
      mainWindow.openDevTools();
      mainWindow.webContents.on('context-menu', (e, props) => {
        const { x, y } = props;
  
        Menu.buildFromTemplate([
          {
            label: 'Inspect element',
            click() {
              mainWindow.inspectElement(x, y);
            }
          }
        ]).popup(mainWindow);
      });
    }
  
    if (process.platform === 'darwin') {
      template = [{
        label: 'Translation Editor',
        submenu: [{
          label: 'About Translation Editor',
          selector: 'orderFrontStandardAboutPanel:'
        }, {
          type: 'separator'
        }, {
          label: 'Services',
          submenu: []
        }, {
          type: 'separator'
        }, {
          label: 'Hide Translation Editor',
          accelerator: 'Command+H',
          selector: 'hide:'
        }, {
          label: 'Hide Others',
          accelerator: 'Command+Shift+H',
          selector: 'hideOtherApplications:'
        }, {
          label: 'Show All',
          selector: 'unhideAllApplications:'
        }, {
          type: 'separator'
        }, {
          label: 'Quit',
          accelerator: 'Command+Q',
          click() {
            app.quit();
          }
        }]
      }, {
        label: 'Edit',
        submenu: [{
          label: 'Undo',
          accelerator: 'Command+Z',
          selector: 'undo:'
        }, {
          label: 'Redo',
          accelerator: 'Shift+Command+Z',
          selector: 'redo:'
        }, {
          type: 'separator'
        }, {
          label: 'Cut',
          accelerator: 'Command+X',
          selector: 'cut:'
        }, {
          label: 'Copy',
          accelerator: 'Command+C',
          selector: 'copy:'
        }, {
          label: 'Paste',
          accelerator: 'Command+V',
          selector: 'paste:'
        }, {
          label: 'Select All',
          accelerator: 'Command+A',
          selector: 'selectAll:'
        },
        /* debug */
        // {
        //   label: 'Toggle Developer Tools',
        //   accelerator: 'Alt+Command+I',
        //   click() {
        //     mainWindow.toggleDevTools();
        //   }
        // }
        /* /debug */
        ]
      }, {
        label: 'View',
        submenu: (process.env.NODE_ENV === 'development') ? [{
          label: 'Reload',
          accelerator: 'Command+R',
          click() {
            mainWindow.webContents.reload();
          }
        }, {
          label: 'Toggle Full Screen',
          accelerator: 'Ctrl+Command+F',
          click() {
            mainWindow.setFullScreen(!mainWindow.isFullScreen());
          }
        }, {
          label: 'Toggle Developer Tools',
          accelerator: 'Alt+Command+I',
          click() {
            mainWindow.toggleDevTools();
          }
        }] : [{
          label: 'Toggle Full Screen',
          accelerator: 'Ctrl+Command+F',
          click() {
            mainWindow.setFullScreen(!mainWindow.isFullScreen());
          }
        }]
      }, {
        label: 'Window',
        submenu: [{
          label: 'Minimize',
          accelerator: 'Command+M',
          selector: 'performMiniaturize:'
        }, {
          label: 'Close',
          accelerator: 'Command+W',
          selector: 'performClose:'
        }, {
          type: 'separator'
        }, {
          label: 'Bring All to Front',
          selector: 'arrangeInFront:'
        }]
      }, {
        label: 'Help',
        submenu: [{
          label: 'Learn More',
          click() {
            shell.openExternal('https://bitbucket.org/bflower/react-intl-editor');
          }
        }, {
          label: 'Documentation',
          click() {
            shell.openExternal('https://bitbucket.org/bflower/react-intl-editor/wiki/Home');
          }
        }, {
          label: 'Search Issues',
          click() {
            shell.openExternal('https://bitbucket.org/bflower/react-intl-editor/issues?status=new&status=open');
          }
        }]
      }];
  
      menu = Menu.buildFromTemplate(template);
      Menu.setApplicationMenu(menu);
    } else {
      template = [{
        label: '&File',
        submenu: [{
          label: '&Open',
          accelerator: 'Ctrl+O'
        }, {
          label: '&Close',
          accelerator: 'Ctrl+W',
          click() {
            mainWindow.close();
          }
        }]
      }, {
        label: '&View',
        submenu: (process.env.NODE_ENV === 'development') ? [{
          label: '&Reload',
          accelerator: 'Ctrl+R',
          click() {
            mainWindow.webContents.reload();
          }
        }, {
          label: 'Toggle &Full Screen',
          accelerator: 'F11',
          click() {
            mainWindow.setFullScreen(!mainWindow.isFullScreen());
          }
        }, {
          label: 'Toggle &Developer Tools',
          accelerator: 'Alt+Ctrl+I',
          click() {
            mainWindow.toggleDevTools();
          }
        }] : [{
          label: 'Toggle &Full Screen',
          accelerator: 'F11',
          click() {
            mainWindow.setFullScreen(!mainWindow.isFullScreen());
          }
        }]
      }, {
        label: 'Help',
        submenu: [{
          label: 'Learn More',
          click() {
            shell.openExternal('https://bitbucket.org/bflower/react-intl-editor');
          }
        }, {
          label: 'Documentation',
          click() {
            shell.openExternal('https://bitbucket.org/bflower/react-intl-editor/wiki/Home');
          }
        }, {
          label: 'Search Issues',
          click() {
            shell.openExternal('https://bitbucket.org/bflower/react-intl-editor/issues?status=new&status=open');
          }
        }]
      }];
      menu = Menu.buildFromTemplate(template);
      mainWindow.setMenu(menu);
    }
  });
  