mirror of
https://github.com/electron/electron.git
synced 2026-04-10 03:01:51 -04:00
refactor: move common logic to handleRemoteCommand
This commit is contained in:
@@ -275,21 +275,21 @@ function metaToException (meta) {
|
||||
return error
|
||||
}
|
||||
|
||||
function handleMessage (channel, handler) {
|
||||
ipcRenderer.on(channel, (event, passedContextId, ...args) => {
|
||||
if (passedContextId === contextId) {
|
||||
handler(...args)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
// Browser calls a callback in renderer.
|
||||
ipcRenderer.on('ELECTRON_RENDERER_CALLBACK', (event, passedContextId, id, args) => {
|
||||
if (passedContextId !== contextId) {
|
||||
// The invoked callback belongs to an old page in this renderer.
|
||||
return
|
||||
}
|
||||
handleMessage('ELECTRON_RENDERER_CALLBACK', (id, args) => {
|
||||
callbacksRegistry.apply(id, metaToValue(args))
|
||||
})
|
||||
|
||||
// A callback in browser is released.
|
||||
ipcRenderer.on('ELECTRON_RENDERER_RELEASE_CALLBACK', (event, passedContextId, id) => {
|
||||
if (passedContextId !== contextId) {
|
||||
// The freed callback belongs to an old page in this renderer.
|
||||
return
|
||||
}
|
||||
handleMessage('ELECTRON_RENDERER_RELEASE_CALLBACK', (id) => {
|
||||
callbacksRegistry.remove(id)
|
||||
})
|
||||
|
||||
|
||||
Reference in New Issue
Block a user