This commit is contained in:
deepak1556 2016-11-24 20:46:39 +05:30 committed by Kevin Sawicki
parent d944219b28
commit f124732431
4 changed files with 125 additions and 12 deletions

View file

@ -137,8 +137,16 @@ app.on('ready', function () {
// For session's download test, listen 'will-download' event in browser, and
// reply the result to renderer for verifying
var downloadFilePath = path.join(__dirname, '..', 'fixtures', 'mock.pdf')
ipcMain.on('set-download-option', function (event, needCancel, preventDefault) {
ipcMain.on('set-download-option', function (event, needCancel, preventDefault, filePath = downloadFilePath) {
window.webContents.session.once('will-download', function (e, item) {
window.webContents.send('download-created',
item.getState(),
item.getURLChain(),
item.getMimeType(),
item.getReceivedBytes(),
item.getTotalBytes(),
item.getFilename(),
item.getSavePath())
if (preventDefault) {
e.preventDefault()
const url = item.getURL()
@ -151,7 +159,11 @@ app.on('ready', function () {
}
})
} else {
item.setSavePath(downloadFilePath)
if (item.getState() === 'interrupted' && !needCancel) {
item.resume()
} else {
item.setSavePath(filePath)
}
item.on('done', function (e, state) {
window.webContents.send('download-done',
state,
@ -161,7 +173,10 @@ app.on('ready', function () {
item.getTotalBytes(),
item.getContentDisposition(),
item.getFilename(),
item.getSavePath())
item.getSavePath(),
item.getURLChain(),
item.getLastModifiedTime(),
item.getETag())
})
if (needCancel) item.cancel()
}