show error modal when update failed

This commit is contained in:
HorizonCode 2022-10-20 19:08:48 +02:00
parent 73fb9464d2
commit 1de9fce504
2 changed files with 13 additions and 2 deletions

6
app.js
View File

@ -82,6 +82,12 @@ const run = () => {
type: "update-complete"
})
});
downloadTask.on('error', () => {
mainWindow.webContents.send('status_update', {
type: "error",
message: "An error occured while updating."
});
});
} else
mainWindow.webContents.send('status_update', {

View File

@ -98,14 +98,14 @@ async function filesThatNeedUpdate(osuPath, updateFiles) {
fileName,
fileURL
})
// console.log("hashes are not matching", `(${existingFileMD5} - ${fileHash})`);
//console.log("hashes are not matching", `(${existingFileMD5} - ${fileHash})`);
}
} else {
filesToDownload.push({
fileName,
fileURL
});
// console.log("new file " + fileName);
//console.log("new file " + fileName);
}
}
return filesToDownload;
@ -116,6 +116,7 @@ async function downloadUpdateFiles(osuPath, filesToUpdate) {
let completedIndex = 0;
filesToUpdate.forEach(async (fileToUpdate) => {
const filePath = path.join(osuPath, fileToUpdate.fileName);
console.log(filePath);
if (await fu.existsAsync(filePath))
await fs.promises.rm(filePath);
@ -128,6 +129,10 @@ async function downloadUpdateFiles(osuPath, filesToUpdate) {
if (completedIndex >= filesToUpdate.length)
eventEmitter.emit('completed');
});
fileDownload.on('error', (err) => {
console.log(err);
eventEmitter.emit('error');
});
fileDownload.start().catch(err => console.error(err));
});