1, question 1: a 7za.exe file is placed in the static folder in electron-vue. You want to use childprocess.exec to call it in electron, and you can access it in npm run dev using path.join (_ _ static, "7za.exe"). But after packaging, where will the 7za.exe file in the static be packaged? (the package is electron-builder that comes with electron-vue. )
Code:
/ / here is the process that wants to use nodejs to call the .exe file.
childprocess.exec (path.join (_ _ static, "7za.exe") (err,stdout,stderr) = > {
if(err){
console.log(err);
return false;
}
console.log(stdout);
});
2, question 2: download a .zip file from a specified address in electron. If I want to put the file in the root directory of the packaged application, I use item.setSavePath ("path" + \ ${item.getFilename ()}
) when downloading. How should I write the path when setting the download location? (or save to another location)
mainWindow.webContents.session.on ("will-download", (event, item, webContents) = > {
//
item.setSavePath(+`\\${item.getFilename()}`);
item.on("updated",(event,state)=>{
const totalBytes=item.getTotalBytes();
mainWindow.setProgressBar(item.getReceivedBytes()/totalBytes);
mainWindow.webContents.send("downloadTips",`: ${Math.round(item.getReceivedBytes()/totalBytes*100)}%`);
if(state=="interrupted"){
console.log("");
}else if(state=="progressing"){
console.log("");
}else{
console.log(`: ${item.getReceivedBytes()}`)
}
})