electron/renderer/api/lib/ipc.coffee

27 lines
757 B
CoffeeScript
Raw Normal View History

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