Assign config in Atom environment constructor

This commit is contained in:
Nathan Sobo
2015-09-28 13:21:50 -06:00
parent 43c959fdeb
commit 88d80b1c97
3 changed files with 27 additions and 20 deletions

View File

@@ -10,7 +10,6 @@ fs = require 'fs-plus'
Grim = require 'grim'
KeymapManager = require '../src/keymap-extensions'
Config = require '../src/config'
{Point} = require 'text-buffer'
Project = require '../src/project'
Workspace = require '../src/workspace'
@@ -124,22 +123,20 @@ beforeEach ->
spyOn(atom.menu, 'sendToBrowserProcess')
# reset config before each spec; don't load or save from/to `config.json`
spyOn(Config::, 'load')
spyOn(Config::, 'save')
config = new Config({resourcePath, configDirPath: atom.getConfigDirPath()})
atom.config = config
spyOn(atom.config, 'load')
spyOn(atom.config, 'save')
atom.loadConfig()
config.set "core.destroyEmptyPanes", false
config.set "editor.fontFamily", "Courier"
config.set "editor.fontSize", 16
config.set "editor.autoIndent", false
config.set "core.disabledPackages", ["package-that-throws-an-exception",
atom.config.set "core.destroyEmptyPanes", false
atom.config.set "editor.fontFamily", "Courier"
atom.config.set "editor.fontSize", 16
atom.config.set "editor.autoIndent", false
atom.config.set "core.disabledPackages", ["package-that-throws-an-exception",
"package-with-broken-package-json", "package-with-broken-keymap"]
config.set "editor.useShadowDOM", true
atom.config.set "editor.useShadowDOM", true
advanceClock(1000)
window.setTimeout.reset()
config.load.reset()
config.save.reset()
atom.config.load.reset()
atom.config.save.reset()
# make editor display updates synchronous
TextEditorElement::setUpdatedSynchronously(true)
@@ -159,6 +156,8 @@ beforeEach ->
addCustomMatchers(this)
afterEach ->
atom.reset()
atom.packages.deactivatePackages()
atom.menu.template = []
atom.contextMenu.clear()

View File

@@ -152,6 +152,8 @@ class Atom extends Model
# Call .loadOrCreate instead
constructor: (@state) ->
{@mode} = @state
{resourcePath} = @getLoadSettings()
configDirPath = @getConfigDirPath()
@emitter = new Emitter
@disposables = new CompositeDisposable
@@ -163,6 +165,12 @@ class Atom extends Model
NotificationManager = require './notification-manager'
@notifications = new NotificationManager
Config = require './config'
@config = new Config({configDirPath, resourcePath, notificationManager: @notifications})
reset: ->
@config.reset()
# Sets up the basic services that should be available in all modes
# (both spec and application).
#
@@ -196,7 +204,6 @@ class Atom extends Model
@loadTime = null
Config = require './config'
KeymapManager = require './keymap-extensions'
ViewRegistry = require './view-registry'
CommandRegistry = require './command-registry'
@@ -220,7 +227,6 @@ class Atom extends Model
# Make react.js faster
process.env.NODE_ENV ?= 'production' unless devMode
@config = new Config({configDirPath, resourcePath})
@keymaps = new KeymapManager({configDirPath, resourcePath})
@keymaps.subscribeToFileReadFailure()
@tooltips = new TooltipManager

View File

@@ -331,7 +331,12 @@ class Config
value
# Created during initialization, available as `atom.config`
constructor: ({@configDirPath, @resourcePath}={}) ->
constructor: ({@configDirPath, @resourcePath, @notificationManager}={}) ->
@configFilePath = fs.resolve(@configDirPath, 'config', ['json', 'cson'])
@configFilePath ?= path.join(@configDirPath, 'config.cson')
@reset()
reset: ->
@emitter = new Emitter
@schema =
type: 'object'
@@ -340,11 +345,8 @@ class Config
@settings = {}
@scopedSettingsStore = new ScopedPropertyStore
@configFileHasErrors = false
@configFilePath = fs.resolve(@configDirPath, 'config', ['json', 'cson'])
@configFilePath ?= path.join(@configDirPath, 'config.cson')
@transactDepth = 0
@savePending = false
@requestLoad = _.debounce(@loadUserConfig, 100)
@requestSave = =>
@savePending = true
@@ -779,7 +781,7 @@ class Config
@watchSubscription = null
notifyFailure: (errorMessage, detail) ->
atom.notifications.addError(errorMessage, {detail, dismissable: true})
@notificationManager.addError(errorMessage, {detail, dismissable: true})
save: ->
allSettings = {'*': @settings}