首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >electron怎么下载文件暂停?

electron怎么下载文件暂停?

提问于 2019-02-26 17:27:18
回答 1关注 0查看 2.2K

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()

});

});

});

回答

和开发者交流更多问题细节吧,去 写回答
相关文章

相似问题

相关问答用户
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档