Also use uv loop fixes in browser process.
This commit is contained in:
parent
290dd36bb0
commit
b0c23294fe
4 changed files with 36 additions and 28 deletions
1
atom.gyp
1
atom.gyp
|
@ -30,6 +30,7 @@
|
|||
'common/api/lib/id-weak-map.coffee',
|
||||
'common/api/lib/screen.coffee',
|
||||
'common/api/lib/shell.coffee',
|
||||
'common/lib/init.coffee',
|
||||
'renderer/lib/init.coffee',
|
||||
'renderer/api/lib/ipc.coffee',
|
||||
'renderer/api/lib/remote.coffee',
|
||||
|
|
|
@ -14,12 +14,12 @@ process.argv.splice 1, 1
|
|||
globalPaths = require('module').globalPaths
|
||||
globalPaths.push path.join process.resourcesPath, 'browser', 'api', 'lib'
|
||||
|
||||
# And also common/api/lib
|
||||
globalPaths.push path.join process.resourcesPath, 'common', 'api', 'lib'
|
||||
|
||||
# Do loading in next tick since we still need some initialize work before
|
||||
# native bindings can work.
|
||||
setImmediate ->
|
||||
# Import common settings.
|
||||
require path.resolve(__dirname, '..', '..', 'common', 'lib', 'init.js')
|
||||
|
||||
if process.platform is 'win32'
|
||||
# Redirect node's console to use our own implementations, since node can not
|
||||
# handle console output when running as GUI program.
|
||||
|
|
28
common/lib/init.coffee
Normal file
28
common/lib/init.coffee
Normal file
|
@ -0,0 +1,28 @@
|
|||
path = require 'path'
|
||||
timers = require 'timers'
|
||||
Module = require 'module'
|
||||
|
||||
# Add common/api/lib to module search paths.
|
||||
globalPaths = Module.globalPaths
|
||||
globalPaths.push path.join(process.resourcesPath, 'common', 'api', 'lib')
|
||||
|
||||
# setImmediate and process.nextTick makes use of uv_check and uv_prepare to
|
||||
# run the callbacks, however since we only run uv loop on requests, the
|
||||
# callbacks wouldn't be called until something else activated the uv loop,
|
||||
# which would delay the callbacks for arbitrary long time. So we should
|
||||
# initiatively activate the uv loop once setImmediate and process.nextTick is
|
||||
# called.
|
||||
wrapWithActivateUvLoop = (func) ->
|
||||
->
|
||||
process.activateUvLoop()
|
||||
func.apply this, arguments
|
||||
process.nextTick = wrapWithActivateUvLoop process.nextTick
|
||||
global.setImmediate = wrapWithActivateUvLoop timers.setImmediate
|
||||
global.clearImmediate = timers.clearImmediate
|
||||
|
||||
# The child_process module also needs to activate the uv loop to make the ipc
|
||||
# channel setup.
|
||||
# TODO(zcbenz): Find out why this is needed.
|
||||
childProcess = require 'child_process'
|
||||
childProcess.spawn = wrapWithActivateUvLoop childProcess.spawn
|
||||
childProcess.fork = wrapWithActivateUvLoop childProcess.fork
|
|
@ -1,5 +1,4 @@
|
|||
path = require 'path'
|
||||
timers = require 'timers'
|
||||
Module = require 'module'
|
||||
|
||||
# Expose information of current process.
|
||||
|
@ -14,36 +13,16 @@ process.argv.splice 1, 1
|
|||
# of Atom's built-in libraries.
|
||||
globalPaths = Module.globalPaths
|
||||
globalPaths.push path.join(process.resourcesPath, 'renderer', 'api', 'lib')
|
||||
# And also common/api/lib.
|
||||
globalPaths.push path.join(process.resourcesPath, 'common', 'api', 'lib')
|
||||
# And also app.
|
||||
globalPaths.push path.join(process.resourcesPath, 'app')
|
||||
|
||||
# Import common settings.
|
||||
require path.resolve(__dirname, '..', '..', 'common', 'lib', 'init.js')
|
||||
|
||||
# Expose global variables.
|
||||
global.require = require
|
||||
global.module = module
|
||||
|
||||
# setImmediate and process.nextTick makes use of uv_check and uv_prepare to
|
||||
# run the callbacks, however since we only run uv loop on requests, the
|
||||
# callbacks wouldn't be called until something else activated the uv loop,
|
||||
# which would delay the callbacks for arbitrary long time. So we should
|
||||
# initiatively activate the uv loop once setImmediate and process.nextTick is
|
||||
# called.
|
||||
wrapWithActivateUvLoop = (func) ->
|
||||
->
|
||||
process.activateUvLoop()
|
||||
func.apply this, arguments
|
||||
process.nextTick = wrapWithActivateUvLoop process.nextTick
|
||||
global.setImmediate = wrapWithActivateUvLoop timers.setImmediate
|
||||
global.clearImmediate = timers.clearImmediate
|
||||
|
||||
# The child_process module also needs to activate the uv loop to make the ipc
|
||||
# channel setup.
|
||||
# TODO(zcbenz): Find out why this is needed.
|
||||
childProcess = require 'child_process'
|
||||
childProcess.spawn = wrapWithActivateUvLoop childProcess.spawn
|
||||
childProcess.fork = wrapWithActivateUvLoop childProcess.fork
|
||||
|
||||
# Set the __filename to the path of html file if it's file:// protocol.
|
||||
if window.location.protocol is 'file:'
|
||||
global.__filename =
|
||||
|
|
Loading…
Add table
Reference in a new issue