[AsarUpdate] Source cleanup / simplify
This commit is contained in:
parent
a4de8557d3
commit
2a82ee5a1c
|
@ -21,43 +21,25 @@ module.exports = async () => { // (Try) update asar
|
||||||
await new Promise((res) => {
|
await new Promise((res) => {
|
||||||
const file = fs.createWriteStream(downloadPath);
|
const file = fs.createWriteStream(downloadPath);
|
||||||
|
|
||||||
file.on('error', e => {
|
|
||||||
log('AsarUpdate', e);
|
|
||||||
file.close();
|
|
||||||
|
|
||||||
res();
|
|
||||||
});
|
|
||||||
|
|
||||||
file.on('finish', () => {
|
file.on('finish', () => {
|
||||||
file.close();
|
file.close();
|
||||||
res();
|
res();
|
||||||
});
|
});
|
||||||
|
|
||||||
const req = request.get(asarUrl);
|
request.get(asarUrl).on('response', r => r.pipe(file));
|
||||||
|
|
||||||
req.on('response', (res) => res.pipe(file));
|
|
||||||
});
|
});
|
||||||
|
|
||||||
if (fs.readFileSync(downloadPath, 'utf8').startsWith('<Error>')) return log('AsarUpdate', 'Download error');
|
if (fs.readFileSync(downloadPath, 'utf8').startsWith('<Error>')) return log('AsarUpdate', 'Download error');
|
||||||
|
|
||||||
if (await new Promise((res) => {
|
fs.copyFileSync(downloadPath, asarPath); // Overwrite actual app.asar
|
||||||
try {
|
fs.unlinkSync(downloadPath); // Delete downloaded temp file
|
||||||
fs.copyFileSync(downloadPath, asarPath); // Overwrite actual app.asar
|
|
||||||
fs.unlinkSync(downloadPath); // Delete downloaded temp file
|
|
||||||
res();
|
|
||||||
} catch (err) {
|
|
||||||
log('AsarUpdate', err);
|
|
||||||
res(true);
|
|
||||||
}
|
|
||||||
})) return;
|
|
||||||
|
|
||||||
const newHash = getAsarHash();
|
|
||||||
|
|
||||||
if (oaConfig.updatePrompt === true && originalHash !== newHash) {
|
if (oaConfig.updatePrompt === true && originalHash !== getAsarHash()) {
|
||||||
const { response } = await dialog.showMessageBox(null, {
|
const { response } = await dialog.showMessageBox(null, {
|
||||||
message: 'Updated OpenAsar',
|
message: 'Updated OpenAsar',
|
||||||
detail: `Restart required to use new version.`,
|
detail: `Restart required to use new version.`,
|
||||||
buttons: ['Restart Now', 'Later'],
|
buttons: ['Restart', 'Later'],
|
||||||
defaultId: 0
|
defaultId: 0
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue