mirror of
https://github.com/atom/atom.git
synced 2026-01-24 06:18:03 -05:00
Fall back to local storage when no history can be found
This commit is contained in:
@@ -30,7 +30,7 @@ describe("HistoryManager", () => {
|
||||
return projectDisposable
|
||||
})
|
||||
|
||||
historyManager = new HistoryManager({stateStore, project, commands: commandRegistry})
|
||||
historyManager = new HistoryManager({stateStore, localStorage: window.localStorage, project, commands: commandRegistry})
|
||||
await historyManager.loadState()
|
||||
})
|
||||
|
||||
@@ -75,7 +75,7 @@ describe("HistoryManager", () => {
|
||||
|
||||
it("saves the state", async () => {
|
||||
await historyManager.clearProjects()
|
||||
const historyManager2 = new HistoryManager({stateStore, project, commands: commandRegistry})
|
||||
const historyManager2 = new HistoryManager({stateStore, localStorage: window.localStorage, project, commands: commandRegistry})
|
||||
await historyManager2.loadState()
|
||||
expect(historyManager.getProjects().length).toBe(0)
|
||||
})
|
||||
@@ -186,7 +186,7 @@ describe("HistoryManager", () => {
|
||||
it("saves the state", async () => {
|
||||
await historyManager.addProject(["/save/state"])
|
||||
await historyManager.saveState()
|
||||
const historyManager2 = new HistoryManager({stateStore, project, commands: commandRegistry})
|
||||
const historyManager2 = new HistoryManager({stateStore, localStorage: window.localStorage, project, commands: commandRegistry})
|
||||
await historyManager2.loadState()
|
||||
expect(historyManager2.getProjects()[0].paths).toEqual(['/save/state'])
|
||||
})
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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})
|
||||
|
||||
Reference in New Issue
Block a user