2013-04-23 12:18:07 +08:00
|
|
|
EventEmitter = require('events').EventEmitter
|
2014-10-26 19:30:53 +08:00
|
|
|
process = global.process
|
2013-04-27 19:13:24 +08:00
|
|
|
ipc = process.atomBinding('ipc')
|
2013-04-23 12:18:07 +08:00
|
|
|
|
|
|
|
class Ipc extends EventEmitter
|
|
|
|
constructor: ->
|
|
|
|
process.on 'ATOM_INTERNAL_MESSAGE', (args...) =>
|
2013-12-05 23:34:43 +08:00
|
|
|
@emit args...
|
2013-04-23 12:18:07 +08:00
|
|
|
|
2013-05-04 21:52:14 +08:00
|
|
|
window.addEventListener 'unload', (event) ->
|
|
|
|
process.removeAllListeners 'ATOM_INTERNAL_MESSAGE'
|
|
|
|
|
2013-04-23 12:18:07 +08:00
|
|
|
send: (args...) ->
|
2014-04-25 16:13:16 +08:00
|
|
|
ipc.send 'ipc-message', [args...]
|
2013-04-23 21:52:19 +08:00
|
|
|
|
|
|
|
sendSync: (args...) ->
|
2014-04-25 16:13:16 +08:00
|
|
|
JSON.parse ipc.sendSync('ipc-message-sync', [args...])
|
2013-04-23 21:52:19 +08:00
|
|
|
|
2014-12-17 11:09:11 -08:00
|
|
|
sendToHost: (args...) ->
|
|
|
|
ipc.send 'ipc-message-host', [args...]
|
|
|
|
|
2014-04-25 16:13:16 +08:00
|
|
|
# Discarded
|
|
|
|
sendChannel: -> @send.apply this, arguments
|
|
|
|
sendChannelSync: -> @sendSync.apply this, arguments
|
2013-04-23 12:18:07 +08:00
|
|
|
|
|
|
|
module.exports = new Ipc
|