main: Start loading state before app is ready (#952)
As mentioned in https://github.com/feross/webtorrent-desktop/pull/827#discussion_r799219 59 We should load the state outside the app.on('ready') handler so there's a chance it's ready by the time 'ready' fires. This improves startup time by roughly 50ms on my Macbook 12".
This commit is contained in:
@@ -4,6 +4,8 @@ const electron = require('electron')
|
|||||||
const app = electron.app
|
const app = electron.app
|
||||||
const ipcMain = electron.ipcMain
|
const ipcMain = electron.ipcMain
|
||||||
|
|
||||||
|
const parallel = require('run-parallel')
|
||||||
|
|
||||||
const announcement = require('./announcement')
|
const announcement = require('./announcement')
|
||||||
const config = require('../config')
|
const config = require('../config')
|
||||||
const crashReporter = require('../crash-reporter')
|
const crashReporter = require('../crash-reporter')
|
||||||
@@ -60,23 +62,17 @@ function init () {
|
|||||||
app.ipcReady = false // main window has finished loading and IPC is ready
|
app.ipcReady = false // main window has finished loading and IPC is ready
|
||||||
app.isQuitting = false
|
app.isQuitting = false
|
||||||
|
|
||||||
// Open handlers must be added as early as possible
|
parallel({
|
||||||
app.on('open-file', onOpen)
|
appReady: (cb) => app.on('ready', () => cb(null)),
|
||||||
app.on('open-url', onOpen)
|
state: (cb) => State.load(cb)
|
||||||
|
}, onReady)
|
||||||
|
|
||||||
ipc.init()
|
function onReady (err, results) {
|
||||||
|
if (err) throw err
|
||||||
|
|
||||||
app.once('will-finish-launching', function () {
|
|
||||||
crashReporter.init()
|
|
||||||
})
|
|
||||||
|
|
||||||
app.on('ready', function () {
|
|
||||||
isReady = true
|
isReady = true
|
||||||
|
|
||||||
State.load(function (err, state) {
|
windows.main.init(results.state, {hidden: hidden})
|
||||||
if (err) throw err
|
|
||||||
windows.main.init(state, {hidden: hidden})
|
|
||||||
})
|
|
||||||
windows.webtorrent.init()
|
windows.webtorrent.init()
|
||||||
menu.init()
|
menu.init()
|
||||||
|
|
||||||
@@ -89,6 +85,15 @@ function init () {
|
|||||||
const error = {message: err.message, stack: err.stack}
|
const error = {message: err.message, stack: err.stack}
|
||||||
windows.main.dispatch('uncaughtError', 'main', error)
|
windows.main.dispatch('uncaughtError', 'main', error)
|
||||||
})
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
app.on('open-file', onOpen)
|
||||||
|
app.on('open-url', onOpen)
|
||||||
|
|
||||||
|
ipc.init()
|
||||||
|
|
||||||
|
app.once('will-finish-launching', function () {
|
||||||
|
crashReporter.init()
|
||||||
})
|
})
|
||||||
|
|
||||||
app.once('ipcReady', function () {
|
app.once('ipcReady', function () {
|
||||||
|
|||||||
Reference in New Issue
Block a user