Use require('electron') in Electron's code

This commit is contained in:
Cheng Zhao 2015-11-12 18:28:04 +08:00
parent f9d7e7ce55
commit 1d1f911b09
71 changed files with 265 additions and 250 deletions

View file

@ -1,5 +1,5 @@
deprecate = require 'deprecate' electron = require 'electron'
EventEmitter = require('events').EventEmitter {EventEmitter} = require 'events'
bindings = process.atomBinding 'app' bindings = process.atomBinding 'app'
sessionBindings = process.atomBinding 'session' sessionBindings = process.atomBinding 'session'
@ -9,10 +9,10 @@ app = bindings.app
app.__proto__ = EventEmitter.prototype app.__proto__ = EventEmitter.prototype
app.setApplicationMenu = (menu) -> app.setApplicationMenu = (menu) ->
require('menu').setApplicationMenu menu electron.menu.setApplicationMenu menu
app.getApplicationMenu = -> app.getApplicationMenu = ->
require('menu').getApplicationMenu() electron.menu.getApplicationMenu()
app.commandLine = app.commandLine =
appendSwitch: bindings.appendSwitch, appendSwitch: bindings.appendSwitch,
@ -39,6 +39,7 @@ app.getAppPath = ->
app.resolveProxy = (url, callback) -> @defaultSession.resolveProxy url, callback app.resolveProxy = (url, callback) -> @defaultSession.resolveProxy url, callback
# Deprecated. # Deprecated.
{deprecate} = electron
app.getHomeDir = deprecate 'app.getHomeDir', 'app.getPath', -> app.getHomeDir = deprecate 'app.getHomeDir', 'app.getPath', ->
@getPath 'home' @getPath 'home'
app.getDataPath = deprecate 'app.getDataPath', 'app.getPath', -> app.getDataPath = deprecate 'app.getDataPath', 'app.getPath', ->

View file

@ -1,7 +1,5 @@
EventEmitter = require('events').EventEmitter {app, ipcMain, deprecate} = require 'electron'
app = require 'app' {EventEmitter} = require 'events'
ipc = require 'ipc-main'
deprecate = require 'deprecate'
BrowserWindow = process.atomBinding('window').BrowserWindow BrowserWindow = process.atomBinding('window').BrowserWindow
BrowserWindow::__proto__ = EventEmitter.prototype BrowserWindow::__proto__ = EventEmitter.prototype
@ -15,7 +13,7 @@ BrowserWindow::_init = ->
# Make new windows requested by links behave like "window.open" # Make new windows requested by links behave like "window.open"
@webContents.on '-new-window', (event, url, frameName) -> @webContents.on '-new-window', (event, url, frameName) ->
options = show: true, width: 800, height: 600 options = show: true, width: 800, height: 600
ipc.emit 'ATOM_SHELL_GUEST_WINDOW_MANAGER_WINDOW_OPEN', event, url, frameName, options ipcMain.emit 'ATOM_SHELL_GUEST_WINDOW_MANAGER_WINDOW_OPEN', event, url, frameName, options
# window.resizeTo(...) # window.resizeTo(...)
# window.moveTo(...) # window.moveTo(...)

View file

@ -1,7 +1,7 @@
{app, BrowserWindow} = require 'electron'
binding = process.atomBinding 'dialog' binding = process.atomBinding 'dialog'
v8Util = process.atomBinding 'v8_util' v8Util = process.atomBinding 'v8_util'
app = require 'app'
BrowserWindow = require 'browser-window'
fileDialogProperties = fileDialogProperties =
openFile: 1 << 0 openFile: 1 << 0

View file

@ -45,3 +45,8 @@ Object.defineProperties module.exports,
tray: tray:
enumerable: true enumerable: true
get: -> require '../tray' get: -> require '../tray'
# The internal modules, invisible unless you know their names.
NavigationController:
get: -> require '../navigation-controller'
webContents:
get: -> require '../web-contents'

View file

@ -1,5 +1,3 @@
bindings = process.atomBinding 'global_shortcut' {globalShortcut} = process.atomBinding 'global_shortcut'
globalShortcut = bindings.globalShortcut
module.exports = globalShortcut module.exports = globalShortcut

View file

@ -1,6 +1,6 @@
deprecate = require 'deprecate' {deprecate, ipcMain} = require 'electron'
# This module is deprecated, we mirror everything from ipcMain. # This module is deprecated, we mirror everything from ipcMain.
deprecate.warn 'ipc module', 'ipcMain module' deprecate.warn 'ipc module', 'ipcMain module'
module.exports = require 'ipc-main' module.exports = ipcMain

View file

@ -1,4 +1,3 @@
BrowserWindow = require 'browser-window'
v8Util = process.atomBinding 'v8_util' v8Util = process.atomBinding 'v8_util'
nextCommandId = 0 nextCommandId = 0
@ -18,7 +17,7 @@ class MenuItem
@types = ['normal', 'separator', 'submenu', 'checkbox', 'radio'] @types = ['normal', 'separator', 'submenu', 'checkbox', 'radio']
constructor: (options) -> constructor: (options) ->
Menu = require 'menu' {Menu} = require 'electron'
{click, @selector, @type, @role, @label, @sublabel, @accelerator, @icon, @enabled, @visible, @checked, @submenu} = options {click, @selector, @type, @role, @label, @sublabel, @accelerator, @icon, @enabled, @visible, @checked, @submenu} = options

View file

@ -1,8 +1,7 @@
BrowserWindow = require 'browser-window' {BrowserWindow, MenuItem} = require 'electron'
EventEmitter = require('events').EventEmitter {EventEmitter} = require 'events'
MenuItem = require 'menu-item'
v8Util = process.atomBinding 'v8_util'
v8Util = process.atomBinding 'v8_util'
bindings = process.atomBinding 'menu' bindings = process.atomBinding 'menu'
# Automatically generated radio menu item's group id. # Automatically generated radio menu item's group id.

View file

@ -1,10 +1,10 @@
ipc = require 'ipc-main' {ipcMain} = require 'electron'
# The history operation in renderer is redirected to browser. # The history operation in renderer is redirected to browser.
ipc.on 'ATOM_SHELL_NAVIGATION_CONTROLLER', (event, method, args...) -> ipcMain.on 'ATOM_SHELL_NAVIGATION_CONTROLLER', (event, method, args...) ->
event.sender[method] args... event.sender[method] args...
ipc.on 'ATOM_SHELL_SYNC_NAVIGATION_CONTROLLER', (event, method, args...) -> ipcMain.on 'ATOM_SHELL_SYNC_NAVIGATION_CONTROLLER', (event, method, args...) ->
event.returnValue = event.sender[method] args... event.returnValue = event.sender[method] args...
# JavaScript implementation of Chromium's NavigationController. # JavaScript implementation of Chromium's NavigationController.

View file

@ -1,5 +1,6 @@
powerMonitor = process.atomBinding('power_monitor').powerMonitor {EventEmitter} = require 'events'
EventEmitter = require('events').EventEmitter
{powerMonitor} = process.atomBinding 'power_monitor'
powerMonitor.__proto__ = EventEmitter.prototype powerMonitor.__proto__ = EventEmitter.prototype

View file

@ -1,3 +1,3 @@
bindings = process.atomBinding 'power_save_blocker' {powerSaveBlocker} = process.atomBinding 'power_save_blocker'
module.exports = bindings.powerSaveBlocker module.exports = powerSaveBlocker

View file

@ -1,7 +1,8 @@
app = require 'app' {app} = require 'electron'
throw new Error('Can not initialize protocol module before app is ready') unless app.isReady() throw new Error('Can not initialize protocol module before app is ready') unless app.isReady()
protocol = process.atomBinding('protocol').protocol {protocol} = process.atomBinding 'protocol'
# Warn about removed APIs. # Warn about removed APIs.
logAndThrow = (callback, message) -> logAndThrow = (callback, message) ->

View file

@ -1,6 +1,6 @@
EventEmitter = require('events').EventEmitter {EventEmitter} = require 'events'
{screen} = process.atomBinding 'screen'
screen = process.atomBinding('screen').screen
screen.__proto__ = EventEmitter.prototype screen.__proto__ = EventEmitter.prototype
module.exports = screen module.exports = screen

View file

@ -1,7 +1,6 @@
EventEmitter = require('events').EventEmitter {EventEmitter} = require 'events'
bindings = process.atomBinding 'tray' {Tray} = process.atomBinding 'tray'
Tray = bindings.Tray
Tray::__proto__ = EventEmitter.prototype Tray::__proto__ = EventEmitter.prototype
Tray::setContextMenu = (menu) -> Tray::setContextMenu = (menu) ->

View file

@ -1,8 +1,7 @@
EventEmitter = require('events').EventEmitter {EventEmitter} = require 'events'
Menu = require './menu' {ipcMain, NavigationController, Menu} = require 'electron'
NavigationController = require './navigation-controller'
binding = process.atomBinding 'web_contents' binding = process.atomBinding 'web_contents'
ipc = require 'ipc-main'
nextId = 0 nextId = 0
getNextId = -> ++nextId getNextId = -> ++nextId
@ -60,11 +59,11 @@ wrapWebContents = (webContents) ->
# Dispatch IPC messages to the ipc module. # Dispatch IPC messages to the ipc module.
webContents.on 'ipc-message', (event, packed) -> webContents.on 'ipc-message', (event, packed) ->
[channel, args...] = packed [channel, args...] = packed
ipc.emit channel, event, args... ipcMain.emit channel, event, args...
webContents.on 'ipc-message-sync', (event, packed) -> webContents.on 'ipc-message-sync', (event, packed) ->
[channel, args...] = packed [channel, args...] = packed
Object.defineProperty event, 'returnValue', set: (value) -> event.sendReply JSON.stringify(value) Object.defineProperty event, 'returnValue', set: (value) -> event.sendReply JSON.stringify(value)
ipc.emit channel, event, args... ipcMain.emit channel, event, args...
# Handle context menu action request from pepper plugin. # Handle context menu action request from pepper plugin.
webContents.on 'pepper-context-menu', (event, params) -> webContents.on 'pepper-context-menu', (event, params) ->

View file

@ -1,5 +1,6 @@
var app = require('app'); const electron = require('electron');
var BrowserWindow = require('browser-window'); const app = electron.app;
const BrowserWindow = electron.BrowserWindow;
var mainWindow = null; var mainWindow = null;

View file

@ -57,13 +57,17 @@
</head> </head>
<body> <body>
<script> <script>
var execPath = require('remote').process.execPath; const electron = require('electron');
const remote = electron.remote;
const shell = electron.shell;
var execPath = remote.process.execPath;
var command = execPath + ' path-to-your-app'; var command = execPath + ' path-to-your-app';
document.onclick = function(e) { document.onclick = function(e) {
e.preventDefault(); e.preventDefault();
if (e.target.tagName == 'A') if (e.target.tagName == 'A')
require('shell').openExternal(e.target.href); shell.openExternal(e.target.href);
return false; return false;
}; };
document.ondragover = document.ondrop = function(e) { document.ondragover = document.ondrop = function(e) {

View file

@ -1,9 +1,11 @@
var app = require('app'); const electron = require('electron');
var dialog = require('dialog'); const app = electron.app;
const dialog = electron.dialog;
const shell = electron.shell;
const Menu = electron.Menu;
var fs = require('fs'); var fs = require('fs');
var path = require('path'); var path = require('path');
var Menu = require('menu');
var BrowserWindow = require('browser-window');
// Quit when all windows are closed and no other one is listening to this. // Quit when all windows are closed and no other one is listening to this.
app.on('window-all-closed', function() { app.on('window-all-closed', function() {
@ -142,19 +144,19 @@ app.once('ready', function() {
submenu: [ submenu: [
{ {
label: 'Learn More', label: 'Learn More',
click: function() { require('shell').openExternal('http://electron.atom.io') } click: function() { shell.openExternal('http://electron.atom.io') }
}, },
{ {
label: 'Documentation', label: 'Documentation',
click: function() { require('shell').openExternal('https://github.com/atom/electron/tree/master/docs#readme') } click: function() { shell.openExternal('https://github.com/atom/electron/tree/master/docs#readme') }
}, },
{ {
label: 'Community Discussions', label: 'Community Discussions',
click: function() { require('shell').openExternal('https://discuss.atom.io/c/electron') } click: function() { shell.openExternal('https://discuss.atom.io/c/electron') }
}, },
{ {
label: 'Search Issues', label: 'Search Issues',
click: function() { require('shell').openExternal('https://github.com/atom/electron/issues') } click: function() { shell.openExternal('https://github.com/atom/electron/issues') }
} }
] ]
}, },
@ -269,5 +271,5 @@ if (option.file && !option.webdriver) {
console.log(helpMessage); console.log(helpMessage);
process.exit(0); process.exit(0);
} else { } else {
require('./default_app.js'); require('./default_app');
} }

View file

@ -1,4 +1,4 @@
app = require 'app' electron = require 'electron'
fs = require 'fs' fs = require 'fs'
path = require 'path' path = require 'path'
url = require 'url' url = require 'url'
@ -40,6 +40,7 @@ loadedExtensions = null
loadedExtensionsPath = null loadedExtensionsPath = null
# Persistent loaded extensions. # Persistent loaded extensions.
{app} = electron
app.on 'will-quit', -> app.on 'will-quit', ->
try try
loadedExtensions = Object.keys(extensionInfoMap).map (key) -> extensionInfoMap[key].srcDirectory loadedExtensions = Object.keys(extensionInfoMap).map (key) -> extensionInfoMap[key].srcDirectory
@ -51,8 +52,7 @@ app.on 'will-quit', ->
# We can not use protocol or BrowserWindow until app is ready. # We can not use protocol or BrowserWindow until app is ready.
app.once 'ready', -> app.once 'ready', ->
protocol = require 'protocol' {protocol, BrowserWindow} = electron
BrowserWindow = require 'browser-window'
# Load persistented extensions. # Load persistented extensions.
loadedExtensionsPath = path.join app.getPath('userData'), 'DevTools Extensions' loadedExtensionsPath = path.join app.getPath('userData'), 'DevTools Extensions'

View file

@ -1,5 +1,5 @@
ipc = require 'ipc-main' {ipcMain, webContents} = require 'electron'
webContents = require 'web-contents'
webViewManager = null # Doesn't exist in early initialization. webViewManager = null # Doesn't exist in early initialization.
supportedWebViewEvents = [ supportedWebViewEvents = [
@ -140,19 +140,19 @@ destroyGuest = (embedder, id) ->
delete reverseEmbedderElementsMap[id] delete reverseEmbedderElementsMap[id]
delete embedderElementsMap[key] delete embedderElementsMap[key]
ipc.on 'ATOM_SHELL_GUEST_VIEW_MANAGER_CREATE_GUEST', (event, params, requestId) -> ipcMain.on 'ATOM_SHELL_GUEST_VIEW_MANAGER_CREATE_GUEST', (event, params, requestId) ->
event.sender.send "ATOM_SHELL_RESPONSE_#{requestId}", createGuest(event.sender, params) event.sender.send "ATOM_SHELL_RESPONSE_#{requestId}", createGuest(event.sender, params)
ipc.on 'ATOM_SHELL_GUEST_VIEW_MANAGER_ATTACH_GUEST', (event, elementInstanceId, guestInstanceId, params) -> ipcMain.on 'ATOM_SHELL_GUEST_VIEW_MANAGER_ATTACH_GUEST', (event, elementInstanceId, guestInstanceId, params) ->
attachGuest event.sender, elementInstanceId, guestInstanceId, params attachGuest event.sender, elementInstanceId, guestInstanceId, params
ipc.on 'ATOM_SHELL_GUEST_VIEW_MANAGER_DESTROY_GUEST', (event, id) -> ipcMain.on 'ATOM_SHELL_GUEST_VIEW_MANAGER_DESTROY_GUEST', (event, id) ->
destroyGuest event.sender, id destroyGuest event.sender, id
ipc.on 'ATOM_SHELL_GUEST_VIEW_MANAGER_SET_SIZE', (event, id, params) -> ipcMain.on 'ATOM_SHELL_GUEST_VIEW_MANAGER_SET_SIZE', (event, id, params) ->
guestInstances[id]?.guest.setSize params guestInstances[id]?.guest.setSize params
ipc.on 'ATOM_SHELL_GUEST_VIEW_MANAGER_SET_ALLOW_TRANSPARENCY', (event, id, allowtransparency) -> ipcMain.on 'ATOM_SHELL_GUEST_VIEW_MANAGER_SET_ALLOW_TRANSPARENCY', (event, id, allowtransparency) ->
guestInstances[id]?.guest.setAllowTransparency allowtransparency guestInstances[id]?.guest.setAllowTransparency allowtransparency
# Returns WebContents from its guest id. # Returns WebContents from its guest id.

View file

@ -1,6 +1,5 @@
ipc = require 'ipc-main' {ipcMain, BrowserWindow} = require 'electron'
v8Util = process.atomBinding 'v8_util' v8Util = process.atomBinding 'v8_util'
BrowserWindow = require 'browser-window'
frameToGuest = {} frameToGuest = {}
@ -58,7 +57,7 @@ createGuest = (embedder, url, frameName, options) ->
guest.id guest.id
# Routed window.open messages. # Routed window.open messages.
ipc.on 'ATOM_SHELL_GUEST_WINDOW_MANAGER_WINDOW_OPEN', (event, args...) -> ipcMain.on 'ATOM_SHELL_GUEST_WINDOW_MANAGER_WINDOW_OPEN', (event, args...) ->
[url, frameName, options] = args [url, frameName, options] = args
options = mergeBrowserWindowOptions event.sender, options options = mergeBrowserWindowOptions event.sender, options
event.sender.emit 'new-window', event, url, frameName, 'new-window', options event.sender.emit 'new-window', event, url, frameName, 'new-window', options
@ -67,26 +66,26 @@ ipc.on 'ATOM_SHELL_GUEST_WINDOW_MANAGER_WINDOW_OPEN', (event, args...) ->
else else
event.returnValue = createGuest event.sender, url, frameName, options event.returnValue = createGuest event.sender, url, frameName, options
ipc.on 'ATOM_SHELL_GUEST_WINDOW_MANAGER_WINDOW_CLOSE', (event, guestId) -> ipcMain.on 'ATOM_SHELL_GUEST_WINDOW_MANAGER_WINDOW_CLOSE', (event, guestId) ->
BrowserWindow.fromId(guestId)?.destroy() BrowserWindow.fromId(guestId)?.destroy()
ipc.on 'ATOM_SHELL_GUEST_WINDOW_MANAGER_WINDOW_METHOD', (event, guestId, method, args...) -> ipcMain.on 'ATOM_SHELL_GUEST_WINDOW_MANAGER_WINDOW_METHOD', (event, guestId, method, args...) ->
BrowserWindow.fromId(guestId)?[method] args... BrowserWindow.fromId(guestId)?[method] args...
ipc.on 'ATOM_SHELL_GUEST_WINDOW_MANAGER_WINDOW_POSTMESSAGE', (event, guestId, message, targetOrigin) -> ipcMain.on 'ATOM_SHELL_GUEST_WINDOW_MANAGER_WINDOW_POSTMESSAGE', (event, guestId, message, targetOrigin) ->
guestContents = BrowserWindow.fromId(guestId)?.webContents guestContents = BrowserWindow.fromId(guestId)?.webContents
if guestContents?.getUrl().indexOf(targetOrigin) is 0 or targetOrigin is '*' if guestContents?.getUrl().indexOf(targetOrigin) is 0 or targetOrigin is '*'
guestContents.send 'ATOM_SHELL_GUEST_WINDOW_POSTMESSAGE', guestId, message, targetOrigin guestContents.send 'ATOM_SHELL_GUEST_WINDOW_POSTMESSAGE', guestId, message, targetOrigin
ipc.on 'ATOM_SHELL_GUEST_WINDOW_MANAGER_WINDOW_OPENER_POSTMESSAGE', (event, guestId, message, targetOrigin, sourceOrigin) -> ipcMain.on 'ATOM_SHELL_GUEST_WINDOW_MANAGER_WINDOW_OPENER_POSTMESSAGE', (event, guestId, message, targetOrigin, sourceOrigin) ->
embedder = v8Util.getHiddenValue event.sender, 'embedder' embedder = v8Util.getHiddenValue event.sender, 'embedder'
if embedder?.getUrl().indexOf(targetOrigin) is 0 or targetOrigin is '*' if embedder?.getUrl().indexOf(targetOrigin) is 0 or targetOrigin is '*'
embedder.send 'ATOM_SHELL_GUEST_WINDOW_POSTMESSAGE', guestId, message, sourceOrigin embedder.send 'ATOM_SHELL_GUEST_WINDOW_POSTMESSAGE', guestId, message, sourceOrigin
ipc.on 'ATOM_SHELL_GUEST_WINDOW_MANAGER_WEB_CONTENTS_METHOD', (event, guestId, method, args...) -> ipcMain.on 'ATOM_SHELL_GUEST_WINDOW_MANAGER_WEB_CONTENTS_METHOD', (event, guestId, method, args...) ->
BrowserWindow.fromId(guestId)?.webContents?[method] args... BrowserWindow.fromId(guestId)?.webContents?[method] args...
ipc.on 'ATOM_SHELL_GUEST_WINDOW_MANAGER_GET_GUEST_ID', (event) -> ipcMain.on 'ATOM_SHELL_GUEST_WINDOW_MANAGER_GET_GUEST_ID', (event) ->
embedder = v8Util.getHiddenValue event.sender, 'embedder' embedder = v8Util.getHiddenValue event.sender, 'embedder'
if embedder? if embedder?
guest = BrowserWindow.fromWebContents event.sender guest = BrowserWindow.fromWebContents event.sender

View file

@ -46,12 +46,13 @@ process.on 'uncaughtException', (error) ->
return return
# Show error in GUI. # Show error in GUI.
{dialog} = require 'electron'
stack = error.stack ? "#{error.name}: #{error.message}" stack = error.stack ? "#{error.name}: #{error.message}"
message = "Uncaught Exception:\n#{stack}" message = "Uncaught Exception:\n#{stack}"
require('dialog').showErrorBox 'A JavaScript error occurred in the main process', message dialog.showErrorBox 'A JavaScript error occurred in the main process', message
# Emit 'exit' event on quit. # Emit 'exit' event on quit.
app = require 'app' {app} = require 'electron'
app.on 'quit', -> app.on 'quit', ->
process.emit 'exit' process.emit 'exit'

View file

@ -1,4 +1,4 @@
EventEmitter = require('events').EventEmitter {EventEmitter} = require 'events'
v8Util = process.atomBinding 'v8_util' v8Util = process.atomBinding 'v8_util'
class ObjectsRegistry extends EventEmitter class ObjectsRegistry extends EventEmitter

View file

@ -1,8 +1,9 @@
ipc = require 'ipc-main' {ipcMain} = require 'electron'
path = require 'path' path = require 'path'
objectsRegistry = require './objects-registry.js' objectsRegistry = require './objects-registry'
v8Util = process.atomBinding 'v8_util' v8Util = process.atomBinding 'v8_util'
IDWeakMap = process.atomBinding('id_weak_map').IDWeakMap {IDWeakMap} = process.atomBinding 'id_weak_map'
# Convert a real value into meta data. # Convert a real value into meta data.
valueToMeta = (sender, value, optimizeSimpleObject=false) -> valueToMeta = (sender, value, optimizeSimpleObject=false) ->
@ -115,28 +116,28 @@ callFunction = (event, func, caller, args) ->
process.on 'ATOM_BROWSER_RELEASE_RENDER_VIEW', (id) -> process.on 'ATOM_BROWSER_RELEASE_RENDER_VIEW', (id) ->
objectsRegistry.clear id objectsRegistry.clear id
ipc.on 'ATOM_BROWSER_REQUIRE', (event, module) -> ipcMain.on 'ATOM_BROWSER_REQUIRE', (event, module) ->
try try
event.returnValue = valueToMeta event.sender, process.mainModule.require(module) event.returnValue = valueToMeta event.sender, process.mainModule.require(module)
catch e catch e
event.returnValue = exceptionToMeta e event.returnValue = exceptionToMeta e
ipc.on 'ATOM_BROWSER_GLOBAL', (event, name) -> ipcMain.on 'ATOM_BROWSER_GLOBAL', (event, name) ->
try try
event.returnValue = valueToMeta event.sender, global[name] event.returnValue = valueToMeta event.sender, global[name]
catch e catch e
event.returnValue = exceptionToMeta e event.returnValue = exceptionToMeta e
ipc.on 'ATOM_BROWSER_CURRENT_WINDOW', (event) -> ipcMain.on 'ATOM_BROWSER_CURRENT_WINDOW', (event) ->
try try
event.returnValue = valueToMeta event.sender, event.sender.getOwnerBrowserWindow() event.returnValue = valueToMeta event.sender, event.sender.getOwnerBrowserWindow()
catch e catch e
event.returnValue = exceptionToMeta e event.returnValue = exceptionToMeta e
ipc.on 'ATOM_BROWSER_CURRENT_WEB_CONTENTS', (event) -> ipcMain.on 'ATOM_BROWSER_CURRENT_WEB_CONTENTS', (event) ->
event.returnValue = valueToMeta event.sender, event.sender event.returnValue = valueToMeta event.sender, event.sender
ipc.on 'ATOM_BROWSER_CONSTRUCTOR', (event, id, args) -> ipcMain.on 'ATOM_BROWSER_CONSTRUCTOR', (event, id, args) ->
try try
args = unwrapArgs event.sender, args args = unwrapArgs event.sender, args
constructor = objectsRegistry.get id constructor = objectsRegistry.get id
@ -147,7 +148,7 @@ ipc.on 'ATOM_BROWSER_CONSTRUCTOR', (event, id, args) ->
catch e catch e
event.returnValue = exceptionToMeta e event.returnValue = exceptionToMeta e
ipc.on 'ATOM_BROWSER_FUNCTION_CALL', (event, id, args) -> ipcMain.on 'ATOM_BROWSER_FUNCTION_CALL', (event, id, args) ->
try try
args = unwrapArgs event.sender, args args = unwrapArgs event.sender, args
func = objectsRegistry.get id func = objectsRegistry.get id
@ -155,7 +156,7 @@ ipc.on 'ATOM_BROWSER_FUNCTION_CALL', (event, id, args) ->
catch e catch e
event.returnValue = exceptionToMeta e event.returnValue = exceptionToMeta e
ipc.on 'ATOM_BROWSER_MEMBER_CONSTRUCTOR', (event, id, method, args) -> ipcMain.on 'ATOM_BROWSER_MEMBER_CONSTRUCTOR', (event, id, method, args) ->
try try
args = unwrapArgs event.sender, args args = unwrapArgs event.sender, args
constructor = objectsRegistry.get(id)[method] constructor = objectsRegistry.get(id)[method]
@ -165,7 +166,7 @@ ipc.on 'ATOM_BROWSER_MEMBER_CONSTRUCTOR', (event, id, method, args) ->
catch e catch e
event.returnValue = exceptionToMeta e event.returnValue = exceptionToMeta e
ipc.on 'ATOM_BROWSER_MEMBER_CALL', (event, id, method, args) -> ipcMain.on 'ATOM_BROWSER_MEMBER_CALL', (event, id, method, args) ->
try try
args = unwrapArgs event.sender, args args = unwrapArgs event.sender, args
obj = objectsRegistry.get id obj = objectsRegistry.get id
@ -173,7 +174,7 @@ ipc.on 'ATOM_BROWSER_MEMBER_CALL', (event, id, method, args) ->
catch e catch e
event.returnValue = exceptionToMeta e event.returnValue = exceptionToMeta e
ipc.on 'ATOM_BROWSER_MEMBER_SET', (event, id, name, value) -> ipcMain.on 'ATOM_BROWSER_MEMBER_SET', (event, id, name, value) ->
try try
obj = objectsRegistry.get id obj = objectsRegistry.get id
obj[name] = value obj[name] = value
@ -181,17 +182,17 @@ ipc.on 'ATOM_BROWSER_MEMBER_SET', (event, id, name, value) ->
catch e catch e
event.returnValue = exceptionToMeta e event.returnValue = exceptionToMeta e
ipc.on 'ATOM_BROWSER_MEMBER_GET', (event, id, name) -> ipcMain.on 'ATOM_BROWSER_MEMBER_GET', (event, id, name) ->
try try
obj = objectsRegistry.get id obj = objectsRegistry.get id
event.returnValue = valueToMeta event.sender, obj[name] event.returnValue = valueToMeta event.sender, obj[name]
catch e catch e
event.returnValue = exceptionToMeta e event.returnValue = exceptionToMeta e
ipc.on 'ATOM_BROWSER_DEREFERENCE', (event, id) -> ipcMain.on 'ATOM_BROWSER_DEREFERENCE', (event, id) ->
objectsRegistry.remove event.sender.getId(), id objectsRegistry.remove event.sender.getId(), id
ipc.on 'ATOM_BROWSER_GUEST_WEB_CONTENTS', (event, guestInstanceId) -> ipcMain.on 'ATOM_BROWSER_GUEST_WEB_CONTENTS', (event, guestInstanceId) ->
try try
guestViewManager = require './guest-view-manager' guestViewManager = require './guest-view-manager'
event.returnValue = valueToMeta event.sender, guestViewManager.getGuest(guestInstanceId) event.returnValue = valueToMeta event.sender, guestViewManager.getGuest(guestInstanceId)

View file

@ -1,5 +1,6 @@
if process.platform is 'linux' and process.type is 'renderer' if process.platform is 'linux' and process.type is 'renderer'
{remote} = require 'electron'
# On Linux we could not access clipboard in renderer process. # On Linux we could not access clipboard in renderer process.
module.exports = require('remote').require 'clipboard' module.exports = remote.require 'clipboard'
else else
module.exports = process.atomBinding 'clipboard' module.exports = process.atomBinding 'clipboard'

View file

@ -8,11 +8,12 @@ class CrashReporter
start: (options={}) -> start: (options={}) ->
{@productName, companyName, submitUrl, autoSubmit, ignoreSystemCrashHandler, extra} = options {@productName, companyName, submitUrl, autoSubmit, ignoreSystemCrashHandler, extra} = options
app = electron = require 'electron'
{app} =
if process.type is 'browser' if process.type is 'browser'
require 'app' electron
else else
require('remote').require 'app' electron.remote.require 'electron'
@productName ?= app.getName() @productName ?= app.getName()
companyName ?= 'GitHub, Inc' companyName ?= 'GitHub, Inc'

View file

@ -13,3 +13,8 @@ Object.defineProperties exports,
shell: shell:
enumerable: true enumerable: true
get: -> require '../shell' get: -> require '../shell'
# The internal modules, invisible unless you know their names.
CallbacksRegistry:
get: -> require '../callbacks-registry'
deprecate:
get: -> require '../deprecate'

View file

@ -1,5 +1,4 @@
deprecate = require 'deprecate' {ipcRenderer, deprecate} = require 'electron'
ipcRenderer = require 'ipc-renderer'
{EventEmitter} = require 'events' {EventEmitter} = require 'events'
# This module is deprecated, we mirror everything from ipcRenderer. # This module is deprecated, we mirror everything from ipcRenderer.

View file

@ -1,6 +1,5 @@
ipc = require 'ipc-renderer' {ipcRenderer, CallbacksRegistry} = require 'electron'
v8Util = process.atomBinding 'v8_util' v8Util = process.atomBinding 'v8_util'
CallbacksRegistry = require 'callbacks-registry'
callbacksRegistry = new CallbacksRegistry callbacksRegistry = new CallbacksRegistry
@ -58,7 +57,7 @@ metaToValue = (meta) ->
constructor: -> constructor: ->
if @constructor == RemoteFunction if @constructor == RemoteFunction
# Constructor call. # Constructor call.
obj = ipc.sendSync 'ATOM_BROWSER_CONSTRUCTOR', meta.id, wrapArgs(arguments) obj = ipcRenderer.sendSync 'ATOM_BROWSER_CONSTRUCTOR', meta.id, wrapArgs(arguments)
# Returning object in constructor will replace constructed object # Returning object in constructor will replace constructed object
# with the returned object. # with the returned object.
@ -66,7 +65,7 @@ metaToValue = (meta) ->
return metaToValue obj return metaToValue obj
else else
# Function call. # Function call.
ret = ipc.sendSync 'ATOM_BROWSER_FUNCTION_CALL', meta.id, wrapArgs(arguments) ret = ipcRenderer.sendSync 'ATOM_BROWSER_FUNCTION_CALL', meta.id, wrapArgs(arguments)
return metaToValue ret return metaToValue ret
else else
ret = v8Util.createObjectWithName meta.name ret = v8Util.createObjectWithName meta.name
@ -80,11 +79,11 @@ metaToValue = (meta) ->
constructor: -> constructor: ->
if @constructor is RemoteMemberFunction if @constructor is RemoteMemberFunction
# Constructor call. # Constructor call.
obj = ipc.sendSync 'ATOM_BROWSER_MEMBER_CONSTRUCTOR', meta.id, member.name, wrapArgs(arguments) obj = ipcRenderer.sendSync 'ATOM_BROWSER_MEMBER_CONSTRUCTOR', meta.id, member.name, wrapArgs(arguments)
return metaToValue obj return metaToValue obj
else else
# Call member function. # Call member function.
ret = ipc.sendSync 'ATOM_BROWSER_MEMBER_CALL', meta.id, member.name, wrapArgs(arguments) ret = ipcRenderer.sendSync 'ATOM_BROWSER_MEMBER_CALL', meta.id, member.name, wrapArgs(arguments)
return metaToValue ret return metaToValue ret
else else
Object.defineProperty ret, member.name, Object.defineProperty ret, member.name,
@ -92,18 +91,18 @@ metaToValue = (meta) ->
configurable: false, configurable: false,
set: (value) -> set: (value) ->
# Set member data. # Set member data.
ipc.sendSync 'ATOM_BROWSER_MEMBER_SET', meta.id, member.name, value ipcRenderer.sendSync 'ATOM_BROWSER_MEMBER_SET', meta.id, member.name, value
value value
get: -> get: ->
# Get member data. # Get member data.
ret = ipc.sendSync 'ATOM_BROWSER_MEMBER_GET', meta.id, member.name ret = ipcRenderer.sendSync 'ATOM_BROWSER_MEMBER_GET', meta.id, member.name
metaToValue ret metaToValue ret
# Track delegate object's life time, and tell the browser to clean up # Track delegate object's life time, and tell the browser to clean up
# when the object is GCed. # when the object is GCed.
v8Util.setDestructor ret, -> v8Util.setDestructor ret, ->
ipc.send 'ATOM_BROWSER_DEREFERENCE', meta.id ipcRenderer.send 'ATOM_BROWSER_DEREFERENCE', meta.id
# Remember object's id. # Remember object's id.
v8Util.setHiddenValue ret, 'atomId', meta.id v8Util.setHiddenValue ret, 'atomId', meta.id
@ -119,11 +118,11 @@ metaToPlainObject = (meta) ->
obj obj
# Browser calls a callback in renderer. # Browser calls a callback in renderer.
ipc.on 'ATOM_RENDERER_CALLBACK', (event, id, args) -> ipcRenderer.on 'ATOM_RENDERER_CALLBACK', (event, id, args) ->
callbacksRegistry.apply id, metaToValue(args) callbacksRegistry.apply id, metaToValue(args)
# A callback in browser is released. # A callback in browser is released.
ipc.on 'ATOM_RENDERER_RELEASE_CALLBACK', (event, id) -> ipcRenderer.on 'ATOM_RENDERER_RELEASE_CALLBACK', (event, id) ->
callbacksRegistry.remove id callbacksRegistry.remove id
# Get remote module. # Get remote module.
@ -133,26 +132,26 @@ moduleCache = {}
exports.require = (module) -> exports.require = (module) ->
return moduleCache[module] if moduleCache[module]? return moduleCache[module] if moduleCache[module]?
meta = ipc.sendSync 'ATOM_BROWSER_REQUIRE', module meta = ipcRenderer.sendSync 'ATOM_BROWSER_REQUIRE', module
moduleCache[module] = metaToValue meta moduleCache[module] = metaToValue meta
# Get current BrowserWindow object. # Get current BrowserWindow object.
windowCache = null windowCache = null
exports.getCurrentWindow = -> exports.getCurrentWindow = ->
return windowCache if windowCache? return windowCache if windowCache?
meta = ipc.sendSync 'ATOM_BROWSER_CURRENT_WINDOW' meta = ipcRenderer.sendSync 'ATOM_BROWSER_CURRENT_WINDOW'
windowCache = metaToValue meta windowCache = metaToValue meta
# Get current WebContents object. # Get current WebContents object.
webContentsCache = null webContentsCache = null
exports.getCurrentWebContents = -> exports.getCurrentWebContents = ->
return webContentsCache if webContentsCache? return webContentsCache if webContentsCache?
meta = ipc.sendSync 'ATOM_BROWSER_CURRENT_WEB_CONTENTS' meta = ipcRenderer.sendSync 'ATOM_BROWSER_CURRENT_WEB_CONTENTS'
webContentsCache = metaToValue meta webContentsCache = metaToValue meta
# Get a global object in browser. # Get a global object in browser.
exports.getGlobal = (name) -> exports.getGlobal = (name) ->
meta = ipc.sendSync 'ATOM_BROWSER_GLOBAL', name meta = ipcRenderer.sendSync 'ATOM_BROWSER_GLOBAL', name
metaToValue meta metaToValue meta
# Get the process object in browser. # Get the process object in browser.
@ -169,5 +168,5 @@ exports.createFunctionWithReturnValue = (returnValue) ->
# Get the guest WebContents from guestInstanceId. # Get the guest WebContents from guestInstanceId.
exports.getGuestWebContents = (guestInstanceId) -> exports.getGuestWebContents = (guestInstanceId) ->
meta = ipc.sendSync 'ATOM_BROWSER_GUEST_WEB_CONTENTS', guestInstanceId meta = ipcRenderer.sendSync 'ATOM_BROWSER_GUEST_WEB_CONTENTS', guestInstanceId
metaToValue meta metaToValue meta

View file

@ -1 +1 @@
module.exports = require('remote').require('screen') module.exports = require('electron').remote.require('electron').screen

View file

@ -32,8 +32,8 @@ convertToMenuTemplate = (items) ->
template template
createMenu = (x, y, items, document) -> createMenu = (x, y, items, document) ->
remote = require 'remote' {remote} = require 'electron'
Menu = remote.require 'menu' {Menu} = remote.require 'electron'
menu = Menu.buildFromTemplate convertToMenuTemplate(items) menu = Menu.buildFromTemplate convertToMenuTemplate(items)
# The menu is expected to show asynchronously. # The menu is expected to show asynchronously.
@ -42,8 +42,8 @@ createMenu = (x, y, items, document) ->
DevToolsAPI.contextMenuCleared() DevToolsAPI.contextMenuCleared()
showFileChooserDialog = (callback) -> showFileChooserDialog = (callback) ->
remote = require 'remote' {remote} = require 'electron'
dialog = remote.require 'dialog' {dialog} = remote.require 'electron'
files = dialog.showOpenDialog {} files = dialog.showOpenDialog {}
callback pathToHtml5FileObject files[0] if files? callback pathToHtml5FileObject files[0] if files?

View file

@ -1,5 +1,4 @@
ipc = require 'ipc-renderer' {ipcRenderer, remote} = require 'electron'
remote = require 'remote'
# Helper function to resolve relative url. # Helper function to resolve relative url.
a = window.top.document.createElement 'a' a = window.top.document.createElement 'a'
@ -11,24 +10,24 @@ resolveUrl = (url) ->
class BrowserWindowProxy class BrowserWindowProxy
constructor: (@guestId) -> constructor: (@guestId) ->
@closed = false @closed = false
ipc.on 'ATOM_SHELL_GUEST_WINDOW_MANAGER_WINDOW_CLOSED', (event, guestId) => ipcRenderer.on 'ATOM_SHELL_GUEST_WINDOW_MANAGER_WINDOW_CLOSED', (event, guestId) =>
if guestId is @guestId if guestId is @guestId
@closed = true @closed = true
close: -> close: ->
ipc.send 'ATOM_SHELL_GUEST_WINDOW_MANAGER_WINDOW_CLOSE', @guestId ipcRenderer.send 'ATOM_SHELL_GUEST_WINDOW_MANAGER_WINDOW_CLOSE', @guestId
focus: -> focus: ->
ipc.send 'ATOM_SHELL_GUEST_WINDOW_MANAGER_WINDOW_METHOD', @guestId, 'focus' ipcRenderer.send 'ATOM_SHELL_GUEST_WINDOW_MANAGER_WINDOW_METHOD', @guestId, 'focus'
blur: -> blur: ->
ipc.send 'ATOM_SHELL_GUEST_WINDOW_MANAGER_WINDOW_METHOD', @guestId, 'blur' ipcRenderer.send 'ATOM_SHELL_GUEST_WINDOW_MANAGER_WINDOW_METHOD', @guestId, 'blur'
postMessage: (message, targetOrigin='*') -> postMessage: (message, targetOrigin='*') ->
ipc.send 'ATOM_SHELL_GUEST_WINDOW_MANAGER_WINDOW_POSTMESSAGE', @guestId, message, targetOrigin ipcRenderer.send 'ATOM_SHELL_GUEST_WINDOW_MANAGER_WINDOW_POSTMESSAGE', @guestId, message, targetOrigin
eval: (args...) -> eval: (args...) ->
ipc.send 'ATOM_SHELL_GUEST_WINDOW_MANAGER_WEB_CONTENTS_METHOD', @guestId, 'executeJavaScript', args... ipcRenderer.send 'ATOM_SHELL_GUEST_WINDOW_MANAGER_WEB_CONTENTS_METHOD', @guestId, 'executeJavaScript', args...
unless process.guestInstanceId? unless process.guestInstanceId?
# Override default window.close. # Override default window.close.
@ -60,7 +59,7 @@ window.open = (url, frameName='', features='') ->
(options[name] = parseInt(options[name], 10) if options[name]?) for name in ints (options[name] = parseInt(options[name], 10) if options[name]?) for name in ints
guestId = ipc.sendSync 'ATOM_SHELL_GUEST_WINDOW_MANAGER_WINDOW_OPEN', url, frameName, options guestId = ipcRenderer.sendSync 'ATOM_SHELL_GUEST_WINDOW_MANAGER_WINDOW_OPEN', url, frameName, options
if guestId if guestId
new BrowserWindowProxy(guestId) new BrowserWindowProxy(guestId)
else else
@ -87,13 +86,13 @@ window.prompt = ->
throw new Error('prompt() is and will not be supported.') throw new Error('prompt() is and will not be supported.')
# Implement window.postMessage if current window is a guest window. # Implement window.postMessage if current window is a guest window.
guestId = ipc.sendSync 'ATOM_SHELL_GUEST_WINDOW_MANAGER_GET_GUEST_ID' guestId = ipcRenderer.sendSync 'ATOM_SHELL_GUEST_WINDOW_MANAGER_GET_GUEST_ID'
if guestId? if guestId?
window.opener = window.opener =
postMessage: (message, targetOrigin='*') -> postMessage: (message, targetOrigin='*') ->
ipc.send 'ATOM_SHELL_GUEST_WINDOW_MANAGER_WINDOW_OPENER_POSTMESSAGE', guestId, message, targetOrigin, location.origin ipcRenderer.send 'ATOM_SHELL_GUEST_WINDOW_MANAGER_WINDOW_OPENER_POSTMESSAGE', guestId, message, targetOrigin, location.origin
ipc.on 'ATOM_SHELL_GUEST_WINDOW_POSTMESSAGE', (event, guestId, message, sourceOrigin) -> ipcRenderer.on 'ATOM_SHELL_GUEST_WINDOW_POSTMESSAGE', (event, guestId, message, sourceOrigin) ->
# Manually dispatch event instead of using postMessage because we also need to # Manually dispatch event instead of using postMessage because we also need to
# set event.source. # set event.source.
event = document.createEvent 'Event' event = document.createEvent 'Event'
@ -105,10 +104,10 @@ ipc.on 'ATOM_SHELL_GUEST_WINDOW_POSTMESSAGE', (event, guestId, message, sourceOr
# Forward history operations to browser. # Forward history operations to browser.
sendHistoryOperation = (args...) -> sendHistoryOperation = (args...) ->
ipc.send 'ATOM_SHELL_NAVIGATION_CONTROLLER', args... ipcRenderer.send 'ATOM_SHELL_NAVIGATION_CONTROLLER', args...
getHistoryOperation = (args...) -> getHistoryOperation = (args...) ->
ipc.sendSync 'ATOM_SHELL_SYNC_NAVIGATION_CONTROLLER', args... ipcRenderer.sendSync 'ATOM_SHELL_SYNC_NAVIGATION_CONTROLLER', args...
window.history.back = -> sendHistoryOperation 'goBack' window.history.back = -> sendHistoryOperation 'goBack'
window.history.forward = -> sendHistoryOperation 'goForward' window.history.forward = -> sendHistoryOperation 'goForward'

View file

@ -1,5 +1,4 @@
ipc = require 'ipc-renderer' {ipcRenderer, webFrame} = require 'electron'
webFrame = require 'web-frame'
requestId = 0 requestId = 0
@ -37,40 +36,40 @@ dispatchEvent = (webView, event, args...) ->
module.exports = module.exports =
registerEvents: (webView, viewInstanceId) -> registerEvents: (webView, viewInstanceId) ->
ipc.on "ATOM_SHELL_GUEST_VIEW_INTERNAL_DISPATCH_EVENT-#{viewInstanceId}", (event, domEvent, args...) -> ipcRenderer.on "ATOM_SHELL_GUEST_VIEW_INTERNAL_DISPATCH_EVENT-#{viewInstanceId}", (event, domEvent, args...) ->
dispatchEvent webView, domEvent, args... dispatchEvent webView, domEvent, args...
ipc.on "ATOM_SHELL_GUEST_VIEW_INTERNAL_IPC_MESSAGE-#{viewInstanceId}", (event, channel, args...) -> ipcRenderer.on "ATOM_SHELL_GUEST_VIEW_INTERNAL_IPC_MESSAGE-#{viewInstanceId}", (event, channel, args...) ->
domEvent = new Event('ipc-message') domEvent = new Event('ipc-message')
domEvent.channel = channel domEvent.channel = channel
domEvent.args = [args...] domEvent.args = [args...]
webView.dispatchEvent domEvent webView.dispatchEvent domEvent
ipc.on "ATOM_SHELL_GUEST_VIEW_INTERNAL_SIZE_CHANGED-#{viewInstanceId}", (event, args...) -> ipcRenderer.on "ATOM_SHELL_GUEST_VIEW_INTERNAL_SIZE_CHANGED-#{viewInstanceId}", (event, args...) ->
domEvent = new Event('size-changed') domEvent = new Event('size-changed')
for f, i in ['oldWidth', 'oldHeight', 'newWidth', 'newHeight'] for f, i in ['oldWidth', 'oldHeight', 'newWidth', 'newHeight']
domEvent[f] = args[i] domEvent[f] = args[i]
webView.onSizeChanged domEvent webView.onSizeChanged domEvent
deregisterEvents: (viewInstanceId) -> deregisterEvents: (viewInstanceId) ->
ipc.removeAllListeners "ATOM_SHELL_GUEST_VIEW_INTERNAL_DISPATCH_EVENT-#{viewInstanceId}" ipcRenderer.removeAllListeners "ATOM_SHELL_GUEST_VIEW_INTERNAL_DISPATCH_EVENT-#{viewInstanceId}"
ipc.removeAllListeners "ATOM_SHELL_GUEST_VIEW_INTERNAL_IPC_MESSAGE-#{viewInstanceId}" ipcRenderer.removeAllListeners "ATOM_SHELL_GUEST_VIEW_INTERNAL_IPC_MESSAGE-#{viewInstanceId}"
ipc.removeAllListeners "ATOM_SHELL_GUEST_VIEW_INTERNAL_SIZE_CHANGED-#{viewInstanceId}" ipcRenderer.removeAllListeners "ATOM_SHELL_GUEST_VIEW_INTERNAL_SIZE_CHANGED-#{viewInstanceId}"
createGuest: (params, callback) -> createGuest: (params, callback) ->
requestId++ requestId++
ipc.send 'ATOM_SHELL_GUEST_VIEW_MANAGER_CREATE_GUEST', params, requestId ipcRenderer.send 'ATOM_SHELL_GUEST_VIEW_MANAGER_CREATE_GUEST', params, requestId
ipc.once "ATOM_SHELL_RESPONSE_#{requestId}", callback ipcRenderer.once "ATOM_SHELL_RESPONSE_#{requestId}", callback
attachGuest: (elementInstanceId, guestInstanceId, params) -> attachGuest: (elementInstanceId, guestInstanceId, params) ->
ipc.send 'ATOM_SHELL_GUEST_VIEW_MANAGER_ATTACH_GUEST', elementInstanceId, guestInstanceId, params ipcRenderer.send 'ATOM_SHELL_GUEST_VIEW_MANAGER_ATTACH_GUEST', elementInstanceId, guestInstanceId, params
webFrame.attachGuest elementInstanceId webFrame.attachGuest elementInstanceId
destroyGuest: (guestInstanceId) -> destroyGuest: (guestInstanceId) ->
ipc.send 'ATOM_SHELL_GUEST_VIEW_MANAGER_DESTROY_GUEST', guestInstanceId ipcRenderer.send 'ATOM_SHELL_GUEST_VIEW_MANAGER_DESTROY_GUEST', guestInstanceId
setSize: (guestInstanceId, params) -> setSize: (guestInstanceId, params) ->
ipc.send 'ATOM_SHELL_GUEST_VIEW_MANAGER_SET_SIZE', guestInstanceId, params ipcRenderer.send 'ATOM_SHELL_GUEST_VIEW_MANAGER_SET_SIZE', guestInstanceId, params
setAllowTransparency: (guestInstanceId, allowtransparency) -> setAllowTransparency: (guestInstanceId, allowtransparency) ->
ipc.send 'ATOM_SHELL_GUEST_VIEW_MANAGER_SET_ALLOW_TRANSPARENCY', guestInstanceId, allowtransparency ipcRenderer.send 'ATOM_SHELL_GUEST_VIEW_MANAGER_SET_ALLOW_TRANSPARENCY', guestInstanceId, allowtransparency

View file

@ -1,7 +1,8 @@
WebViewImpl = require './web-view' WebViewImpl = require './web-view'
guestViewInternal = require './guest-view-internal' guestViewInternal = require './guest-view-internal'
webViewConstants = require './web-view-constants' webViewConstants = require './web-view-constants'
remote = require 'remote'
{remote} = require 'electron'
# Helper function to resolve url set in attribute. # Helper function to resolve url set in attribute.
a = document.createElement 'a' a = document.createElement 'a'

View file

@ -1,8 +1,8 @@
{webFrame, remote} = require 'electron'
v8Util = process.atomBinding 'v8_util' v8Util = process.atomBinding 'v8_util'
guestViewInternal = require './guest-view-internal' guestViewInternal = require './guest-view-internal'
webViewConstants = require './web-view-constants' webViewConstants = require './web-view-constants'
webFrame = require 'web-frame'
remote = require 'remote'
# ID generator. # ID generator.
nextId = 0 nextId = 0

View file

@ -1,7 +1,6 @@
assert = require 'assert' assert = require 'assert'
remote = require 'remote' {remote} = require 'electron'
app = remote.require 'app' {app, BrowserWindow} = remote.require 'electron'
BrowserWindow = remote.require 'browser-window'
describe 'app module', -> describe 'app module', ->
describe 'app.getVersion()', -> describe 'app.getVersion()', ->

View file

@ -1,12 +1,12 @@
assert = require 'assert' assert = require 'assert'
fs = require 'fs' fs = require 'fs'
path = require 'path' path = require 'path'
remote = require 'remote'
http = require 'http' http = require 'http'
url = require 'url' url = require 'url'
os = require 'os' os = require 'os'
BrowserWindow = remote.require 'browser-window' {remote, screen} = require 'electron'
{ipcMain, BrowserWindow} = remote.require 'electron'
isCI = remote.process.argv[2] == '--ci' isCI = remote.process.argv[2] == '--ci'
@ -191,7 +191,7 @@ describe 'browser-window module', ->
assert.equal after[1], -10 assert.equal after[1], -10
it 'can set the window larger than screen', -> it 'can set the window larger than screen', ->
size = require('screen').getPrimaryDisplay().size size = screen.getPrimaryDisplay().size
size.width += 100 size.width += 100
size.height += 100 size.height += 100
w.setSize size.width, size.height w.setSize size.width, size.height
@ -201,12 +201,12 @@ describe 'browser-window module', ->
describe '"web-preferences" option', -> describe '"web-preferences" option', ->
afterEach -> afterEach ->
remote.require('ipc-main').removeAllListeners('answer') ipcMain.removeAllListeners('answer')
describe '"preload" option', -> describe '"preload" option', ->
it 'loads the script before other scripts in window', (done) -> it 'loads the script before other scripts in window', (done) ->
preload = path.join fixtures, 'module', 'set-global.js' preload = path.join fixtures, 'module', 'set-global.js'
remote.require('ipc-main').once 'answer', (event, test) -> ipcMain.once 'answer', (event, test) ->
assert.equal(test, 'preload') assert.equal(test, 'preload')
done() done()
w.destroy() w.destroy()
@ -219,7 +219,7 @@ describe 'browser-window module', ->
describe '"node-integration" option', -> describe '"node-integration" option', ->
it 'disables node integration when specified to false', (done) -> it 'disables node integration when specified to false', (done) ->
preload = path.join fixtures, 'module', 'send-later.js' preload = path.join fixtures, 'module', 'send-later.js'
remote.require('ipc-main').once 'answer', (event, test) -> ipcMain.once 'answer', (event, test) ->
assert.equal(test, 'undefined') assert.equal(test, 'undefined')
done() done()
w.destroy() w.destroy()

View file

@ -1,8 +1,8 @@
assert = require 'assert' assert = require 'assert'
clipboard = require 'clipboard'
nativeImage = require 'native-image'
path = require 'path' path = require 'path'
{clipboard, nativeImage} = require 'electron'
describe 'clipboard module', -> describe 'clipboard module', ->
fixtures = path.resolve __dirname, 'fixtures' fixtures = path.resolve __dirname, 'fixtures'

View file

@ -2,11 +2,10 @@ assert = require 'assert'
path = require 'path' path = require 'path'
http = require 'http' http = require 'http'
url = require 'url' url = require 'url'
remote = require 'remote'
multiparty = require 'multiparty' multiparty = require 'multiparty'
crashReporter = remote.require 'crash-reporter' {remote} = require 'electron'
BrowserWindow = remote.require 'browser-window' {app, crashReporter, BrowserWindow} = remote.require 'electron'
describe 'crash-reporter module', -> describe 'crash-reporter module', ->
fixtures = path.resolve __dirname, 'fixtures' fixtures = path.resolve __dirname, 'fixtures'
@ -41,7 +40,7 @@ describe 'crash-reporter module', ->
assert.equal fields['extra2'], 'extra2' assert.equal fields['extra2'], 'extra2'
assert.equal fields['_productName'], 'Zombies' assert.equal fields['_productName'], 'Zombies'
assert.equal fields['_companyName'], 'Umbrella Corporation' assert.equal fields['_companyName'], 'Umbrella Corporation'
assert.equal fields['_version'], require('remote').require('app').getVersion() assert.equal fields['_version'], app.getVersion()
res.end('abc-123-def') res.end('abc-123-def')
done() done()

View file

@ -1,9 +1,8 @@
assert = require 'assert' assert = require 'assert'
ipc = require 'ipc-renderer'
path = require 'path' path = require 'path'
remote = require 'remote'
BrowserWindow = remote.require 'browser-window' {ipcRenderer, remote} = require 'electron'
{ipcMain, BrowserWindow} = remote.require 'electron'
comparePaths = (path1, path2) -> comparePaths = (path1, path2) ->
if process.platform is 'win32' if process.platform is 'win32'
@ -17,8 +16,8 @@ describe 'ipc module', ->
describe 'remote.require', -> describe 'remote.require', ->
it 'should returns same object for the same module', -> it 'should returns same object for the same module', ->
dialog1 = remote.require 'dialog' dialog1 = remote.require 'electron'
dialog2 = remote.require 'dialog' dialog2 = remote.require 'electron'
assert.equal dialog1, dialog2 assert.equal dialog1, dialog2
it 'should work when object contains id property', -> it 'should work when object contains id property', ->
@ -70,20 +69,20 @@ describe 'ipc module', ->
describe 'ipc.sender.send', -> describe 'ipc.sender.send', ->
it 'should work when sending an object containing id property', (done) -> it 'should work when sending an object containing id property', (done) ->
obj = id: 1, name: 'ly' obj = id: 1, name: 'ly'
ipc.once 'message', (event, message) -> ipcRenderer.once 'message', (event, message) ->
assert.deepEqual message, obj assert.deepEqual message, obj
done() done()
ipc.send 'message', obj ipcRenderer.send 'message', obj
describe 'ipc.sendSync', -> describe 'ipc.sendSync', ->
it 'can be replied by setting event.returnValue', -> it 'can be replied by setting event.returnValue', ->
msg = ipc.sendSync 'echo', 'test' msg = ipcRenderer.sendSync 'echo', 'test'
assert.equal msg, 'test' assert.equal msg, 'test'
it 'does not crash when reply is not sent and browser is destroyed', (done) -> it 'does not crash when reply is not sent and browser is destroyed', (done) ->
@timeout 10000 @timeout 10000
w = new BrowserWindow(show: false) w = new BrowserWindow(show: false)
remote.require('ipc-main').once 'send-sync-message', (event) -> ipcMain.once 'send-sync-message', (event) ->
event.returnValue = null event.returnValue = null
w.destroy() w.destroy()
done() done()

View file

@ -1,8 +1,7 @@
assert = require 'assert' assert = require 'assert'
remote = require 'remote'
Menu = remote.require 'menu' {remote} = require 'electron'
MenuItem = remote.require 'menu-item' {Menu, MenuItem} = remote.require 'electron'
describe 'menu module', -> describe 'menu module', ->
describe 'Menu.buildFromTemplate', -> describe 'Menu.buildFromTemplate', ->

View file

@ -1,8 +1,9 @@
assert = require 'assert' assert = require 'assert'
http = require 'http' http = require 'http'
path = require 'path' path = require 'path'
remote = require 'remote'
protocol = remote.require 'protocol' {remote} = require 'electron'
{protocol} = remote.require 'electron'
describe 'protocol module', -> describe 'protocol module', ->
protocolName = 'sp' protocolName = 'sp'

View file

@ -1,5 +1,6 @@
assert = require 'assert' assert = require 'assert'
screen = require 'screen'
{screen} = require 'electron'
describe 'screen module', -> describe 'screen module', ->
describe 'screen.getCursorScreenPoint()', -> describe 'screen.getCursorScreenPoint()', ->

View file

@ -1,10 +1,10 @@
assert = require 'assert' assert = require 'assert'
remote = require 'remote'
http = require 'http' http = require 'http'
path = require 'path' path = require 'path'
fs = require 'fs' fs = require 'fs'
app = remote.require 'app'
BrowserWindow = remote.require 'browser-window' {ipcRenderer, remote} = require 'electron'
{app, ipcMain, BrowserWindow} = remote.require 'electron'
describe 'session module', -> describe 'session module', ->
@timeout 10000 @timeout 10000
@ -60,7 +60,6 @@ describe 'session module', ->
describe 'session.clearStorageData(options)', -> describe 'session.clearStorageData(options)', ->
fixtures = path.resolve __dirname, 'fixtures' fixtures = path.resolve __dirname, 'fixtures'
it 'clears localstorage data', (done) -> it 'clears localstorage data', (done) ->
ipcMain = remote.require('ipc-main')
ipcMain.on 'count', (event, count) -> ipcMain.on 'count', (event, count) ->
ipcMain.removeAllListeners 'count' ipcMain.removeAllListeners 'count'
assert not count assert not count
@ -78,7 +77,6 @@ describe 'session module', ->
# A 5 MB mock pdf. # A 5 MB mock pdf.
mockPDF = new Buffer 1024 * 1024 * 5 mockPDF = new Buffer 1024 * 1024 * 5
contentDisposition = 'inline; filename="mock.pdf"' contentDisposition = 'inline; filename="mock.pdf"'
ipc = require 'ipc-renderer'
downloadFilePath = path.join fixtures, 'mock.pdf' downloadFilePath = path.join fixtures, 'mock.pdf'
downloadServer = http.createServer (req, res) -> downloadServer = http.createServer (req, res) ->
res.writeHead 200, { res.writeHead 200, {
@ -92,9 +90,9 @@ describe 'session module', ->
it 'can download successfully', (done) -> it 'can download successfully', (done) ->
downloadServer.listen 0, '127.0.0.1', -> downloadServer.listen 0, '127.0.0.1', ->
{port} = downloadServer.address() {port} = downloadServer.address()
ipc.sendSync 'set-download-option', false ipcRenderer.sendSync 'set-download-option', false
w.loadUrl "#{url}:#{port}" w.loadUrl "#{url}:#{port}"
ipc.once 'download-done', (event, state, url, mimeType, receivedBytes, totalBytes, disposition, filename) -> ipcRenderer.once 'download-done', (event, state, url, mimeType, receivedBytes, totalBytes, disposition, filename) ->
assert.equal state, 'completed' assert.equal state, 'completed'
assert.equal filename, 'mock.pdf' assert.equal filename, 'mock.pdf'
assert.equal url, "http://127.0.0.1:#{port}/" assert.equal url, "http://127.0.0.1:#{port}/"
@ -109,9 +107,9 @@ describe 'session module', ->
it 'can cancel download', (done) -> it 'can cancel download', (done) ->
downloadServer.listen 0, '127.0.0.1', -> downloadServer.listen 0, '127.0.0.1', ->
{port} = downloadServer.address() {port} = downloadServer.address()
ipc.sendSync 'set-download-option', true ipcRenderer.sendSync 'set-download-option', true
w.loadUrl "#{url}:#{port}/" w.loadUrl "#{url}:#{port}/"
ipc.once 'download-done', (event, state, url, mimeType, receivedBytes, totalBytes, disposition, filename) -> ipcRenderer.once 'download-done', (event, state, url, mimeType, receivedBytes, totalBytes, disposition, filename) ->
assert.equal state, 'cancelled' assert.equal state, 'cancelled'
assert.equal filename, 'mock.pdf' assert.equal filename, 'mock.pdf'
assert.equal mimeType, 'application/pdf' assert.equal mimeType, 'application/pdf'

View file

@ -3,6 +3,9 @@ child_process = require 'child_process'
fs = require 'fs' fs = require 'fs'
path = require 'path' path = require 'path'
{nativeImage, remote} = require 'electron'
{ipcMain, BrowserWindow} = remote.require 'electron'
describe 'asar package', -> describe 'asar package', ->
fixtures = path.join __dirname, 'fixtures' fixtures = path.join __dirname, 'fixtures'
@ -406,9 +409,6 @@ describe 'asar package', ->
describe 'asar protocol', -> describe 'asar protocol', ->
url = require 'url' url = require 'url'
remote = require 'remote'
ipc = remote.require 'ipc-main'
BrowserWindow = remote.require 'browser-window'
it 'can request a file in package', (done) -> it 'can request a file in package', (done) ->
p = path.resolve fixtures, 'asar', 'a.asar', 'file1' p = path.resolve fixtures, 'asar', 'a.asar', 'file1'
@ -445,12 +445,12 @@ describe 'asar package', ->
it 'sets __dirname correctly', (done) -> it 'sets __dirname correctly', (done) ->
after -> after ->
w.destroy() w.destroy()
ipc.removeAllListeners 'dirname' ipcMain.removeAllListeners 'dirname'
w = new BrowserWindow(show: false, width: 400, height: 400) w = new BrowserWindow(show: false, width: 400, height: 400)
p = path.resolve fixtures, 'asar', 'web.asar', 'index.html' p = path.resolve fixtures, 'asar', 'web.asar', 'index.html'
u = url.format protocol: 'file', slashed: true, pathname: p u = url.format protocol: 'file', slashed: true, pathname: p
ipc.once 'dirname', (event, dirname) -> ipcMain.once 'dirname', (event, dirname) ->
assert.equal dirname, path.dirname(p) assert.equal dirname, path.dirname(p)
done() done()
w.loadUrl u w.loadUrl u
@ -458,13 +458,13 @@ describe 'asar package', ->
it 'loads script tag in html', (done) -> it 'loads script tag in html', (done) ->
after -> after ->
w.destroy() w.destroy()
ipc.removeAllListeners 'ping' ipcMain.removeAllListeners 'ping'
w = new BrowserWindow(show: false, width: 400, height: 400) w = new BrowserWindow(show: false, width: 400, height: 400)
p = path.resolve fixtures, 'asar', 'script.asar', 'index.html' p = path.resolve fixtures, 'asar', 'script.asar', 'index.html'
u = url.format protocol: 'file', slashed: true, pathname: p u = url.format protocol: 'file', slashed: true, pathname: p
w.loadUrl u w.loadUrl u
ipc.once 'ping', (event, message) -> ipcMain.once 'ping', (event, message) ->
assert.equal message, 'pong' assert.equal message, 'pong'
done() done()
@ -496,10 +496,10 @@ describe 'asar package', ->
describe 'native-image', -> describe 'native-image', ->
it 'reads image from asar archive', -> it 'reads image from asar archive', ->
p = path.join fixtures, 'asar', 'logo.asar', 'logo.png' p = path.join fixtures, 'asar', 'logo.asar', 'logo.png'
logo = require('native-image').createFromPath p logo = nativeImage.createFromPath p
assert.deepEqual logo.getSize(), {width: 55, height: 55} assert.deepEqual logo.getSize(), {width: 55, height: 55}
it 'reads image from asar archive with unpacked files', -> it 'reads image from asar archive with unpacked files', ->
p = path.join fixtures, 'asar', 'unpack.asar', 'atom.png' p = path.join fixtures, 'asar', 'unpack.asar', 'atom.png'
logo = require('native-image').createFromPath p logo = nativeImage.createFromPath p
assert.deepEqual logo.getSize(), {width: 1024, height: 1024} assert.deepEqual logo.getSize(), {width: 1024, height: 1024}

View file

@ -3,8 +3,9 @@ http = require 'http'
https = require 'https' https = require 'https'
path = require 'path' path = require 'path'
ws = require 'ws' ws = require 'ws'
remote = require 'remote'
BrowserWindow = remote.require 'browser-window' {remote} = require 'electron'
{BrowserWindow} = remote.require 'electron'
describe 'chromium feature', -> describe 'chromium feature', ->
fixtures = path.resolve __dirname, 'fixtures' fixtures = path.resolve __dirname, 'fixtures'

View file

@ -3,7 +3,7 @@
<script type="text/javascript" charset="utf-8"> <script type="text/javascript" charset="utf-8">
window.onbeforeunload = function() { window.onbeforeunload = function() {
setTimeout(function() { setTimeout(function() {
require('remote').getCurrentWindow().emit('onbeforeunload'); require('electron').remote.getCurrentWindow().emit('onbeforeunload');
}, 0); }, 0);
return false; return false;
} }

View file

@ -3,7 +3,7 @@
<script type="text/javascript" charset="utf-8"> <script type="text/javascript" charset="utf-8">
window.onbeforeunload = function() { window.onbeforeunload = function() {
setTimeout(function() { setTimeout(function() {
require('remote').getCurrentWindow().emit('onbeforeunload'); require('electron').remote.getCurrentWindow().emit('onbeforeunload');
}, 0); }, 0);
return ''; return '';
} }

View file

@ -3,7 +3,7 @@
<script type="text/javascript" charset="utf-8"> <script type="text/javascript" charset="utf-8">
window.onbeforeunload = function() { window.onbeforeunload = function() {
setTimeout(function() { setTimeout(function() {
require('remote').getCurrentWindow().emit('onbeforeunload'); require('electron').remote.getCurrentWindow().emit('onbeforeunload');
}, 0); }, 0);
return false; return false;
} }

View file

@ -3,7 +3,7 @@
<script type="text/javascript" charset="utf-8"> <script type="text/javascript" charset="utf-8">
window.onbeforeunload = function() { window.onbeforeunload = function() {
setTimeout(function() { setTimeout(function() {
require('remote').getCurrentWindow().emit('onbeforeunload'); require('electron').remote.getCurrentWindow().emit('onbeforeunload');
}, 0); }, 0);
return 'string'; return 'string';
} }

View file

@ -3,7 +3,7 @@
<script type="text/javascript" charset="utf-8"> <script type="text/javascript" charset="utf-8">
window.onbeforeunload = function() { window.onbeforeunload = function() {
setTimeout(function() { setTimeout(function() {
require('remote').getCurrentWindow().emit('onbeforeunload'); require('electron').remote.getCurrentWindow().emit('onbeforeunload');
}, 0); }, 0);
return true; return true;
} }

View file

@ -2,7 +2,7 @@
<body> <body>
<script type="text/javascript" charset="utf-8"> <script type="text/javascript" charset="utf-8">
var port = require('url').parse(window.location.href, true).query.port; var port = require('url').parse(window.location.href, true).query.port;
var crashReporter = require('crash-reporter'); var crashReporter = require('electron').crashReporter;
crashReporter.start({ crashReporter.start({
productName: 'Zombies', productName: 'Zombies',
companyName: 'Umbrella Corporation', companyName: 'Umbrella Corporation',

View file

@ -2,9 +2,9 @@
<body> <body>
<script type="text/javascript" charset="utf-8"> <script type="text/javascript" charset="utf-8">
window.localStorage.setItem('test', 'test'); window.localStorage.setItem('test', 'test');
var ipc = require('ipc-renderer'); var ipcRenderer = require('electron').ipcRenderer;
ipc.on('getcount', function() { ipcRenderer.on('getcount', function() {
ipc.send('count', window.localStorage.length); ipcRenderer.send('count', window.localStorage.length);
}) })
</script> </script>
</body> </body>

View file

@ -3,7 +3,7 @@
<script type="text/javascript" charset="utf-8"> <script type="text/javascript" charset="utf-8">
if (!window.test) if (!window.test)
window.test = 'window' window.test = 'window'
require('ipc-renderer').send('answer', window.test); require('electron').ipcRenderer.send('answer', window.test);
</script> </script>
</body> </body>
</html> </html>

View file

@ -1,8 +1,8 @@
<html> <html>
<body> <body>
<script type="text/javascript" charset="utf-8"> <script type="text/javascript" charset="utf-8">
var ipc = require('ipc-renderer'); var ipcRenderer = require('electron').ipcRenderer;
ipc.sendSync('send-sync-message', 'message'); ipcRenderer.sendSync('send-sync-message', 'message');
</script> </script>
</body> </body>
</html> </html>

Binary file not shown.

Binary file not shown.

View file

@ -1,4 +1,4 @@
var ipc = require('ipc-renderer'); var ipcRenderer = require('electron').ipcRenderer;
ipc.on('ping', function(event, message) { ipcRenderer.on('ping', function(event, message) {
ipc.sendToHost('pong', message); ipcRenderer.sendToHost('pong', message);
}); });

View file

@ -1,4 +1,4 @@
var ipc = require('ipc-renderer'); var ipcRenderer = require('electron').ipcRenderer;
window.onload = function() { window.onload = function() {
ipc.send('answer', typeof window.process); ipcRenderer.send('answer', typeof window.process);
} }

View file

@ -2,7 +2,7 @@
<body> <body>
<script src="../../static/jquery-2.0.3.min.js"></script> <script src="../../static/jquery-2.0.3.min.js"></script>
<script type="text/javascript" charset="utf-8"> <script type="text/javascript" charset="utf-8">
var ipc = require('ipc-renderer'); var ipcRenderer = require('electron').ipcRenderer;
var port = location.search.substr("?port=".length); var port = location.search.substr("?port=".length);
$.ajax({ $.ajax({
type: "GET", type: "GET",
@ -11,10 +11,10 @@
"Authorization": "Basic " + btoa("test:test") "Authorization": "Basic " + btoa("test:test")
}, },
success: function(result) { success: function(result) {
ipc.sendToHost(result); ipcRenderer.sendToHost(result);
}, },
error: function(xhr, status, error) { error: function(xhr, status, error) {
ipc.sendToHost(error); ipcRenderer.sendToHost(error);
}, },
}); });
</script> </script>

View file

@ -3,8 +3,8 @@
<script type="text/javascript" charset="utf-8"> <script type="text/javascript" charset="utf-8">
window.onbeforeunload = function() { window.onbeforeunload = function() {
setTimeout(function() { setTimeout(function() {
var ipc = require('ipc-renderer'); var ipcRenderer = require('electron').ipcRenderer;
ipc.sendToHost('onbeforeunload'); ipcRenderer.sendToHost('onbeforeunload');
}, 0); }, 0);
return false; return false;
} }

View file

@ -1,7 +1,7 @@
<html> <html>
<body> <body>
<script type="text/javascript" charset="utf-8"> <script type="text/javascript" charset="utf-8">
require('ipc-renderer').send('hidden', document.hidden); require('electron').ipcRenderer.send('hidden', document.hidden);
</script> </script>
</body> </body>
</html> </html>

View file

@ -2,7 +2,7 @@
<body> <body>
<script type="text/javascript" charset="utf-8"> <script type="text/javascript" charset="utf-8">
window.history.pushState(window.history.state, "test page", "foo.html") window.history.pushState(window.history.state, "test page", "foo.html")
require('ipc-renderer').sendToHost('history', window.history.length); require('electron').ipcRenderer.sendToHost('history', window.history.length);
</script> </script>
</body> </body>
</html> </html>

View file

@ -1,7 +1,7 @@
<html> <html>
<body> <body>
<script type="text/javascript" charset="utf-8"> <script type="text/javascript" charset="utf-8">
require('ipc-renderer').sendToHost('channel', 'arg1', 'arg2'); require('electron').ipcRenderer.sendToHost('channel', 'arg1', 'arg2');
</script> </script>
</body> </body>
</html> </html>

View file

@ -2,7 +2,7 @@
<body> <body>
<script type="text/javascript" charset="utf-8"> <script type="text/javascript" charset="utf-8">
document.onkeyup = function(e) { document.onkeyup = function(e) {
require('ipc-renderer').sendToHost('keyup', e.keyCode, e.shiftKey, e.ctrlKey); require('electron').ipcRenderer.sendToHost('keyup', e.keyCode, e.shiftKey, e.ctrlKey);
} }
</script> </script>
</body> </body>

View file

@ -2,7 +2,7 @@
<body> <body>
<script type="text/javascript" charset="utf-8"> <script type="text/javascript" charset="utf-8">
document.onmouseup = function(e) { document.onmouseup = function(e) {
require('ipc-renderer').sendToHost('mouseup', e.x, e.y, e.shiftKey, e.ctrlKey); require('electron').ipcRenderer.sendToHost('mouseup', e.x, e.y, e.shiftKey, e.ctrlKey);
} }
</script> </script>
</body> </body>

View file

@ -1,7 +1,7 @@
<html> <html>
<body> <body>
<script type="text/javascript" charset="utf-8"> <script type="text/javascript" charset="utf-8">
var size = require('remote').getCurrentWindow().getSize(); var size = require('electron').remote.getCurrentWindow().getSize();
window.opener.postMessage('size: ' + size.width + ' ' + size.height, '*') window.opener.postMessage('size: ' + size.width + ' ' + size.height, '*')
</script> </script>
</body> </body>

View file

@ -4,7 +4,7 @@
if (window.opener !== null) if (window.opener !== null)
window.opener.postMessage(typeof window.opener, '*'); window.opener.postMessage(typeof window.opener, '*');
else else
require('ipc-renderer').send('opener', window.opener); require('electron').ipcRenderer.send('opener', window.opener);
</script> </script>
</body> </body>
</html> </html>

View file

@ -3,7 +3,8 @@ child_process = require 'child_process'
fs = require 'fs' fs = require 'fs'
path = require 'path' path = require 'path'
os = require 'os' os = require 'os'
remote = require 'remote'
{remote} = require 'electron'
describe 'node feature', -> describe 'node feature', ->
fixtures = path.join __dirname, 'fixtures' fixtures = path.join __dirname, 'fixtures'

View file

@ -14,22 +14,25 @@
process.throwDeprecation = true; process.throwDeprecation = true;
// Check if we are running in CI. // Check if we are running in CI.
var argv = require('remote').process.argv; var electron = require ('electron');
var remote = electron.remote;
var ipcRenderer = electron.ipcRenderer;
var argv = remote.process.argv;
var isCi = argv[2] == '--ci'; var isCi = argv[2] == '--ci';
if (!isCi) { if (!isCi) {
var win = require('remote').getCurrentWindow(); var win = remote.getCurrentWindow();
win.show(); win.show();
win.focus(); win.focus();
} }
// Show DevTools. // Show DevTools.
document.oncontextmenu = function(e) { document.oncontextmenu = function(e) {
require('remote').getCurrentWindow().inspectElement(e.clientX, e.clientY); remote.getCurrentWindow().inspectElement(e.clientX, e.clientY);
} }
require('coffee-script/register'); // Supports .coffee tests. require('coffee-script/register'); // Supports .coffee tests.
var ipc = require('ipc-renderer');
// Rediret all output to browser. // Rediret all output to browser.
if (isCi) { if (isCi) {
@ -37,11 +40,11 @@
return { return {
log: function() { log: function() {
args = Array.prototype.slice.call(arguments); args = Array.prototype.slice.call(arguments);
ipc.send('console.log', args); ipcRenderer.send('console.log', args);
}, },
error: function() { error: function() {
args = Array.prototype.slice.call(arguments); args = Array.prototype.slice.call(arguments);
ipc.send('console.error', args); ipcRenderer.send('console.error', args);
}, },
} }
}); });
@ -70,7 +73,7 @@
var runner = mocha.run(function() { var runner = mocha.run(function() {
Mocha.utils.highlightTags('code'); Mocha.utils.highlightTags('code');
if (isCi) if (isCi)
ipc.send('process.exit', runner.failures); ipcRenderer.send('process.exit', runner.failures);
}); });
}); });
})(); })();

View file

@ -1,8 +1,10 @@
var app = require('app'); const electron = require('electron');
var ipc = require('ipc-main'); const app = electron.app;
var dialog = require('dialog'); const ipcMain = electron.ipcMain;
var path = require('path'); const dialog = electron.dialog;
var BrowserWindow = require('browser-window'); const BrowserWindow = electron.BrowserWindow;
const path = require('path');
var window = null; var window = null;
process.port = 0; // will be used by crash-reporter spec. process.port = 0; // will be used by crash-reporter spec.
@ -16,27 +18,27 @@ app.commandLine.appendSwitch('disable-renderer-backgrounding');
// sure we can reproduce it in renderer process. // sure we can reproduce it in renderer process.
process.stdout; process.stdout;
ipc.on('message', function(event, arg) { ipcMain.on('message', function(event, arg) {
event.sender.send('message', arg); event.sender.send('message', arg);
}); });
ipc.on('console.log', function(event, args) { ipcMain.on('console.log', function(event, args) {
console.error.apply(console, args); console.error.apply(console, args);
}); });
ipc.on('console.error', function(event, args) { ipcMain.on('console.error', function(event, args) {
console.error.apply(console, args); console.error.apply(console, args);
}); });
ipc.on('process.exit', function(event, code) { ipcMain.on('process.exit', function(event, code) {
process.exit(code); process.exit(code);
}); });
ipc.on('eval', function(event, script) { ipcMain.on('eval', function(event, script) {
event.returnValue = eval(script); event.returnValue = eval(script);
}); });
ipc.on('echo', function(event, msg) { ipcMain.on('echo', function(event, msg) {
event.returnValue = msg; event.returnValue = msg;
}); });
@ -54,7 +56,7 @@ app.on('window-all-closed', function() {
app.on('ready', function() { app.on('ready', function() {
// Test if using protocol module would crash. // Test if using protocol module would crash.
require('protocol').registerStringProtocol('test-if-crashes', function() {}); electron.protocol.registerStringProtocol('test-if-crashes', function() {});
window = new BrowserWindow({ window = new BrowserWindow({
title: 'Electron Tests', title: 'Electron Tests',
@ -79,7 +81,7 @@ app.on('ready', function() {
// For session's download test, listen 'will-download' event in browser, and // For session's download test, listen 'will-download' event in browser, and
// reply the result to renderer for verifying // reply the result to renderer for verifying
var downloadFilePath = path.join(__dirname, '..', 'fixtures', 'mock.pdf'); var downloadFilePath = path.join(__dirname, '..', 'fixtures', 'mock.pdf');
ipc.on('set-download-option', function(event, need_cancel) { ipcMain.on('set-download-option', function(event, need_cancel) {
window.webContents.session.once('will-download', window.webContents.session.once('will-download',
function(e, item, webContents) { function(e, item, webContents) {
item.setSavePath(downloadFilePath); item.setSavePath(downloadFilePath);