From 9f453e64fe4f55c243c32e7c0cfeec2cbcb3278c Mon Sep 17 00:00:00 2001 From: Rafael Oleza Date: Tue, 26 Mar 2019 16:52:40 +0100 Subject: [PATCH] Fix reopen project when there are no open windows --- spec/main-process/atom-application.test.js | 37 ++++++++++++++++++++++ spec/reopen-project-menu-manager-spec.js | 15 +++++---- src/main-process/atom-application.js | 4 +++ src/reopen-project-menu-manager.js | 2 +- 4 files changed, 51 insertions(+), 7 deletions(-) diff --git a/spec/main-process/atom-application.test.js b/spec/main-process/atom-application.test.js index 83feac157..7381a21bc 100644 --- a/spec/main-process/atom-application.test.js +++ b/spec/main-process/atom-application.test.js @@ -900,6 +900,43 @@ describe('AtomApplication', function () { ) atomApplication.promptForPathToOpen.reset() }) + + it('allows reopening an existing project after all windows are closed', async () => { + const tempDirPath = makeTempDir('reopen') + + const atomApplication = buildAtomApplication() + sinon.stub(atomApplication, 'promptForPathToOpen') + + // Open a window and then close it, leaving the app running + const [window] = await atomApplication.launch(parseCommandLine([])) + await focusWindow(window) + window.close() + await window.closedPromise + + // Reopen one of the recent projects + atomApplication.emit('application:reopen-project', { paths: [tempDirPath] }) + + const windows = atomApplication.getAllWindows() + + assert(windows.length === 1) + + await focusWindow(windows[0]) + + await conditionPromise( + async () => (await getTreeViewRootDirectories(windows[0])).length === 1 + ) + + // Check that the project was opened correctly. + assert.deepEqual( + await evalInWebContents( + windows[0].browserWindow.webContents, + send => { + send(atom.project.getPaths()) + } + ), + [tempDirPath] + ) + }) } function buildAtomApplication (params = {}) { diff --git a/spec/reopen-project-menu-manager-spec.js b/spec/reopen-project-menu-manager-spec.js index f122eaa3b..82d8eddf5 100644 --- a/spec/reopen-project-menu-manager-spec.js +++ b/spec/reopen-project-menu-manager-spec.js @@ -137,12 +137,12 @@ describe('ReopenProjectMenuManager', () => { const first = projectsMenu.submenu[0] expect(first.label).toBe('/a') expect(first.command).toBe('application:reopen-project') - expect(first.commandDetail).toEqual({ index: 0 }) + expect(first.commandDetail).toEqual({ index: 0, paths: ['/a'] }) const second = projectsMenu.submenu[1] expect(second.label).toBe('b, c:\\') expect(second.command).toBe('application:reopen-project') - expect(second.commandDetail).toEqual({ index: 1 }) + expect(second.commandDetail).toEqual({ index: 1, paths: ['/b', 'c:\\'] }) }) it("adds only the number of menu items specified in the 'core.reopenProjectMenuCount' config", () => { @@ -199,12 +199,12 @@ describe('ReopenProjectMenuManager', () => { const first = projectsMenu.submenu[0] expect(first.label).toBe('/a') expect(first.command).toBe('application:reopen-project') - expect(first.commandDetail).toEqual({ index: 0 }) + expect(first.commandDetail).toEqual({ index: 0, paths: ['/a'] }) const second = projectsMenu.submenu[1] expect(second.label).toBe('b, c:\\') expect(second.command).toBe('application:reopen-project') - expect(second.commandDetail).toEqual({ index: 1 }) + expect(second.commandDetail).toEqual({ index: 1, paths: ['/b', 'c:\\'] }) }) }) @@ -226,12 +226,15 @@ describe('ReopenProjectMenuManager', () => { const first = recentMenu.submenu[0] expect(first.label).toBe('/users/neila') expect(first.command).toBe('application:reopen-project') - expect(first.commandDetail).toEqual({ index: 0 }) + expect(first.commandDetail).toEqual({ index: 0, paths: ['/users/neila'] }) const second = recentMenu.submenu[1] expect(second.label).toBe('buzza, michaelc') expect(second.command).toBe('application:reopen-project') - expect(second.commandDetail).toEqual({ index: 1 }) + expect(second.commandDetail).toEqual({ + index: 1, + paths: ['/users/buzza', 'users/michaelc'] + }) }) }) diff --git a/src/main-process/atom-application.js b/src/main-process/atom-application.js index 00fef2d6f..0021d2df3 100644 --- a/src/main-process/atom-application.js +++ b/src/main-process/atom-application.js @@ -403,6 +403,10 @@ class AtomApplication extends EventEmitter { this.on('application:check-for-update', () => this.autoUpdateManager.check()) if (process.platform === 'darwin') { + this.on('application:reopen-project', ({ paths }) => { + this.openPaths({ pathsToOpen: paths }) + }) + this.on('application:open', () => this.promptForPathToOpen('all', getLoadSettings(), getDefaultPath())) this.on('application:open-file', () => this.promptForPathToOpen('file', getLoadSettings(), getDefaultPath())) this.on('application:open-folder', () => this.promptForPathToOpen('folder', getLoadSettings(), getDefaultPath())) diff --git a/src/reopen-project-menu-manager.js b/src/reopen-project-menu-manager.js index 35564f705..e8c6f03ff 100644 --- a/src/reopen-project-menu-manager.js +++ b/src/reopen-project-menu-manager.js @@ -125,7 +125,7 @@ class ReopenProjectMenuManager { submenu: projects.map((project, index) => ({ label: this.createLabel(project), command: 'application:reopen-project', - commandDetail: {index: index} + commandDetail: { index: index, paths: project.paths } })) } ]