Queue messages for WebTorrent window until it's ready

This commit is contained in:
DC
2016-04-06 03:22:29 -07:00
parent 2e08eea43d
commit 9d4c65d1b1
2 changed files with 23 additions and 1 deletions

View File

@@ -26,6 +26,17 @@ function init () {
}, 50)
})
var messageQueueMainToWebTorrent = []
ipcMain.on('ipcReadyWebTorrent', function (e) {
app.ipcReadyWebTorrent = true
log('sending %d queued messages from the main win to the webtorrent window',
messageQueueMainToWebTorrent.length)
messageQueueMainToWebTorrent.forEach(function (message) {
windows.webtorrent.send(message.name, ...message.args)
log('webtorrent: sent queued %s', message.name)
})
})
ipcMain.on('showOpenTorrentFile', menu.showOpenTorrentFile)
ipcMain.on('showCreateTorrent', menu.showCreateTorrent)
@@ -80,11 +91,20 @@ function init () {
// Relay messages between the main window and the WebTorrent hidden window
if (name.startsWith('wt-')) {
if (e.sender.browserWindowOptions.title === 'webtorrent-hidden-window') {
// Send message to main window
windows.main.send(name, ...args)
log('webtorrent: got %s', name)
} else {
} else if (app.ipcReadyWebTorrent) {
// Send message to webtorrent window
windows.webtorrent.send(name, ...args)
log('webtorrent: sent %s', name)
} else {
// Queue message for webtorrent window, it hasn't finished loading yet
messageQueueMainToWebTorrent.push({
name: name,
args: args
})
log('webtorrent: queueing %s', name)
}
return
}

View File

@@ -55,6 +55,8 @@ function init () {
ipc.on('wt-stop-server', (e) =>
stopServer())
ipc.send('ipcReadyWebTorrent')
setInterval(updateTorrentProgress, 1000)
}