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

View file

@ -1,7 +1,5 @@
EventEmitter = require('events').EventEmitter
app = require 'app'
ipc = require 'ipc-main'
deprecate = require 'deprecate'
{app, ipcMain, deprecate} = require 'electron'
{EventEmitter} = require 'events'
BrowserWindow = process.atomBinding('window').BrowserWindow
BrowserWindow::__proto__ = EventEmitter.prototype
@ -15,7 +13,7 @@ BrowserWindow::_init = ->
# Make new windows requested by links behave like "window.open"
@webContents.on '-new-window', (event, url, frameName) ->
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.moveTo(...)

View file

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

View file

@ -45,3 +45,8 @@ Object.defineProperties module.exports,
tray:
enumerable: true
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 = bindings.globalShortcut
{globalShortcut} = process.atomBinding 'global_shortcut'
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.
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'
nextCommandId = 0
@ -18,7 +17,7 @@ class MenuItem
@types = ['normal', 'separator', 'submenu', 'checkbox', 'radio']
constructor: (options) ->
Menu = require 'menu'
{Menu} = require 'electron'
{click, @selector, @type, @role, @label, @sublabel, @accelerator, @icon, @enabled, @visible, @checked, @submenu} = options

View file

@ -1,8 +1,7 @@
BrowserWindow = require 'browser-window'
EventEmitter = require('events').EventEmitter
MenuItem = require 'menu-item'
v8Util = process.atomBinding 'v8_util'
{BrowserWindow, MenuItem} = require 'electron'
{EventEmitter} = require 'events'
v8Util = process.atomBinding 'v8_util'
bindings = process.atomBinding 'menu'
# 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.
ipc.on 'ATOM_SHELL_NAVIGATION_CONTROLLER', (event, method, args...) ->
ipcMain.on 'ATOM_SHELL_NAVIGATION_CONTROLLER', (event, 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...
# JavaScript implementation of Chromium's NavigationController.

View file

@ -1,5 +1,6 @@
powerMonitor = process.atomBinding('power_monitor').powerMonitor
EventEmitter = require('events').EventEmitter
{EventEmitter} = require 'events'
{powerMonitor} = process.atomBinding 'power_monitor'
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()
protocol = process.atomBinding('protocol').protocol
{protocol} = process.atomBinding 'protocol'
# Warn about removed APIs.
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
module.exports = screen

View file

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

View file

@ -1,8 +1,7 @@
EventEmitter = require('events').EventEmitter
Menu = require './menu'
NavigationController = require './navigation-controller'
{EventEmitter} = require 'events'
{ipcMain, NavigationController, Menu} = require 'electron'
binding = process.atomBinding 'web_contents'
ipc = require 'ipc-main'
nextId = 0
getNextId = -> ++nextId
@ -60,11 +59,11 @@ wrapWebContents = (webContents) ->
# Dispatch IPC messages to the ipc module.
webContents.on 'ipc-message', (event, packed) ->
[channel, args...] = packed
ipc.emit channel, event, args...
ipcMain.emit channel, event, args...
webContents.on 'ipc-message-sync', (event, packed) ->
[channel, args...] = packed
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.
webContents.on 'pepper-context-menu', (event, params) ->