diff --git a/spec/history-manager-spec.js b/spec/history-manager-spec.js index bc77cb9b8..ed6aac626 100644 --- a/spec/history-manager-spec.js +++ b/spec/history-manager-spec.js @@ -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']) }) diff --git a/src/atom-environment.coffee b/src/atom-environment.coffee index cf5df00d2..6d9b3333f 100644 --- a/src/atom-environment.coffee +++ b/src/atom-environment.coffee @@ -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 diff --git a/src/history-manager.js b/src/history-manager.js index 5087c3bf9..084bdc386 100644 --- a/src/history-manager.js +++ b/src/history-manager.js @@ -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})