diff --git a/spec/spec-helper.coffee b/spec/spec-helper.coffee index d494abfca..3b8b16cd2 100644 --- a/spec/spec-helper.coffee +++ b/spec/spec-helper.coffee @@ -38,7 +38,6 @@ beforeEach -> window.resetTimeouts() atom.packageStates = {} - spyOn(atom, 'saveWindowState') spyOn(atom, 'getSavedWindowState').andReturn(null) $native.setWindowState('') syntax.clearGrammarOverrides() diff --git a/src/app/atom.coffee b/src/app/atom.coffee index e8cc2f441..0874336d9 100644 --- a/src/app/atom.coffee +++ b/src/app/atom.coffee @@ -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') diff --git a/src/app/config.coffee b/src/app/config.coffee index c47b1e4cf..2cb4115f8 100644 --- a/src/app/config.coffee +++ b/src/app/config.coffee @@ -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 diff --git a/src/app/window.coffee b/src/app/window.coffee index 0f3370710..08a34681a 100644 --- a/src/app/window.coffee +++ b/src/app/window.coffee @@ -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') diff --git a/src/main.coffee b/src/main.coffee index 36ef9cc4c..37fbf1061 100644 --- a/src/main.coffee +++ b/src/main.coffee @@ -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'