From dba2a77e1fb0f4ee5d2893a07324ccf73d0b78f7 Mon Sep 17 00:00:00 2001 From: Nathan Sobo Date: Wed, 30 Sep 2015 11:33:40 -0600 Subject: [PATCH] Assign env vars in initialize-application-window Also, add a get-window-load-settings helper. --- src/atom.coffee | 19 ++----------------- src/get-window-load-settings.coffee | 16 ++++++++++++++++ src/initialize-application-window.coffee | 13 +++++++++++++ 3 files changed, 31 insertions(+), 17 deletions(-) create mode 100644 src/get-window-load-settings.coffee diff --git a/src/atom.coffee b/src/atom.coffee index 720f2c455..4c0807dc4 100644 --- a/src/atom.coffee +++ b/src/atom.coffee @@ -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) diff --git a/src/get-window-load-settings.coffee b/src/get-window-load-settings.coffee new file mode 100644 index 000000000..7f41ad05f --- /dev/null +++ b/src/get-window-load-settings.coffee @@ -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 diff --git a/src/initialize-application-window.coffee b/src/initialize-application-window.coffee index 886ba26dc..69c7e6582 100644 --- a/src/initialize-application-window.coffee +++ b/src/initialize-application-window.coffee @@ -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')