item.pause();会报未定义
// to store downloadItems
var downloadItems = [];
ipcMain.on('dowloadFiles', function(evt, options) {
if(options.command === 'startDownload') {
wc.downloadURL(file.url);
return;
}
if(options.command === 'stopDownload') {
var item = getDownloadItem(options.url);
item.pause();
return;
}
if(options.command === 'resumeDownload') {
var item = getDownloadItem(options.url);
item.resume();
return;
}
});
mainWindow.webContents.session.on('will-download', function(event, item, webContents) {
// Set the save path, making Electron not to prompt a save dialog.
item.setSavePath('c:\\downloadTest\\test.txt');
// store the download item, so that we can call item.pause/resume in a
downloadItems.push(item);
item.on('updated', function(event, state) {
// console.log('when updated send download progress to render process')
mainWindow.webContents.send('updateDownload', {
url: item.getURL(),
progress: item.getReceivedBytes() / item.getTotalBytes()
});
});
});
相似问题