Fall back to local storage when no history can be found

This commit is contained in:
Antonio Scandurra
2017-03-10 14:37:37 +01:00
parent cf9a5b13e3
commit 7e761d39af
3 changed files with 11 additions and 6 deletions

View File

@@ -229,7 +229,7 @@ class AtomEnvironment extends Model
@observeAutoHideMenuBar()
@history = new HistoryManager({@project, @commands, @stateStore})
@history = new HistoryManager({@project, @commands, @stateStore, localStorage: window.localStorage})
# Keep instances of HistoryManager in sync
@disposables.add @history.onDidChangeProjects (e) =>
@applicationDelegate.didChangeHistoryManager() unless e.reloaded

View File

@@ -8,8 +8,9 @@ import {Emitter, CompositeDisposable} from 'event-kit'
//
// The project history is used to enable the 'Reopen Project' menu.
export class HistoryManager {
constructor ({stateStore, project, commands}) {
constructor ({stateStore, localStorage, project, commands}) {
this.stateStore = stateStore
this.localStorage = localStorage
this.emitter = new Emitter()
this.projects = []
this.disposables = new CompositeDisposable()
@@ -93,7 +94,11 @@ export class HistoryManager {
}
async loadState () {
const history = await this.stateStore.load('history-manager')
let history = await this.stateStore.load('history-manager')
if (!history) {
history = JSON.parse(this.localStorage.getItem('history'))
}
if (history && history.projects) {
this.projects = history.projects.filter(p => Array.isArray(p.paths) && p.paths.length > 0).map(p => new HistoryProject(p.paths, new Date(p.lastOpened)))
this.didChangeProjects({reloaded: true})