/* ------------------------------------------------
 * Dependencies
 * ------------------------------------------------ */
const app = require('app');
const BrowserWindow = require('browser-window');
const crashReporter = require('crash-reporter');
const ipc = require('ipc');
const path = require('path');

const appConfig = require('src/config/appConfig');

/* ------------------------------------------------
 * App initialization
 * ------------------------------------------------ */
var mainWindow;

crashReporter.start(); // Report crashes to our server.

ipc.on('set-title', function(event, title) {
  mainWindow.setTitle(title || 'Mongotron');
});

ipc.on('quit', function() {
  app.quit();
});

app.on('window-all-closed', function() {
  // Quit when all windows are closed.
  // On OS X it is common for applications and their menu bar
  // to stay active until the user quits explicitly with Cmd + Q
  if (process.platform !== 'darwin') {
    app.quit();
  }
});

app.on('ready', function() {
  mainWindow = new BrowserWindow({});

  mainWindow.maximize();

  mainWindow.setMinimumSize(770, 400);

  mainWindow.loadUrl(path.join('file://', __dirname, '../ui/index.html'));

  if (appConfig.ENV !== 'production') mainWindow.openDevTools();

  mainWindow.webContents.on('did-finish-load', function() {
    mainWindow.setTitle('Mongotron');
  });

  mainWindow.on('closed', function() {
    // Dereference the window object, usually you would store windows
    // in an array if your app supports multi windows, this is the time
    // when you should delete the corresponding element.
    mainWindow = null;
  });
});

@@ -1346,24 +1346,85 @@
 n');%0A  %7D);%0A%0A
+  mainWindow.on('close', function() %7B%0A    app.quit();%0A  %7D);%0A%0A
   mainWindow

quit app when main window is closed