[Updater > v2] Rewrite RetainAsar to hook into restarting directly in updater to simplify
This commit is contained in:
parent
4f2a8599f0
commit
7e9ede7fc8
|
@ -1,22 +0,0 @@
|
|||
const paths = require('../paths');
|
||||
const { join } = require('path');
|
||||
const fs = require('original-fs'); // Use original-fs, not Electron's modified fs
|
||||
|
||||
module.exports = () => {
|
||||
log('RetainAsar', 'Trying...');
|
||||
|
||||
const current = join(require.main.filename, '..');
|
||||
|
||||
const installDir = paths.getInstallPath();
|
||||
|
||||
const nextRes = join(installDir, fs.readdirSync(installDir).reverse().find(x => x.startsWith('app-1')), 'resources');
|
||||
const next = join(nextRes, 'app.asar');
|
||||
const backup = join(nextRes, 'app.asar.backup');
|
||||
|
||||
if (next === current) return;
|
||||
|
||||
fs.copyFileSync(next, backup);
|
||||
fs.copyFileSync(current, next);
|
||||
|
||||
log('RetainAsar', 'Done');
|
||||
};
|
|
@ -1,7 +1,6 @@
|
|||
const { join, basename, dirname } = require('path');
|
||||
|
||||
const registry = require('../utils/registry');
|
||||
const retainAsar = require('./retainAsar');
|
||||
|
||||
const appSettings = require('../appSettings');
|
||||
const settings = appSettings.getSettings();
|
||||
|
@ -23,8 +22,6 @@ exports.update = (callback) => {
|
|||
log('AutoStart', 'Update');
|
||||
|
||||
exports.isInstalled(installed => installed ? exports.install(callback) : callback()); // Reinstall if installed, else just callback
|
||||
|
||||
retainAsar(); // Retain OpenAsar
|
||||
};
|
||||
|
||||
exports.uninstall = (callback) => {
|
||||
|
|
|
@ -144,7 +144,17 @@ class Updater extends require('events').EventEmitter {
|
|||
const next = resolve(join(this._getHostPath(), basename(process.execPath)));
|
||||
|
||||
if (next != cur && !options?.allowObsoleteHost) {
|
||||
app.once('will-quit', spawn(next, [], {
|
||||
// Retain OpenAsar
|
||||
const fs = require('original-fs');
|
||||
|
||||
const getAsar = (p) => join(p, '..', 'resources', 'app.asar');
|
||||
const cAsar = getAsar(cur);
|
||||
const nAsar = getAsar(next);
|
||||
|
||||
fs.copyFileSync(nAsar, nAsar + '.backup'); // Copy new app.asar to backup file (<new>/app.asar -> <new>/app.asar.backup)
|
||||
fs.copyFileSync(cAsar, nAsar); // Copy old app.asar to new app.asar (<old>/app.asar -> <new>/app.asar)
|
||||
|
||||
app.once('will-quit', () => spawn(next, [], {
|
||||
detached: true,
|
||||
stdio: 'inherit'
|
||||
}));
|
||||
|
|
Loading…
Reference in New Issue