import path from 'path';

import { shell, BrowserWindow } from 'electron';

export function deferURL(event, url) {
  event.preventDefault();
  shell.openExternal(url);
}

export function launch(filename) {
  let iconPath = '';
  if (process.argv[0].match(/electron/i)) {
    iconPath = './static/icon.png';
  } else {
    iconPath = '.cd/resources/app/static/icon.png';
  }

  let win = new BrowserWindow({
    width: 800,
    height: 1000,
    icon: iconPath,
    title: 'nteract',
  });

  const index = path.join(__dirname, '..', '..', 'static', 'index.html');
  win.loadURL(`file://${index}`);

  win.webContents.on('did-finish-load', () => {
    if (filename) {
      win.webContents.send('main:load', filename);
    }
    // TODO: else, we assume it's an empty notebook
    //       assumption right now is that launchNewNotebook will handle the follow on
  });

  win.webContents.on('will-navigate', deferURL);

  // Emitted when the window is closed.
  win.on('closed', () => {
    win = null;
  });
  return win;
}

export function launchNewNotebook(kernelSpecName) {
  const win = launch();
  win.webContents.on('did-finish-load', () => {
    win.webContents.send('main:new', kernelSpecName);
  });
  return win;
}

@@ -168,124 +168,51 @@
 %0A%7D%0A%0A
-export function launch(filename) %7B%0A  let iconPath = '';%0A  if (process.argv%5B0%5D.match(/electron/i)) %7B%0A    iconPath = '
+const iconPath = path.join(__dirname, '../.
 ./st
@@ -229,77 +229,46 @@
 png'
+)
 ;%0A
-  %7D else %7B%0A    iconPath = '.cd/resources/app/static/icon.png';%0A  %7D%0A
+%0Aexport function launch(filename) %7B
 %0A  l

resolve full path for icon relatively, once