中国建设银行 网站登录,如果建网站,wordpress 内存使用,电气网站开发下载事件
win.webContents.downloadURL(url)
触发session的will-download事件
win.webContents.session.on(will-download, (event, downloadItem, webContents) {// 设置文件保存路径// 如果用户没有设置保存路径#xff0c;Electron将使用默认方式来确定保存路径will-download, (event, downloadItem, webContents) {// 设置文件保存路径// 如果用户没有设置保存路径Electron将使用默认方式来确定保存路径通常会提示保存对话框item.setSavePath(savePath)item.on(updated, (event, state) {// 监听下载过程 state有两种情况// interrupted 下载被中断可恢复// progressing 下载进行中可获取下载进度if (state interrupted) {// 可恢复下载} else if (state progressing) {if (downloadItem.isPaused()) {console.log(Download is paused)} else {// 可以根据字节大小设置进度条console.log(Total bytes: ${downloadItem.getTotalBytes()}) console.log(Received bytes: ${downloadItem.getReceivedBytes()})}}})item.once(done, (event, state) {// 下载结束if (state completed) {// 下载成功console.log(Download successfully)// 用应用程序打开文件openFile(downloadItem.getSavePath())} else {// state为cancelled或interrupted// 下载取消或下载已经中断无法恢复console.log(Download failed: ${state})}// 这里可将下载结束的状态传回给渲染进程win.webContents.send(downstate, state)})
})shell 使用默认应用程序管理文件和 url提供与桌面集成相关的功能
shell.openPath(path) 以桌面的默认方式打开给定的文件。
function openFile(filePath) {const path require(path);shell.openPath(path.join(filePath));
}