Merge pull request #6629 from electron/download-item-get-save-path
Set download item save path to selected path from dialog
This commit is contained in:
commit
e73bd00854
4 changed files with 22 additions and 6 deletions
|
@ -85,6 +85,14 @@ void AtomDownloadManagerDelegate::OnDownloadPathGenerated(
|
||||||
download_manager_->GetBrowserContext());
|
download_manager_->GetBrowserContext());
|
||||||
browser_context->prefs()->SetFilePath(prefs::kDownloadDefaultDirectory,
|
browser_context->prefs()->SetFilePath(prefs::kDownloadDefaultDirectory,
|
||||||
path.DirName());
|
path.DirName());
|
||||||
|
|
||||||
|
v8::Isolate* isolate = v8::Isolate::GetCurrent();
|
||||||
|
v8::Locker locker(isolate);
|
||||||
|
v8::HandleScope handle_scope(isolate);
|
||||||
|
api::DownloadItem* download_item = api::DownloadItem::FromWrappedClass(
|
||||||
|
isolate, item);
|
||||||
|
if (download_item)
|
||||||
|
download_item->SetSavePath(path);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Running the DownloadTargetCallback with an empty FilePath signals that the
|
// Running the DownloadTargetCallback with an empty FilePath signals that the
|
||||||
|
|
|
@ -80,6 +80,12 @@ The API is only available in session's `will-download` callback function.
|
||||||
If user doesn't set the save path via the API, Electron will use the original
|
If user doesn't set the save path via the API, Electron will use the original
|
||||||
routine to determine the save path(Usually prompts a save dialog).
|
routine to determine the save path(Usually prompts a save dialog).
|
||||||
|
|
||||||
|
### `downloadItem.getSavePath()`
|
||||||
|
|
||||||
|
Returns the save path of the download item. This will be either the path
|
||||||
|
set via `downloadItem.setSavePath(path)` or the path selected from the shown
|
||||||
|
save dialog.
|
||||||
|
|
||||||
### `downloadItem.pause()`
|
### `downloadItem.pause()`
|
||||||
|
|
||||||
Pauses the download.
|
Pauses the download.
|
||||||
|
|
|
@ -239,9 +239,10 @@ describe('session module', function () {
|
||||||
res.end(mockPDF)
|
res.end(mockPDF)
|
||||||
downloadServer.close()
|
downloadServer.close()
|
||||||
})
|
})
|
||||||
var assertDownload = function (event, state, url, mimeType, receivedBytes, totalBytes, disposition, filename, port) {
|
var assertDownload = function (event, state, url, mimeType, receivedBytes, totalBytes, disposition, filename, port, savePath) {
|
||||||
assert.equal(state, 'completed')
|
assert.equal(state, 'completed')
|
||||||
assert.equal(filename, 'mock.pdf')
|
assert.equal(filename, 'mock.pdf')
|
||||||
|
assert.equal(savePath, path.join(__dirname, 'fixtures', 'mock.pdf'))
|
||||||
assert.equal(url, 'http://127.0.0.1:' + port + '/')
|
assert.equal(url, 'http://127.0.0.1:' + port + '/')
|
||||||
assert.equal(mimeType, 'application/pdf')
|
assert.equal(mimeType, 'application/pdf')
|
||||||
assert.equal(receivedBytes, mockPDF.length)
|
assert.equal(receivedBytes, mockPDF.length)
|
||||||
|
@ -256,8 +257,8 @@ describe('session module', function () {
|
||||||
var port = downloadServer.address().port
|
var port = downloadServer.address().port
|
||||||
ipcRenderer.sendSync('set-download-option', false, false)
|
ipcRenderer.sendSync('set-download-option', false, false)
|
||||||
w.loadURL(url + ':' + port)
|
w.loadURL(url + ':' + port)
|
||||||
ipcRenderer.once('download-done', function (event, state, url, mimeType, receivedBytes, totalBytes, disposition, filename) {
|
ipcRenderer.once('download-done', function (event, state, url, mimeType, receivedBytes, totalBytes, disposition, filename, savePath) {
|
||||||
assertDownload(event, state, url, mimeType, receivedBytes, totalBytes, disposition, filename, port)
|
assertDownload(event, state, url, mimeType, receivedBytes, totalBytes, disposition, filename, port, savePath)
|
||||||
done()
|
done()
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
@ -272,8 +273,8 @@ describe('session module', function () {
|
||||||
webview.addEventListener('did-finish-load', function () {
|
webview.addEventListener('did-finish-load', function () {
|
||||||
webview.downloadURL(url + ':' + port + '/')
|
webview.downloadURL(url + ':' + port + '/')
|
||||||
})
|
})
|
||||||
ipcRenderer.once('download-done', function (event, state, url, mimeType, receivedBytes, totalBytes, disposition, filename) {
|
ipcRenderer.once('download-done', function (event, state, url, mimeType, receivedBytes, totalBytes, disposition, filename, savePath) {
|
||||||
assertDownload(event, state, url, mimeType, receivedBytes, totalBytes, disposition, filename, port)
|
assertDownload(event, state, url, mimeType, receivedBytes, totalBytes, disposition, filename, port, savePath)
|
||||||
document.body.removeChild(webview)
|
document.body.removeChild(webview)
|
||||||
done()
|
done()
|
||||||
})
|
})
|
||||||
|
|
|
@ -142,7 +142,8 @@ app.on('ready', function () {
|
||||||
item.getReceivedBytes(),
|
item.getReceivedBytes(),
|
||||||
item.getTotalBytes(),
|
item.getTotalBytes(),
|
||||||
item.getContentDisposition(),
|
item.getContentDisposition(),
|
||||||
item.getFilename())
|
item.getFilename(),
|
||||||
|
item.getSavePath())
|
||||||
})
|
})
|
||||||
if (needCancel) item.cancel()
|
if (needCancel) item.cancel()
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue