mirror of
https://github.com/atom/atom.git
synced 2026-01-23 05:48:10 -05:00
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:
@@ -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
|
||||
|
||||
@@ -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"
|
||||
|
||||
|
||||
Reference in New Issue
Block a user