Don't rely on the global process object for message dispatching
This commit is contained in:
parent
c14c6a3521
commit
a10782cdea
3 changed files with 27 additions and 25 deletions
|
@ -1,26 +1,23 @@
|
|||
EventEmitter = require('events').EventEmitter
|
||||
process = global.process
|
||||
ipc = process.atomBinding('ipc')
|
||||
binding = process.atomBinding 'ipc'
|
||||
v8Util = process.atomBinding 'v8_util'
|
||||
|
||||
class Ipc extends EventEmitter
|
||||
constructor: ->
|
||||
process.on 'ATOM_INTERNAL_MESSAGE', (args...) =>
|
||||
@emit args...
|
||||
# Created by init.coffee.
|
||||
ipc = v8Util.getHiddenValue global, 'ipc'
|
||||
|
||||
window.addEventListener 'unload', (event) ->
|
||||
process.removeAllListeners 'ATOM_INTERNAL_MESSAGE'
|
||||
ipc.on 'ATOM_INTERNAL_MESSAGE', (args...) ->
|
||||
@emit args...
|
||||
|
||||
send: (args...) ->
|
||||
ipc.send 'ipc-message', [args...]
|
||||
ipc.send = (args...) ->
|
||||
binding.send 'ipc-message', [args...]
|
||||
|
||||
sendSync: (args...) ->
|
||||
JSON.parse ipc.sendSync('ipc-message-sync', [args...])
|
||||
ipc.sendSync = (args...) ->
|
||||
JSON.parse binding.sendSync('ipc-message-sync', [args...])
|
||||
|
||||
sendToHost: (args...) ->
|
||||
ipc.send 'ipc-message-host', [args...]
|
||||
ipc.sendToHost = (args...) ->
|
||||
binding.send 'ipc-message-host', [args...]
|
||||
|
||||
# Discarded
|
||||
sendChannel: -> @send.apply this, arguments
|
||||
sendChannelSync: -> @sendSync.apply this, arguments
|
||||
# Deprecated.
|
||||
ipc.sendChannel = ipc.send
|
||||
ipc.sendChannelSync = ipc.sendSync
|
||||
|
||||
module.exports = new Ipc
|
||||
module.exports = ipc
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue