fix(downloads): Add a check to see if last download directory is different, only show item in folder if true

Summary:
Each file downloaded would open finder and show the path to the file. Users were reporting that this felt excessive when downloading multiple files all to the same location #1044. I added a check to see if the path was the same as the previous file path, and only showed the item in the folder if these differed.

Also added tests for this in file download store.

test(downloads): Add tests for showing item in folder only if lastDownloadDirectory differs

Test Plan: Added tests to file-download-store-spec

Reviewers: bengotow

Reviewed By: bengotow

Differential Revision: https://phab.nylas.com/D3121
This commit is contained in:
Annie 2016-07-26 15:01:52 -07:00
parent 2843f3c5f9
commit bff998e1f5
3 changed files with 26 additions and 4 deletions

View file

@ -285,9 +285,28 @@ describe "FileDownloadStore", ->
expect(shell.showItemInFolder).not.toHaveBeenCalled()
@onEndEventCallback()
advanceClock(1)
it "should show file in folder if download path differs from previous download path", ->
spyOn(FileDownloadStore, '_saveDownload').andCallFake =>
Promise.resolve(@testfile)
NylasEnv.savedState.lastDownloadDirectory = null
@userSelectedPath = "/Users/imaginary/.nylas/Another Random Folder/file.jpg"
FileDownloadStore._fetchAndSave(@testfile)
advanceClock(1)
expect(shell.showItemInFolder).toHaveBeenCalledWith(@userSelectedPath)
it "should update the NylasEnv.savedState.lastDownloadDirectory", ->
it "should not show the file in the folder if the download path is the previous download path", ->
spyOn(FileDownloadStore, '_saveDownload').andCallFake =>
Promise.resolve(@testfile)
@userSelectedPath = "/Users/imaginary/.nylas/Another Random Folder/123.png"
NylasEnv.savedState.lastDownloadDirectory = "/Users/imaginary/.nylas/Another Random Folder"
FileDownloadStore._fetchAndSave(@testfile)
advanceClock(1)
expect(shell.showItemInFolder).not.toHaveBeenCalled()
it "should update the NylasEnv.savedState.lastDownloadDirectory if is has changed", ->
spyOn(FileDownloadStore, '_saveDownload').andCallFake =>
Promise.resolve(@testfile)
NylasEnv.savedState.lastDownloadDirectory = null
@userSelectedPath = "/Users/imaginary/.nylas/Another Random Folder/file.jpg"
FileDownloadStore._fetchAndSave(@testfile)

View file

@ -231,8 +231,8 @@ FileDownloadStore = Reflux.createStore
NylasEnv.showSaveDialog {defaultPath}, (savePath) =>
return unless savePath
NylasEnv.savedState.lastDownloadDirectory = path.dirname(savePath)
newDownloadDirectory = path.dirname(savePath)
saveExtension = path.extname(savePath)
didLoseExtension = defaultExtension isnt '' and saveExtension is ''
if didLoseExtension
@ -240,7 +240,10 @@ FileDownloadStore = Reflux.createStore
@_runDownload(file)
.then (download) => @_saveDownload(download, savePath)
.then => shell.showItemInFolder(savePath)
.then =>
if NylasEnv.savedState.lastDownloadDirectory isnt newDownloadDirectory
shell.showItemInFolder(savePath)
NylasEnv.savedState.lastDownloadDirectory = newDownloadDirectory
.catch(@_catchFSErrors)
.catch (error) =>
@_presentError({file, error})

@ -1 +1 @@
Subproject commit e04a35d00a2320a915d4164c886c6d7dd3f0d8f3
Subproject commit aac7ee6017a38af8a93d1a352e5fe3c0153db4a0