2013-04-23 04:18:07 +00:00
|
|
|
EventEmitter = require('events').EventEmitter
|
2013-04-27 11:13:24 +00:00
|
|
|
ipc = process.atomBinding('ipc')
|
2013-04-23 04:18:07 +00:00
|
|
|
|
|
|
|
class Ipc extends EventEmitter
|
|
|
|
constructor: ->
|
|
|
|
process.on 'ATOM_INTERNAL_MESSAGE', (args...) =>
|
2013-04-23 12:57:14 +00:00
|
|
|
@emit(args...)
|
2013-04-23 04:18:07 +00:00
|
|
|
|
2013-05-04 13:52:14 +00:00
|
|
|
window.addEventListener 'unload', (event) ->
|
|
|
|
process.removeAllListeners 'ATOM_INTERNAL_MESSAGE'
|
|
|
|
|
2013-04-23 04:18:07 +00:00
|
|
|
send: (args...) ->
|
2013-04-23 14:21:49 +00:00
|
|
|
ipc.send('ATOM_INTERNAL_MESSAGE', 'message', args...)
|
2013-04-23 09:21:34 +00:00
|
|
|
|
|
|
|
sendChannel: (args...) ->
|
2013-04-23 13:52:19 +00:00
|
|
|
ipc.send('ATOM_INTERNAL_MESSAGE', args...)
|
|
|
|
|
|
|
|
sendSync: (args...) ->
|
2013-09-20 13:24:04 +00:00
|
|
|
msg = ipc.sendSync('ATOM_INTERNAL_MESSAGE_SYNC', 'sync-message', args...)
|
|
|
|
msg.returnValue ? msg.result
|
2013-04-23 13:52:19 +00:00
|
|
|
|
|
|
|
sendChannelSync: (args...) ->
|
2013-09-20 13:24:04 +00:00
|
|
|
msg = ipc.sendSync('ATOM_INTERNAL_MESSAGE_SYNC', args...)
|
|
|
|
msg.returnValue ? msg.result
|
2013-04-23 04:18:07 +00:00
|
|
|
|
|
|
|
module.exports = new Ipc
|