'use strict'; var app = require('app'), BrowserWindow = require('browser-window'); require('crash-reporter').start(); var mainWindow; var filepath; var ready = false; app.on('ready', function() { mainWindow = new BrowserWindow({ 'width': 800, 'height': 600 }); mainWindow.loadUrl('file://' + __dirname + '/index.html'); mainWindow.focus(); mainWindow.on('closed', function() { mainWindow = null; }); mainWindow.webContents.on('did-finish-load', function() { if (filepath) { mainWindow.webContents.send('open-file', filepath); filepath = null; } }); ready = true; }); app.on("open-file", function(event, path) { event.preventDefault(); filepath = path; if (ready) { mainWindow.webContents.send('open-file', filepath); filepath = null; return; } }); app.on('window-all-closed', function() { app.quit(); });