electron/atom/browser/api/lib/web-contents.coffee

24 lines
829 B
CoffeeScript
Raw Normal View History

EventEmitter = require('events').EventEmitter
ipc = require 'ipc'
module.exports.wrap = (webContents) ->
return null unless webContents.isAlive()
# webContents is an EventEmitter.
webContents.__proto__ = EventEmitter.prototype
# Add the send method.
webContents.send = (args...) ->
@_send 'ATOM_INTERNAL_MESSAGE', [args...]
# Dispatch IPC messages to the ipc module.
webContents.on 'ipc-message', (event, channel, args...) =>
Object.defineProperty event, 'sender', value: webContents
ipc.emit channel, event, args...
webContents.on 'ipc-message-sync', (event, channel, args...) =>
Object.defineProperty event, 'returnValue', set: (value) -> event.sendReply JSON.stringify(value)
Object.defineProperty event, 'sender', value: webContents
ipc.emit channel, event, args...
webContents