Serialize site across window loads

This prevents issues with the site counter resetting to 1 on each
load causing duplicate array and marker ids to be generated.

Closes #729
This commit is contained in:
Kevin Sawicki & Nathan Sobo
2013-08-20 18:29:19 -07:00
parent 6fb8dcbaa5
commit 116c56c236
3 changed files with 12 additions and 5 deletions

View File

@@ -228,11 +228,19 @@ window.atom =
catch error
console.warn "Error parsing window state: #{windowStatePath}", error.stack, error
windowState ?= {}
site.deserializeDocument(windowState) ? site.createDocument({})
{site, document} = windowState ? {}
if site? and document?
window.site = telepath.Site.deserialize(site)
window.site.deserializeDocument(document)
else
window.site = new telepath.Site(1)
window.site.createDocument({})
saveWindowState: ->
windowStateJson = JSON.stringify(@getWindowState().serialize(), null, 2)
windowState =
site: site.serialize()
document: @getWindowState().serialize()
windowStateJson = JSON.stringify(windowState, null, 2)
if windowStatePath = @getWindowStatePath()
fsUtils.writeSync(windowStatePath, "#{windowStateJson}\n")
else

View File

@@ -21,7 +21,6 @@ windowEventHandler = null
# This method is called in any window needing a general environment, including specs
window.setUpEnvironment = (windowMode) ->
window.site = new telepath.Site(1)
atom.windowMode = windowMode
window.resourcePath = remote.getCurrentWindow().loadSettings.resourcePath