diff --git a/CHANGELOG.md b/CHANGELOG.md index 270f30cff..16da93e55 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,4 @@ +* Fixed: Atom can now be launched when ~/.atom/config.cson doesn't exist * Added: Initial collaboration sessions * Fixed: Empty lines being deleted via uppercase/downcase command * Fixed: Keybindings not working when using non-English keyboard language diff --git a/spec/app/config-spec.coffee b/spec/app/config-spec.coffee index 0e47a6fc3..cf0726384 100644 --- a/spec/app/config-spec.coffee +++ b/spec/app/config-spec.coffee @@ -1,6 +1,7 @@ fs = require 'fs' fsUtils = require 'fs-utils' path = require 'path' +CSON = require 'season' describe "Config", -> describe ".get(keyPath)", -> @@ -210,6 +211,13 @@ describe "Config", -> config.set("hair", "blonde") # trigger a save expect(config.save).not.toHaveBeenCalled() + describe "when the config file does not exist", -> + it "creates it with an empty object", -> + fsUtils.makeTree(config.configDirPath) + config.loadUserConfig() + expect(fsUtils.exists(config.configFilePath)).toBe true + expect(CSON.readFileSync(config.configFilePath)).toEqual {} + describe ".observeUserConfig()", -> updatedHandler = null diff --git a/src/app/config.coffee b/src/app/config.coffee index 9def00a53..2b0f9dc37 100644 --- a/src/app/config.coffee +++ b/src/app/config.coffee @@ -66,16 +66,19 @@ class Config @observeUserConfig() loadUserConfig: -> - if fsUtils.exists(@configFilePath) - try - userConfig = CSON.readFileSync(@configFilePath) - _.extend(@settings, userConfig) - @configFileHasErrors = false - @trigger 'updated' - catch e - @configFileHasErrors = true - console.error "Failed to load user config '#{@configFilePath}'", e.message - console.error e.stack + if !fsUtils.exists(@configFilePath) + fsUtils.makeTree(path.dirname(@configFilePath)) + CSON.writeFileSync(@configFilePath, {}) + + try + userConfig = CSON.readFileSync(@configFilePath) + _.extend(@settings, userConfig) + @configFileHasErrors = false + @trigger 'updated' + catch e + @configFileHasErrors = true + console.error "Failed to load user config '#{@configFilePath}'", e.message + console.error e.stack observeUserConfig: -> @watchSubscription ?= pathWatcher.watch @configFilePath, (eventType) =>