mirror of
https://github.com/atom/atom.git
synced 2026-01-24 14:28:14 -05:00
Move StateStore into the snapshot
This commit is contained in:
@@ -144,6 +144,8 @@ class AtomEnvironment extends Model
|
||||
@views = new ViewRegistry(this)
|
||||
@notifications = new NotificationManager
|
||||
|
||||
@stateStore = new StateStore('AtomEnvironments', 1)
|
||||
|
||||
@config = new Config({notificationManager: @notifications, @enablePersistence})
|
||||
@config.setSchema null, {type: 'object', properties: _.clone(ConfigSchema)}
|
||||
|
||||
@@ -193,7 +195,7 @@ class AtomEnvironment extends Model
|
||||
|
||||
@windowEventHandler = new WindowEventHandler({atomEnvironment: this, @applicationDelegate})
|
||||
|
||||
@history = new HistoryManager({@project, @commands})
|
||||
@history = new HistoryManager({@project, @commands, @stateStore})
|
||||
# Keep instances of HistoryManager in sync
|
||||
@disposables.add @history.onDidChangeProjects (e) =>
|
||||
@applicationDelegate.didChangeHistoryManager() unless e.reloaded
|
||||
@@ -202,8 +204,6 @@ class AtomEnvironment extends Model
|
||||
{@window, @document, @blobStore, @configDirPath, onlyLoadBaseStyleSheets} = params
|
||||
{devMode, safeMode, resourcePath, clearWindowState} = @getLoadSettings()
|
||||
|
||||
@stateStore = new StateStore('AtomEnvironments', 1)
|
||||
|
||||
if clearWindowState
|
||||
@getStorageFolder().clear()
|
||||
@stateStore.clear()
|
||||
@@ -256,7 +256,7 @@ class AtomEnvironment extends Model
|
||||
|
||||
@observeAutoHideMenuBar()
|
||||
|
||||
@history.initialize(@stateStore, @window.localStorage)
|
||||
@history.initialize(@window.localStorage)
|
||||
@disposables.add @applicationDelegate.onDidChangeHistoryManager(=> @history.loadState())
|
||||
|
||||
attachSaveStateListeners: ->
|
||||
|
||||
@@ -8,7 +8,8 @@ import {Emitter, CompositeDisposable} from 'event-kit'
|
||||
//
|
||||
// The project history is used to enable the 'Reopen Project' menu.
|
||||
export class HistoryManager {
|
||||
constructor ({project, commands}) {
|
||||
constructor ({project, commands, stateStore}) {
|
||||
this.stateStore = stateStore
|
||||
this.emitter = new Emitter()
|
||||
this.projects = []
|
||||
this.disposables = new CompositeDisposable()
|
||||
@@ -16,8 +17,7 @@ export class HistoryManager {
|
||||
this.disposables.add(project.onDidChangePaths((projectPaths) => this.addProject(projectPaths)))
|
||||
}
|
||||
|
||||
initialize (stateStore, localStorage) {
|
||||
this.stateStore = stateStore
|
||||
initialize (localStorage) {
|
||||
this.localStorage = localStorage
|
||||
}
|
||||
|
||||
|
||||
@@ -4,22 +4,31 @@ module.exports =
|
||||
class StateStore {
|
||||
constructor (databaseName, version) {
|
||||
this.connected = false
|
||||
this.dbPromise = new Promise((resolve) => {
|
||||
let dbOpenRequest = indexedDB.open(databaseName, version)
|
||||
dbOpenRequest.onupgradeneeded = (event) => {
|
||||
let db = event.target.result
|
||||
db.createObjectStore('states')
|
||||
}
|
||||
dbOpenRequest.onsuccess = () => {
|
||||
this.connected = true
|
||||
resolve(dbOpenRequest.result)
|
||||
}
|
||||
dbOpenRequest.onerror = (error) => {
|
||||
console.error('Could not connect to indexedDB', error)
|
||||
this.connected = false
|
||||
resolve(null)
|
||||
}
|
||||
})
|
||||
this.databaseName = databaseName
|
||||
this.version = version
|
||||
}
|
||||
|
||||
get dbPromise () {
|
||||
if (!this._dbPromise) {
|
||||
this._dbPromise = new Promise((resolve) => {
|
||||
const dbOpenRequest = indexedDB.open(this.databaseName, this.version)
|
||||
dbOpenRequest.onupgradeneeded = (event) => {
|
||||
let db = event.target.result
|
||||
db.createObjectStore('states')
|
||||
}
|
||||
dbOpenRequest.onsuccess = () => {
|
||||
this.connected = true
|
||||
resolve(dbOpenRequest.result)
|
||||
}
|
||||
dbOpenRequest.onerror = (error) => {
|
||||
console.error('Could not connect to indexedDB', error)
|
||||
this.connected = false
|
||||
resolve(null)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
return this._dbPromise
|
||||
}
|
||||
|
||||
isConnected () {
|
||||
|
||||
Reference in New Issue
Block a user