Redefine 'will-download' design.
This commit is contained in:
parent
5ef9c7e1a1
commit
0861d5d44b
11 changed files with 149 additions and 101 deletions
|
@ -1,6 +1,7 @@
|
|||
var app = require('app');
|
||||
var ipc = require('ipc');
|
||||
var dialog = require('dialog');
|
||||
var path = require('path');
|
||||
var BrowserWindow = require('browser-window');
|
||||
|
||||
var window = null;
|
||||
|
@ -73,4 +74,26 @@ app.on('ready', function() {
|
|||
});
|
||||
if (chosen == 0) window.destroy();
|
||||
});
|
||||
|
||||
// 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');
|
||||
require('ipc').on('set-download-option', function(event, need_cancel) {
|
||||
window.webContents.session.once('will-download',
|
||||
function(e, item, webContents) {
|
||||
item.setSavePath(downloadFilePath);
|
||||
item.on('done', function(e, state) {
|
||||
window.webContents.send('download-done',
|
||||
state,
|
||||
item.getUrl(),
|
||||
item.getMimeType(),
|
||||
item.getReceivedBytes(),
|
||||
item.getTotalBytes(),
|
||||
item.getContentDisposition());
|
||||
});
|
||||
if (need_cancel)
|
||||
item.cancel();
|
||||
});
|
||||
event.returnValue = "done";
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue