allow the main process to dispatch any event to the renderer

This commit is contained in:
Feross Aboukhadijeh
2016-03-09 02:36:10 -08:00
parent fe524f8432
commit 944a47be72
3 changed files with 5 additions and 9 deletions

View File

@@ -37,5 +37,5 @@ ipc.init()
function onOpen (e, torrentId) {
e.preventDefault()
windows.main.send('addTorrent', torrentId)
windows.main.send('dispatch', 'addTorrent', torrentId)
}

View File

@@ -85,7 +85,7 @@ function getMenuTemplate () {
properties: [ 'openFile', 'openDirectory', 'multiSelections' ]
}, function (filenames) {
if (!Array.isArray(filenames)) return
windows.main.send('seed', filenames)
windows.main.send('dispatch', 'seed', filenames)
})
}
},
@@ -99,7 +99,7 @@ function getMenuTemplate () {
}, function (filenames) {
if (!Array.isArray(filenames)) return
filenames.forEach(function (filename) {
windows.main.send('addTorrent', filename)
windows.main.send('dispatch', 'addTorrent', filename)
})
})
}

View File

@@ -210,12 +210,8 @@ function dispatch (action, ...args) {
}
function setupIpc () {
ipcRenderer.on('addTorrent', function (e, torrentId) {
dispatch('addTorrent', torrentId)
})
ipcRenderer.on('seed', function (e, files) {
dispatch('seed', files)
ipcRenderer.on('dispatch', function (e, action, ...args) {
dispatch(action, ...args)
})
ipcRenderer.on('fullscreenChanged', function (e, isFullScreen) {