Store untitled window state under load settings

This keeps untitled windows from contaminating each other by
storing to the same state path on disk but still stores state
across reloads of the windows.

Closes #599
This commit is contained in:
Kevin Sawicki
2013-06-24 10:37:53 -07:00
parent aeee3c9ade
commit d31d18360b
2 changed files with 23 additions and 8 deletions

View File

@@ -235,25 +235,40 @@ window.atom =
sha1 = crypto.createHash('sha1').update(initialPath).digest('hex')
filename = "editor-#{sha1}"
filename ?= 'undefined'
path.join(config.userStoragePath, filename)
if filename
path.join(config.userStoragePath, filename)
else
null
saveWindowState: (windowState) ->
windowStateJson = JSON.stringify(windowState)
if windowStatePath = @getWindowStatePath()
fsUtils.writeSync(windowStatePath, windowStateJson)
else
@getLoadSettings().windowState = windowStateJson
setWindowState: (keyPath, value) ->
windowState = @getWindowState()
_.setValueForKeyPath(windowState, keyPath, value)
fsUtils.writeSync(@getWindowStatePath(), JSON.stringify(windowState))
@saveWindowState(windowState)
windowState
getWindowState: (keyPath) ->
windowStatePath = @getWindowStatePath()
return {} unless fsUtils.exists(windowStatePath)
if windowStatePath = @getWindowStatePath()
if fsUtils.exists(windowStatePath)
try
windowStateJson = fsUtils.read(windowStatePath)
catch error
console.warn "Error reading window state: #{windowStatePath}", error.stack, error
else
windowStateJson = @getLoadSettings().windowState
try
windowState = JSON.parse(fsUtils.read(windowStatePath) or '{}')
windowState = JSON.parse(windowStateJson or '{}')
catch error
console.warn "Error parsing window state: #{windowStatePath}", error.stack, error
windowState = {}
windowState ?= {}
if keyPath
_.valueForKeyPath(windowState, keyPath)
else

View File

@@ -20,7 +20,7 @@ class AtomWindow
try
initialPath = path.dirname(pathToOpen) if fs.statSync(pathToOpen).isFile()
@browserWindow.loadSettings = {initialPath, bootstrapScript, resourcePath, exitWhenDone}
@browserWindow.loadSettings = {initialPath, bootstrapScript, resourcePath, exitWhenDone, windowState: ''}
@browserWindow.once 'window:loaded', => @loaded = true
@browserWindow.loadUrl "file://#{resourcePath}/static/index.html"