Assign env vars in initialize-application-window

Also, add a get-window-load-settings helper.
This commit is contained in:
Nathan Sobo
2015-09-30 11:33:40 -06:00
parent 7d014581cf
commit dba2a77e1f
3 changed files with 31 additions and 17 deletions

View File

@@ -14,6 +14,7 @@ Model = require './model'
WindowEventHandler = require './window-event-handler'
StylesElement = require './styles-element'
StorageFolder = require './storage-folder'
getWindowLoadSettings = require './get-window-load-settings'
# Essential: Atom global for dealing with packages, themes, menus, and the window.
#
@@ -72,15 +73,7 @@ class Atom extends Model
@storageFolder ?= new StorageFolder(@getConfigDirPath())
# Returns the load settings hash associated with the current window.
@getLoadSettings: ->
@loadSettings ?= JSON.parse(decodeURIComponent(location.hash.substr(1)))
cloned = _.deepClone(@loadSettings)
# The loadSettings.windowState could be large, request it only when needed.
cloned.__defineGetter__ 'windowState', =>
@getCurrentWindow().loadSettings.windowState
cloned.__defineSetter__ 'windowState', (value) =>
@getCurrentWindow().loadSettings.windowState = value
cloned
@getLoadSettings: -> getWindowLoadSettings()
@updateLoadSetting: (key, value) ->
@getLoadSettings()
@@ -261,14 +254,6 @@ class Atom extends Model
{devMode, safeMode, resourcePath} = @getLoadSettings()
configDirPath = @getConfigDirPath()
# Add 'exports' to module search path.
exportsPath = path.join(resourcePath, 'exports')
require('module').globalPaths.push(exportsPath)
# Still set NODE_PATH since tasks may need it.
process.env.NODE_PATH = exportsPath
# Make react.js faster
process.env.NODE_ENV ?= 'production' unless devMode
document.head.appendChild(new StylesElement)

View File

@@ -0,0 +1,16 @@
remote = require 'remote'
_ = require 'underscore-plus'
windowLoadSettings = null
module.exports = ->
windowLoadSettings ?= JSON.parse(window.decodeURIComponent(window.location.hash.substr(1)))
clone = _.deepClone(windowLoadSettings)
# The windowLoadSettings.windowState could be large, request it only when needed.
clone.__defineGetter__ 'windowState', =>
remote.getCurrentWindow().loadSettings.windowState
clone.__defineSetter__ 'windowState', (value) =>
remote.getCurrentWindow().loadSettings.windowState = value
clone

View File

@@ -1,5 +1,18 @@
# Like sands through the hourglass, so are the days of our lives.
path = require 'path'
require './window'
getWindowLoadSettings = require './get-window-load-settings'
{devMode, resourcePath} = getWindowLoadSettings()
# Add application-specific exports to module search path.
exportsPath = path.join(resourcePath, 'exports')
require('module').globalPaths.push(exportsPath)
process.env.NODE_PATH = exportsPath
# Make React faster
process.env.NODE_ENV ?= 'production' unless devMode
Atom = require './atom'
window.atom = Atom.loadOrCreate('editor')