From 386b786d93b68d9b72e7a483a39d46ede7bcab0d Mon Sep 17 00:00:00 2001 From: Max Brunsfeld Date: Fri, 5 Jan 2018 17:43:51 -0800 Subject: [PATCH] Let 'atom --wait -a folder' exit due to removing the project folder --- spec/main-process/atom-application.test.js | 29 +++++++++++++++++++++- src/atom-environment.js | 11 ++++++-- src/main-process/atom-application.js | 1 + 3 files changed, 38 insertions(+), 3 deletions(-) diff --git a/spec/main-process/atom-application.test.js b/spec/main-process/atom-application.test.js index e9775d225..7818314db 100644 --- a/spec/main-process/atom-application.test.js +++ b/spec/main-process/atom-application.test.js @@ -465,6 +465,33 @@ describe('AtomApplication', function () { await processKillPromise assert.deepEqual(killedPids, [102, 101]) }) + + it('kills the specified pid after a newly-opened directory in an existing window is closed', async () => { + const window = atomApplication.launch(parseCommandLine([])) + await focusWindow(window) + + const dirPath1 = makeTempDir() + const reusedWindow = atomApplication.launch(parseCommandLine(['--wait', '--pid', '101', dirPath1])) + assert.equal(reusedWindow, window) + assert.deepEqual(await getTreeViewRootDirectories(window), [dirPath1]) + assert.deepEqual(killedPids, []) + + const dirPath2 = makeTempDir() + await evalInWebContents(window.browserWindow.webContents, (send, dirPath1, dirPath2) => { + atom.project.setPaths([dirPath1, dirPath2]) + send() + }, dirPath1, dirPath2) + await timeoutPromise(100) + assert.deepEqual(killedPids, []) + + let processKillPromise = new Promise(resolve => { onDidKillProcess = resolve }) + await evalInWebContents(window.browserWindow.webContents, (send, dirPath2) => { + atom.project.setPaths([dirPath2]) + send() + }, dirPath2) + await processKillPromise + assert.deepEqual(killedPids, [101]) + }) }) describe('when closing the last window', () => { @@ -662,7 +689,7 @@ describe('AtomApplication', function () { function sendBackToMainProcess (result) { require('electron').ipcRenderer.send('${channelId}', result) } - (${source})(sendBackToMainProcess) + (${source})(sendBackToMainProcess, ${args.map(JSON.stringify).join(', ')}) `) }) } diff --git a/src/atom-environment.js b/src/atom-environment.js index b629e96d2..6e42f88a0 100644 --- a/src/atom-environment.js +++ b/src/atom-environment.js @@ -824,8 +824,15 @@ class AtomEnvironment { this.document.body.appendChild(this.workspace.getElement()) if (this.backgroundStylesheet) this.backgroundStylesheet.remove() - this.disposables.add(this.project.onDidChangePaths(() => { - this.applicationDelegate.setRepresentedDirectoryPaths(this.project.getPaths()) + let previousProjectPaths = this.project.getPaths() + this.disposables.add(this.project.onDidChangePaths(newPaths => { + for (let path of previousProjectPaths) { + if (this.pathsToNotifyWhenClosed.has(path) && !newPaths.includes(path)) { + this.applicationDelegate.didCloseInitialPath(path) + } + } + previousProjectPaths = newPaths + this.applicationDelegate.setRepresentedDirectoryPaths(newPaths) })) this.disposables.add(this.workspace.onDidDestroyPaneItem(({item}) => { const path = item.getPath && item.getPath() diff --git a/src/main-process/atom-application.js b/src/main-process/atom-application.js index 46a5f8afa..52bc1287b 100644 --- a/src/main-process/atom-application.js +++ b/src/main-process/atom-application.js @@ -888,6 +888,7 @@ class AtomApplication extends EventEmitter { windowDidCloseInitialPath (window, initialPath) { const waitSessions = this.waitSessionsByWindow.get(window) + if (!waitSessions) return for (let i = waitSessions.length - 1; i >= 0; i--) { const session = waitSessions[i] session.remainingPaths.delete(initialPath)