background.js添加
import { app, ipcMain } from 'electron'
ipcMain.on('updateapp', (event, url) => {
win.webContents.session.once('will-download', (event, item, webContents) => {
const filePath = path.join(app.getPath('downloads'), item.getFilename());
item.setSavePath(filePath);
item.once('done', (event, state) => {
if (state === 'completed') {
const exec = require('child_process').exec
exec(filePath)
} else {
}
})
})
win.webContents.downloadURL(url);
})
页面中调用
import { ipcRenderer } from 'electron'
ipcRenderer.send('updateapp','http://www.baidu.com/update.exe')