From 82fc6cabe80b70468f56fe79a156003ce0ae2ad0 Mon Sep 17 00:00:00 2001 From: Feross Aboukhadijeh Date: Fri, 4 Mar 2016 16:10:14 -0800 Subject: [PATCH] move config.startTime to app.startTime MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This also captures the true start time since it runs before any require() calls, so the time to require() will be taken into account. --- main/config.js | 3 +-- main/index.js | 7 ++++++- main/menu.js | 9 +++++---- main/windows.js | 6 ++++-- 4 files changed, 16 insertions(+), 9 deletions(-) diff --git a/main/config.js b/main/config.js index 552906b7..0f435f5f 100644 --- a/main/config.js +++ b/main/config.js @@ -2,6 +2,5 @@ var path = require('path') module.exports = { APP_NAME: 'WebTorrent', - INDEX: 'file://' + path.resolve(__dirname, '..', 'renderer', 'index.html'), - startTime: Date.now() + INDEX: 'file://' + path.resolve(__dirname, '..', 'renderer', 'index.html') } diff --git a/main/index.js b/main/index.js index 43960b75..709569dd 100644 --- a/main/index.js +++ b/main/index.js @@ -1,9 +1,14 @@ +var startTime = Date.now() + var electron = require('electron') +var ipc = require('./ipc') var menu = require('./menu') var windows = require('./windows') -var ipc = require('./ipc') + var app = electron.app +app.startTime = startTime + app.on('open-file', onOpen) app.on('open-url', onOpen) diff --git a/main/menu.js b/main/menu.js index 9fcf41d9..ad05ab85 100644 --- a/main/menu.js +++ b/main/menu.js @@ -1,7 +1,8 @@ var electron = require('electron') var debug = require('debug')('webtorrent-app:menu') var windows = require('./windows') -var config = require('./config') + +var app = electron.app function toggleFullScreen () { debug('toggleFullScreen') @@ -34,7 +35,7 @@ function toggleDevTools () { function reloadWindow () { debug('reloadWindow') if (windows.main) { - config.startTime = Date.now() + app.startTime = Date.now() windows.main.webContents.reloadIgnoringCache() } } @@ -191,7 +192,7 @@ function getMenuTemplate () { ] if (process.platform === 'darwin') { - var name = electron.app.getName() + var name = app.getName() template.unshift({ label: name, submenu: [ @@ -230,7 +231,7 @@ function getMenuTemplate () { { label: 'Quit', accelerator: 'Command+Q', - click: function () { electron.app.quit() } + click: function () { app.quit() } } ] }) diff --git a/main/windows.js b/main/windows.js index c0c932ca..1bba659d 100644 --- a/main/windows.js +++ b/main/windows.js @@ -2,13 +2,15 @@ var electron = require('electron') var debug = require('debug')('webtorrent-app:windows') var config = require('./config') +var app = electron.app + var windows = { main: null, createMainWindow: createMainWindow } var isQuitting = false -electron.app.on('before-quit', function () { +app.on('before-quit', function () { isQuitting = true }) @@ -27,7 +29,7 @@ function createMainWindow (menu) { windows.main.loadURL(config.INDEX) windows.main.webContents.on('did-finish-load', function () { setTimeout(function () { - debug('startup time: %sms', Date.now() - config.startTime) + debug('startup time: %sms', Date.now() - app.startTime) windows.main.show() }, 50) })