From 751af25f374c0c144b3f56fb301170fc5b0829b8 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Tue, 10 Nov 2015 16:04:34 +0800 Subject: [PATCH] Use ipcMain in Electron's code --- atom/browser/api/lib/browser-window.coffee | 2 +- atom/browser/api/lib/navigation-controller.coffee | 2 +- atom/browser/api/lib/web-contents.coffee | 2 +- atom/browser/lib/guest-view-manager.coffee | 2 +- atom/browser/lib/guest-window-manager.coffee | 2 +- atom/browser/lib/rpc-server.coffee | 2 +- spec/api-browser-window-spec.coffee | 6 +++--- spec/api-ipc-spec.coffee | 2 +- spec/api-session-spec.coffee | 6 +++--- spec/asar-spec.coffee | 2 +- spec/static/main.js | 4 ++-- 11 files changed, 16 insertions(+), 16 deletions(-) diff --git a/atom/browser/api/lib/browser-window.coffee b/atom/browser/api/lib/browser-window.coffee index d8ac221c62e..5bb63320884 100644 --- a/atom/browser/api/lib/browser-window.coffee +++ b/atom/browser/api/lib/browser-window.coffee @@ -1,6 +1,6 @@ EventEmitter = require('events').EventEmitter app = require 'app' -ipc = require 'ipc' +ipc = require 'ipc-main' deprecate = require 'deprecate' BrowserWindow = process.atomBinding('window').BrowserWindow diff --git a/atom/browser/api/lib/navigation-controller.coffee b/atom/browser/api/lib/navigation-controller.coffee index f78d92c341d..34911dd759e 100644 --- a/atom/browser/api/lib/navigation-controller.coffee +++ b/atom/browser/api/lib/navigation-controller.coffee @@ -1,4 +1,4 @@ -ipc = require 'ipc' +ipc = require 'ipc-main' # The history operation in renderer is redirected to browser. ipc.on 'ATOM_SHELL_NAVIGATION_CONTROLLER', (event, method, args...) -> diff --git a/atom/browser/api/lib/web-contents.coffee b/atom/browser/api/lib/web-contents.coffee index 331a561189d..958c3f8270c 100644 --- a/atom/browser/api/lib/web-contents.coffee +++ b/atom/browser/api/lib/web-contents.coffee @@ -2,7 +2,7 @@ EventEmitter = require('events').EventEmitter Menu = require './menu' NavigationController = require './navigation-controller' binding = process.atomBinding 'web_contents' -ipc = require 'ipc' +ipc = require 'ipc-main' nextId = 0 getNextId = -> ++nextId diff --git a/atom/browser/lib/guest-view-manager.coffee b/atom/browser/lib/guest-view-manager.coffee index 455e969812f..c99b681498e 100644 --- a/atom/browser/lib/guest-view-manager.coffee +++ b/atom/browser/lib/guest-view-manager.coffee @@ -1,4 +1,4 @@ -ipc = require 'ipc' +ipc = require 'ipc-main' webContents = require 'web-contents' webViewManager = null # Doesn't exist in early initialization. diff --git a/atom/browser/lib/guest-window-manager.coffee b/atom/browser/lib/guest-window-manager.coffee index 5de3ad3b042..fe01c6fa771 100644 --- a/atom/browser/lib/guest-window-manager.coffee +++ b/atom/browser/lib/guest-window-manager.coffee @@ -1,4 +1,4 @@ -ipc = require 'ipc' +ipc = require 'ipc-main' v8Util = process.atomBinding 'v8_util' BrowserWindow = require 'browser-window' diff --git a/atom/browser/lib/rpc-server.coffee b/atom/browser/lib/rpc-server.coffee index ae4b161674b..c6a646edcd9 100644 --- a/atom/browser/lib/rpc-server.coffee +++ b/atom/browser/lib/rpc-server.coffee @@ -1,4 +1,4 @@ -ipc = require 'ipc' +ipc = require 'ipc-main' path = require 'path' objectsRegistry = require './objects-registry.js' v8Util = process.atomBinding 'v8_util' diff --git a/spec/api-browser-window-spec.coffee b/spec/api-browser-window-spec.coffee index 1218d27b7fd..460a1c1ec17 100644 --- a/spec/api-browser-window-spec.coffee +++ b/spec/api-browser-window-spec.coffee @@ -201,12 +201,12 @@ describe 'browser-window module', -> describe '"web-preferences" option', -> afterEach -> - remote.require('ipc').removeAllListeners('answer') + remote.require('ipc-main').removeAllListeners('answer') describe '"preload" option', -> it 'loads the script before other scripts in window', (done) -> preload = path.join fixtures, 'module', 'set-global.js' - remote.require('ipc').once 'answer', (event, test) -> + remote.require('ipc-main').once 'answer', (event, test) -> assert.equal(test, 'preload') done() w.destroy() @@ -219,7 +219,7 @@ describe 'browser-window module', -> describe '"node-integration" option', -> it 'disables node integration when specified to false', (done) -> preload = path.join fixtures, 'module', 'send-later.js' - remote.require('ipc').once 'answer', (event, test) -> + remote.require('ipc-main').once 'answer', (event, test) -> assert.equal(test, 'undefined') done() w.destroy() diff --git a/spec/api-ipc-spec.coffee b/spec/api-ipc-spec.coffee index e5028c602b1..d8918338c96 100644 --- a/spec/api-ipc-spec.coffee +++ b/spec/api-ipc-spec.coffee @@ -83,7 +83,7 @@ describe 'ipc module', -> it 'does not crash when reply is not sent and browser is destroyed', (done) -> @timeout 10000 w = new BrowserWindow(show: false) - remote.require('ipc').once 'send-sync-message', (event) -> + remote.require('ipc-main').once 'send-sync-message', (event) -> event.returnValue = null w.destroy() done() diff --git a/spec/api-session-spec.coffee b/spec/api-session-spec.coffee index 8baca1557cc..028768f61d3 100644 --- a/spec/api-session-spec.coffee +++ b/spec/api-session-spec.coffee @@ -60,9 +60,9 @@ describe 'session module', -> describe 'session.clearStorageData(options)', -> fixtures = path.resolve __dirname, 'fixtures' it 'clears localstorage data', (done) -> - ipc = remote.require('ipc') - ipc.on 'count', (event, count) -> - ipc.removeAllListeners 'count' + ipcMain = remote.require('ipc-main') + ipcMain.on 'count', (event, count) -> + ipcMain.removeAllListeners 'count' assert not count done() w.loadUrl 'file://' + path.join(fixtures, 'api', 'localstorage.html') diff --git a/spec/asar-spec.coffee b/spec/asar-spec.coffee index 75f0cec63ad..3e3890d529f 100644 --- a/spec/asar-spec.coffee +++ b/spec/asar-spec.coffee @@ -407,7 +407,7 @@ describe 'asar package', -> describe 'asar protocol', -> url = require 'url' remote = require 'remote' - ipc = remote.require 'ipc' + ipc = remote.require 'ipc-main' BrowserWindow = remote.require 'browser-window' it 'can request a file in package', (done) -> diff --git a/spec/static/main.js b/spec/static/main.js index 5b10bb6d43d..702c88ecdd9 100644 --- a/spec/static/main.js +++ b/spec/static/main.js @@ -1,5 +1,5 @@ var app = require('app'); -var ipc = require('ipc'); +var ipc = require('ipc-main'); var dialog = require('dialog'); var path = require('path'); var BrowserWindow = require('browser-window'); @@ -78,7 +78,7 @@ app.on('ready', function() { // For session's download test, listen 'will-download' event in browser, and // reply the result to renderer for verifying var downloadFilePath = path.join(__dirname, '..', 'fixtures', 'mock.pdf'); - require('ipc').on('set-download-option', function(event, need_cancel) { + ipc.on('set-download-option', function(event, need_cancel) { window.webContents.session.once('will-download', function(e, item, webContents) { item.setSavePath(downloadFilePath);