Skip to content

Commit

Permalink
Update AtomWindow::projectRoots synchronously on openLocations()
Browse files Browse the repository at this point in the history
  • Loading branch information
smashwilson committed Apr 24, 2019
1 parent f1e0843 commit a53addb
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 4 deletions.
19 changes: 19 additions & 0 deletions spec/main-process/atom-window.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,7 @@ describe('AtomWindow', function () {
]

const w = new AtomWindow(app, service, { browserWindowConstructor: StubBrowserWindow, locationsToOpen })
assert.deepEqual(w.projectRoots, ['/directory'])

const loadPromise = emitterEventPromise(w, 'window:loaded')
w.browserWindow.emit('window:loaded')
Expand Down Expand Up @@ -258,6 +259,24 @@ describe('AtomWindow', function () {
assert.isTrue(w.hasProjectPaths())
})

it('is updated synchronously by openLocations', async function () {
const locationsToOpen = [
{ pathToOpen: 'file.txt', isFile: true },
{ pathToOpen: 'directory1', isDirectory: true },
{ pathToOpen: 'directory0', isDirectory: true },
{ pathToOpen: 'directory0', isDirectory: true },
{ pathToOpen: 'new-file.txt' }
]

const w = new AtomWindow(app, service, { browserWindowConstructor: StubBrowserWindow })
assert.deepEqual(w.projectRoots, [])

const promise = w.openLocations(locationsToOpen)
assert.deepEqual(w.projectRoots, ['directory0', 'directory1'])
w.resolveLoadedPromise()
await promise
})

it('is updated by setProjectRoots', function () {
const locationsToOpen = [
{ pathToOpen: 'directory0', exists: true, isDirectory: true }
Expand Down
18 changes: 14 additions & 4 deletions src/main-process/atom-window.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,7 @@ class AtomWindow extends EventEmitter {
if (this.loadSettings.safeMode == null) this.loadSettings.safeMode = false
if (this.loadSettings.clearWindowState == null) this.loadSettings.clearWindowState = false

this.projectRoots = locationsToOpen
.filter(location => location.pathToOpen && location.exists && location.isDirectory)
.map(location => location.pathToOpen)
this.projectRoots.sort()
this.addLocationsToOpen(locationsToOpen)

this.loadSettings.hasOpenFiles = locationsToOpen
.some(location => location.pathToOpen && !location.isDirectory)
Expand Down Expand Up @@ -240,6 +237,7 @@ class AtomWindow extends EventEmitter {
}

async openLocations (locationsToOpen) {
this.addLocationsToOpen(locationsToOpen)
await this.loadedPromise
this.sendMessage('open-locations', locationsToOpen)
}
Expand All @@ -252,6 +250,18 @@ class AtomWindow extends EventEmitter {
this.sendMessage('did-fail-to-read-user-settings', message)
}

addLocationsToOpen (locationsToOpen) {
const roots = new Set(this.projectRoots || [])
for (const {pathToOpen, isDirectory} of locationsToOpen) {
if (isDirectory) {
roots.add(pathToOpen)
}
}

this.projectRoots = Array.from(roots)
this.projectRoots.sort()
}

replaceEnvironment (env) {
this.browserWindow.webContents.send('environment', env)
}
Expand Down

0 comments on commit a53addb

Please sign in to comment.