From b25d3e944bfacbfbeb28879e060b4bfae2d0b15a Mon Sep 17 00:00:00 2001 From: Antonio Scandurra Date: Wed, 14 Oct 2015 12:41:00 +0200 Subject: [PATCH] Parameterize configDirPath and move config.load in ctor --- spec/jasmine-test-runner.coffee | 1 - spec/spec-helper.coffee | 6 +----- src/atom-environment.coffee | 22 +++++++++++++--------- src/config.coffee | 15 ++++++++++++--- src/initialize-application-window.coffee | 2 +- src/package-manager.coffee | 2 +- src/storage-folder.coffee | 6 +++++- src/style-manager.coffee | 2 ++ 8 files changed, 35 insertions(+), 21 deletions(-) diff --git a/spec/jasmine-test-runner.coffee b/spec/jasmine-test-runner.coffee index 5f365b16b..04b875ac8 100644 --- a/spec/jasmine-test-runner.coffee +++ b/spec/jasmine-test-runner.coffee @@ -37,7 +37,6 @@ module.exports = ({logFile, headless, testPaths, buildAtomEnvironment}) -> jasmineContent = document.createElement('div') jasmineContent.setAttribute('id', 'jasmine-content') - document.head.appendChild(atom.styles.buildStylesElement()) document.body.appendChild(jasmineContent) jasmineEnv.execute() diff --git a/spec/spec-helper.coffee b/spec/spec-helper.coffee index 7ed77bc2a..9ec8e6460 100644 --- a/spec/spec-helper.coffee +++ b/spec/spec-helper.coffee @@ -20,10 +20,6 @@ jasmineStyle = document.createElement('style') jasmineStyle.textContent = atom.themes.loadStylesheet(atom.themes.resolveStylesheet('../static/jasmine')) document.head.appendChild(jasmineStyle) -atom.themes.loadBaseStylesheets() -initialStyleElements = atom.styles.getSnapshot() -atom.themes.initialLoadComplete = true - fixturePackagesPath = path.resolve(__dirname, './fixtures/packages') atom.packages.packageDirPaths.unshift(fixturePackagesPath) @@ -107,7 +103,7 @@ beforeEach -> addCustomMatchers(this) afterEach -> - atom.reset(stylesSnapshot: initialStyleElements) + atom.reset() document.getElementById('jasmine-content').innerHTML = '' unless window.debugContent diff --git a/src/atom-environment.coffee b/src/atom-environment.coffee index 866c71945..05e99509c 100644 --- a/src/atom-environment.coffee +++ b/src/atom-environment.coffee @@ -105,8 +105,7 @@ class AtomEnvironment extends Model @state = {version: @constructor.version} @loadTime = null - {devMode, safeMode, resourcePath} = @getLoadSettings() - configDirPath = @getConfigDirPath() + {devMode, safeMode, resourcePath, configDirPath} = @getLoadSettings() @emitter = new Emitter @disposables = new CompositeDisposable @@ -179,6 +178,16 @@ class AtomEnvironment extends Model }) @themes.workspace = @workspace + @config.load() + + @themes.loadBaseStylesheets() + @initialStyleElements = @styles.getSnapshot() + @themes.initialLoadComplete = true + @setBodyPlatformClass() + + @stylesElement = @styles.buildStylesElement() + @document.head.appendChild(@stylesElement) + @keymaps.subscribeToFileReadFailure() @keymaps.loadBundledKeymaps() @@ -260,7 +269,7 @@ class AtomEnvironment extends Model @grammars.clear() - @styles.restoreSnapshot(params?.stylesSnapshot ? []) + @styles.restoreSnapshot(@initialStyleElements) @menu.clear() @@ -295,6 +304,7 @@ class AtomEnvironment extends Model @project?.destroy() @project = null @commands.clear() + @stylesElement.remove() @uninstallWindowEventHandler() @@ -598,12 +608,6 @@ class AtomEnvironment extends Model @disposables.add(@applicationDelegate.onContextMenuCommand(@dispatchContextMenuCommand.bind(this))) @listenForUpdates() - @config.load() - @themes.loadBaseStylesheets() - @setBodyPlatformClass() - - @document.head.appendChild(@styles.buildStylesElement()) - @packages.loadPackages() @document.body.appendChild(@views.getView(@workspace)) diff --git a/src/config.coffee b/src/config.coffee index bdeabba00..2faf35f22 100644 --- a/src/config.coffee +++ b/src/config.coffee @@ -332,8 +332,9 @@ class Config # Created during initialization, available as `atom.config` constructor: ({@configDirPath, @resourcePath, @notificationManager}={}) -> - @configFilePath = fs.resolve(@configDirPath, 'config', ['json', 'cson']) - @configFilePath ?= path.join(@configDirPath, 'config.cson') + if @configDirPath? + @configFilePath = fs.resolve(@configDirPath, 'config', ['json', 'cson']) + @configFilePath ?= path.join(@configDirPath, 'config.cson') @clear() clear: -> @@ -356,6 +357,8 @@ class Config @save() debouncedSave = _.debounce(save, 100) + shouldNotAccessFileSystem: -> not @configDirPath? + ### Section: Config Subscription ### @@ -726,7 +729,7 @@ class Config ### initializeConfigDirectory: (done) -> - return if fs.existsSync(@configDirPath) + return if fs.existsSync(@configDirPath) or @shouldNotAccessFileSystem() fs.makeTreeSync(@configDirPath) @@ -742,6 +745,8 @@ class Config fs.traverseTree(templateConfigDirPath, onConfigDirFile, (path) -> true) loadUserConfig: -> + return if @shouldNotAccessFileSystem() + unless fs.existsSync(@configFilePath) fs.makeTreeSync(path.dirname(@configFilePath)) CSON.writeFileSync(@configFilePath, {}) @@ -765,6 +770,8 @@ class Config @notifyFailure(message, detail) observeUserConfig: -> + return if @shouldNotAccessFileSystem() + try @watchSubscription ?= pathWatcher.watch @configFilePath, (eventType) => @requestLoad() if eventType is 'change' and @watchSubscription? @@ -784,6 +791,8 @@ class Config @notificationManager.addError(errorMessage, {detail, dismissable: true}) save: -> + return if @shouldNotAccessFileSystem() + allSettings = {'*': @settings} allSettings = _.extend allSettings, @scopedSettingsStore.propertiesForSource(@getUserConfigPath()) try diff --git a/src/initialize-application-window.coffee b/src/initialize-application-window.coffee index 44bec588e..71b1f3b15 100644 --- a/src/initialize-application-window.coffee +++ b/src/initialize-application-window.coffee @@ -16,7 +16,7 @@ process.env.NODE_ENV ?= 'production' unless devMode AtomEnvironment = require './atom-environment' ApplicationDelegate = require './application-delegate' -window.atom = new AtomEnvironment({applicationDelegate: new ApplicationDelegate, window, document}) +window.atom = new AtomEnvironment({applicationDelegate: new ApplicationDelegate, window, document, configDirPath: process.env.ATOM_HOME}) atom.displayWindow() atom.loadStateSync() diff --git a/src/package-manager.coffee b/src/package-manager.coffee index aeabf62a3..f6cef9465 100644 --- a/src/package-manager.coffee +++ b/src/package-manager.coffee @@ -37,7 +37,7 @@ class PackageManager @emitter = new Emitter @activationHookEmitter = new Emitter @packageDirPaths = [] - unless safeMode + if configDirPath? and not safeMode if @devMode @packageDirPaths.push(path.join(configDirPath, "dev", "packages")) @packageDirPaths.push(path.join(configDirPath, "packages")) diff --git a/src/storage-folder.coffee b/src/storage-folder.coffee index bf969dee2..da8af3f2e 100644 --- a/src/storage-folder.coffee +++ b/src/storage-folder.coffee @@ -4,12 +4,16 @@ fs = require "fs-plus" module.exports = class StorageFolder constructor: (containingPath) -> - @path = path.join(containingPath, "storage") + @path = path.join(containingPath, "storage") if containingPath? store: (name, object) -> + return unless @path? + fs.writeFileSync(@pathForKey(name), JSON.stringify(object), 'utf8') load: (name) -> + return unless @path? + statePath = @pathForKey(name) try stateString = fs.readFileSync(statePath, 'utf8') diff --git a/src/style-manager.coffee b/src/style-manager.coffee index 8b3349b7a..8f932d229 100644 --- a/src/style-manager.coffee +++ b/src/style-manager.coffee @@ -168,6 +168,8 @@ class StyleManager # # Returns a {String}. getUserStyleSheetPath: -> + return "" unless @configDirPath? + stylesheetPath = fs.resolve(path.join(@configDirPath, 'styles'), ['css', 'less']) if fs.isFileSync(stylesheetPath) stylesheetPath