Window state works now

The state is now stored in ~/.atom/.storage/SHA-OF-PATH. It is written
to every time it is set.
This commit is contained in:
probablycorey
2013-05-21 14:07:33 -07:00
parent 26094a5405
commit f23cb1aa79
5 changed files with 15 additions and 33 deletions

View File

@@ -38,7 +38,6 @@ beforeEach ->
window.resetTimeouts()
atom.packageStates = {}
spyOn(atom, 'saveWindowState')
spyOn(atom, 'getSavedWindowState').andReturn(null)
$native.setWindowState('')
syntax.clearGrammarOverrides()

View File

@@ -4,6 +4,7 @@ Package = require 'package'
Theme = require 'theme'
ipc = require 'ipc'
remote = require 'remote'
crypto = require 'crypto'
window.atom =
exitWhenDone: window.location.params.exitWhenDone
@@ -19,7 +20,7 @@ window.atom =
originalSendMessageToBrowserProcess: -> console.log 'this methods needs to be replaced'
getPathToOpen: ->
@getWindowState('pathToOpen') ? window.location.params.pathToOpen
window.location.params.pathToOpen ? @getWindowState('pathToOpen')
getPackageState: (name) ->
@packageStates[name]
@@ -216,38 +217,28 @@ window.atom =
path = data[0]
rootView?.open(path)
getWindowStatePath: ->
shasum = crypto.createHash('sha1')
shasum.update(@getPathToOpen())
fsUtils.join(config.userStoragePath, shasum.digest('hex'))
setWindowState: (keyPath, value) ->
return {} if @windowMode == 'config'
windowState = @getWindowState()
_.setValueForKeyPath(windowState, keyPath, value)
ipc.sendChannel('window-state', JSON.stringify(windowState))
fsUtils.write(@getWindowStatePath(), JSON.stringify(windowState))
windowState
getWindowState: (keyPath) ->
windowState = JSON.parse(@getInMemoryWindowState() ? @getSavedWindowState() ? '{}')
return {} if @windowMode == 'config' or not fsUtils.exists(@getWindowStatePath())
windowState = JSON.parse(fsUtils.read(@getWindowStatePath()) or '{}')
if keyPath
_.valueForKeyPath(windowState, keyPath)
else
windowState
getInMemoryWindowState: ->
inMemoryState = ipc.sendChannelSync('window-state')
if inMemoryState.length > 0
inMemoryState
else
null
getSavedWindowState: ->
storageKey = switch @windowMode
when 'editor' then window.location.params.pathToOpen
when 'config' then 'config'
localStorage[storageKey] if storageKey
saveWindowState: ->
storageKey = switch @windowMode
when 'editor' then @getPathToOpen()
when 'config' then 'config'
localStorage[storageKey] = JSON.stringify(@getWindowState())
update: ->
@sendMessageToBrowserProcess('update')

View File

@@ -13,6 +13,7 @@ vendoredPackagesDirPath = fsUtils.join(resourcePath, "vendor/packages")
vendoredThemesDirPath = fsUtils.join(resourcePath, "vendor/themes")
userThemesDirPath = fsUtils.join(configDirPath, "themes")
userPackagesDirPath = fsUtils.join(configDirPath, "packages")
userStoragePath = fsUtils.join(configDirPath, ".storage")
# Public: Handles all of Atom's configuration details.
#
@@ -24,6 +25,7 @@ class Config
themeDirPaths: [userThemesDirPath, bundledThemesDirPath, vendoredThemesDirPath]
packageDirPaths: [userPackagesDirPath, vendoredPackagesDirPath, bundledPackagesDirPath]
userPackagesDirPath: userPackagesDirPath
userStoragePath: userStoragePath
lessSearchPaths: [fsUtils.join(resourcePath, 'static'), fsUtils.join(resourcePath, 'vendor')]
defaultSettings: null
settings: null

View File

@@ -70,7 +70,6 @@ window.startConfigWindow = ->
$(window).focus()
window.unloadEditorWindow = ->
console.log 'fuck dude'
return if not project and not rootView
atom.setWindowState('pathToOpen', project.getPath())
atom.setWindowState('project', project.serialize())
@@ -79,7 +78,6 @@ window.unloadEditorWindow = ->
atom.deactivatePackages()
atom.setWindowState('packageStates', atom.packageStates)
rootView.remove()
atom.saveWindowState()
project.destroy()
git?.destroy()
$(window).off('focus blur before')
@@ -106,7 +104,6 @@ window.installAtomCommand = (commandPath, done) ->
window.unloadConfigWindow = ->
return if not configView
atom.setWindowState('configView', configView.serialize())
atom.saveWindowState()
configView.remove()
window.configView = null
$(window).off('focus blur before')

View File

@@ -52,12 +52,10 @@ dialog = require 'dialog'
class AtomApplication
resourcePath: null
windowState: null
menu: null
windows: null
constructor: ({@resourcePath, @executedFrom}) ->
@windowState = {}
@windows = []
@setupJavaScriptArguments()
@@ -116,11 +114,6 @@ class AtomApplication
app.on 'window-all-closed', ->
app.quit()
ipc.on 'window-state', (event, processId, messageId, message) =>
console.log 'browser got request', event, processId, messageId, message if message?
@windowState = message unless message == undefined
event.result = @windowState
ipc.on 'close-without-confirm', (processId, routingId) ->
window = BrowserWindow.fromProcessIdAndRoutingId processId, routingId
window.removeAllListeners 'close'