Allow spec window to store window state

It just stores window dimensions for now.
This commit is contained in:
probablycorey
2013-05-22 11:56:33 -07:00
parent 6abe6e7539
commit 0901e1a34c
2 changed files with 8 additions and 7 deletions

View File

@@ -218,20 +218,21 @@ window.atom =
rootView?.open(path)
getWindowStatePath: ->
shasum = crypto.createHash('sha1')
shasum.update(@getPathToOpen())
fsUtils.join(config.userStoragePath, shasum.digest('hex'))
if not @getPathToOpen()
'probably-a-spec-window'
else
shasum = crypto.createHash('sha1')
shasum.update(@getPathToOpen())
fsUtils.join(config.userStoragePath, shasum.digest('hex'))
setWindowState: (keyPath, value) ->
return {} if not @getPathToOpen()
windowState = @getWindowState()
_.setValueForKeyPath(windowState, keyPath, value)
fsUtils.write(@getWindowStatePath(), JSON.stringify(windowState))
windowState
getWindowState: (keyPath) ->
return {} if not @getPathToOpen() or not fsUtils.exists(@getWindowStatePath())
return {} unless fsUtils.exists(@getWindowStatePath())
windowState = JSON.parse(fsUtils.read(@getWindowStatePath()) or '{}')
if keyPath

View File

@@ -40,6 +40,7 @@ window.setUpEnvironment = ->
dimensions = defaultWindowDimensions unless dimensions.width and dimensions.height
window.setDimensions(dimensions)
remote.getCurrentWindow().show()
$(window).on 'unload', -> atom.setWindowState('dimensions', window.getDimensions())
# This method is only called when opening a real application window
window.startEditorWindow = ->
@@ -78,7 +79,6 @@ window.unloadEditorWindow = ->
atom.setWindowState('project', project.serialize())
atom.setWindowState('syntax', syntax.serialize())
atom.setWindowState('rootView', rootView.serialize())
atom.setWindowState('dimensions', window.getDimensions())
atom.deactivatePackages()
atom.setWindowState('packageStates', atom.packageStates)
rootView.remove()