[Updater > v2] Minor source cleanup, fix restarting to next host
This commit is contained in:
parent
8e033ba331
commit
c604370684
1 changed files with 11 additions and 15 deletions
|
@ -22,7 +22,7 @@ class Updater extends EventEmitter {
|
||||||
try {
|
try {
|
||||||
Native = options.nativeUpdaterModule ?? require(paths.getExeDir() + '/updater');
|
Native = options.nativeUpdaterModule ?? require(paths.getExeDir() + '/updater');
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
log('Updater', 'Require fail', e);
|
log('Updater', e); // Error when requiring
|
||||||
|
|
||||||
if (e.code === 'MODULE_NOT_FOUND') return;
|
if (e.code === 'MODULE_NOT_FOUND') return;
|
||||||
throw e;
|
throw e;
|
||||||
|
@ -73,7 +73,7 @@ class Updater extends EventEmitter {
|
||||||
const [ id, detail ] = JSON.parse(response);
|
const [ id, detail ] = JSON.parse(response);
|
||||||
const request = this.requests.get(id);
|
const request = this.requests.get(id);
|
||||||
|
|
||||||
if (request == null) return log('Updater', 'Unknown resp', id, detail);
|
if (request == null) return log('Updater', id, detail); // No request handlers for id / type
|
||||||
|
|
||||||
if (detail['Error'] != null) {
|
if (detail['Error'] != null) {
|
||||||
const {
|
const {
|
||||||
|
@ -113,11 +113,9 @@ class Updater extends EventEmitter {
|
||||||
request.progressCallback?.(progress);
|
request.progressCallback?.(progress);
|
||||||
|
|
||||||
if (progress.task['HostInstall'] != null && progress.state === TASK_STATE_COMPLETE) this.emit('host-updated');
|
if (progress.task['HostInstall'] != null && progress.state === TASK_STATE_COMPLETE) this.emit('host-updated');
|
||||||
} else {
|
} else log('Updater', id, detail); // Unknown response
|
||||||
log('Updater', 'Unknown resp', id, detail);
|
|
||||||
}
|
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
log('Updater', 'Handler excepetion', e);
|
log('Updater', e); // Error handling response
|
||||||
|
|
||||||
if (!this.hasEmittedUnhandledException) {
|
if (!this.hasEmittedUnhandledException) {
|
||||||
this.hasEmittedUnhandledException = true;
|
this.hasEmittedUnhandledException = true;
|
||||||
|
@ -133,7 +131,7 @@ class Updater extends EventEmitter {
|
||||||
else if (detail === 'Ok') return;
|
else if (detail === 'Ok') return;
|
||||||
else if (detail.VersionInfo != null) return detail.VersionInfo;
|
else if (detail.VersionInfo != null) return detail.VersionInfo;
|
||||||
|
|
||||||
log('Updater', 'Unknown resp', detail);
|
log('Updater', detail); // Unknown response
|
||||||
}
|
}
|
||||||
|
|
||||||
_getHostPath() {
|
_getHostPath() {
|
||||||
|
@ -143,16 +141,16 @@ class Updater extends EventEmitter {
|
||||||
_startCurrentVersionInner(options, versions) {
|
_startCurrentVersionInner(options, versions) {
|
||||||
if (this.committedHostVersion == null) this.committedHostVersion = versions.current_host;
|
if (this.committedHostVersion == null) this.committedHostVersion = versions.current_host;
|
||||||
|
|
||||||
const latestPath = resolve(join(this._getHostPath(), basename(process.execPath)));
|
const cur = resolve(process.execPath);
|
||||||
const currentPath = resolve(process.execPath);
|
const next = resolve(join(this._getHostPath(), basename(process.execPath)));
|
||||||
|
|
||||||
if (latestPath != currentPath && !options?.allowObsoleteHost) {
|
if (next != cur && !options?.allowObsoleteHost) {
|
||||||
app.once('will-quit', spawn(hostExePath, [], {
|
app.once('will-quit', spawn(next, [], {
|
||||||
detached: true,
|
detached: true,
|
||||||
stdio: 'inherit'
|
stdio: 'inherit'
|
||||||
}));
|
}));
|
||||||
|
|
||||||
log('Updater', 'Restarting', currentPath, '->', latestPath);
|
log('Updater', 'Restarting', next);
|
||||||
return app.quit();
|
return app.quit();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -288,9 +286,7 @@ class Updater extends EventEmitter {
|
||||||
}
|
}
|
||||||
|
|
||||||
startCurrentVersionSync(options) {
|
startCurrentVersionSync(options) {
|
||||||
const versions = this.queryCurrentVersionsSync();
|
this._startCurrentVersionInner(options, this.queryCurrentVersionsSync());
|
||||||
|
|
||||||
this._startCurrentVersionInner(options, versions);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async commitModules(versions) {
|
async commitModules(versions) {
|
||||||
|
|
Loading…
Reference in a new issue