]> khamidou — GitHub mirrors - electron.git/commitdiff
Send message to window directly when passing BrowserWindow for ipc.send.
authorCheng Zhao <zcbenz@gmail.com>
Fri, 17 May 2013 15:40:37 +0000 (23:40 +0800)
committerCheng Zhao <zcbenz@gmail.com>
Fri, 17 May 2013 15:40:37 +0000 (23:40 +0800)
browser/api/lib/ipc.coffee

index f9acccaa56318489b9ce0fb0d4a40970694f298d..53f4cbddc44f2289bbb9bc7d4d52d5df3765d924 100644 (file)
@@ -1,6 +1,15 @@
 EventEmitter = require('events').EventEmitter
 send = process.atomBinding('ipc').send
 
+sendWrap = (channel, processId, routingId, args...) ->
+  BrowserWindow = require 'browser_window'
+  if processId?.constructor is BrowserWindow
+    window = processId
+    processId = window.getProcessId()
+    routingId = window.getRoutingId()
+
+  send channel, processId, routingId, args...
+
 class Ipc extends EventEmitter
   constructor: ->
     process.on 'ATOM_INTERNAL_MESSAGE', (args...) =>
@@ -12,6 +21,6 @@ class Ipc extends EventEmitter
     @sendChannel(processId, routingId, 'message', args...)
 
   sendChannel: (args...) ->
-    send('ATOM_INTERNAL_MESSAGE', args...)
+    sendWrap('ATOM_INTERNAL_MESSAGE', args...)
 
 module.exports = new Ipc