Avoid using app API in renderer process for #907

This commit is contained in:
Cheng Zhao 2015-01-04 22:45:51 -08:00
parent 3063b5189a
commit 895ccf69a7
2 changed files with 19 additions and 28 deletions

View file

@ -1,6 +1,17 @@
binding = process.atomBinding 'screen'
checkAppIsReady = ->
unless process.type is 'renderer' or require('app').isReady()
throw new Error('Can not use screen module before the "ready" event of app module gets emitted')
module.exports =
if process.platform in ['linux', 'win32'] and process.type is 'renderer'
# On Linux we could not access screen in renderer process.
require('remote').require 'screen'
else
process.atomBinding 'screen'
getCursorScreenPoint: ->
checkAppIsReady()
binding.getCursorScreenPoint()
getPrimaryDisplay: ->
checkAppIsReady()
binding.getPrimaryDisplay()