From 3011ee97d94c6b98dde64b29abd3d819c1854b71 Mon Sep 17 00:00:00 2001 From: Feross Aboukhadijeh Date: Tue, 16 Feb 2016 21:21:19 -0800 Subject: [PATCH] simplify index.js --- index.js | 53 +++++++++++++++++++++-------------------------------- 1 file changed, 21 insertions(+), 32 deletions(-) diff --git a/index.js b/index.js index f04353b7..69656229 100644 --- a/index.js +++ b/index.js @@ -3,14 +3,13 @@ var path = require('path') var app = electron.app -// report crashes to the Electron project -require('crash-reporter').start({ - // TODO: collect crash reports - // productName: 'WebTorrent', - // companyName: 'WebTorrent', - // submitURL: 'https://webtorrent.io/crash-report', - // autoSubmit: true -}) +// report crashes +// require('crash-reporter').start({ +// productName: 'WebTorrent', +// companyName: 'WebTorrent', +// submitURL: 'https://webtorrent.io/crash-report', +// autoSubmit: true +// }) // adds debug features like hotkeys for triggering dev tools and reload require('electron-debug')() @@ -18,36 +17,26 @@ require('electron-debug')() // prevent window being garbage collected var mainWindow -function onClosed () { - // dereference the window - // for multiple windows store them in an array - mainWindow = null -} +app.on('ready', function () { + mainWindow = createMainWindow() +}) + +app.on('activate', function () { + if (!mainWindow) mainWindow = createMainWindow() +}) + +app.on('window-all-closed', function () { + if (process.platform !== 'darwin') app.quit() +}) function createMainWindow () { const win = new electron.BrowserWindow({ width: 600, height: 400 }) - win.loadURL('file://' + path.join(__dirname, 'index.html')) - win.on('closed', onClosed) - + win.once('closed', function () { + mainWindow = null + }) return win } - -app.on('window-all-closed', () => { - if (process.platform !== 'darwin') { - app.quit() - } -}) - -app.on('activate', () => { - if (!mainWindow) { - mainWindow = createMainWindow() - } -}) - -app.on('ready', () => { - mainWindow = createMainWindow() -})