[Updater > Module] More renaming of some general events

This commit is contained in:
Ducko 2022-04-22 21:51:35 +01:00
parent 25ff7efdc0
commit e4990cd3ad
2 changed files with 24 additions and 31 deletions

View file

@ -184,25 +184,27 @@ const initOld = () => { // "Old" (not v2 / new, win32 only)
fail(check); fail(check);
}; };
on('update-check-finished', ({ succeeded, updateCount }) => { on('checked', ({ failed, count }) => { // Finished check
installs.reset(); installs.reset();
downloads.reset(); downloads.reset();
if (!succeeded) handleFail(); if (failed) handleFail();
else if (updateCount === 0) launchMain(); else if (count === 0) launchMain();
}); });
on('downloaded', ({ failed }) => { // Downloaded all modules
toSend = 1;
if (failed > 0) handleFail();
});
on('installed', check); // Installed all modules
on('downloading-module', ({ name, cur, total }) => { on('downloading-module', ({ name, cur, total }) => {
downloads.record(name, '', cur, total); downloads.record(name, '', cur, total);
installs.record(name, 'Waiting'); installs.record(name, 'Waiting');
}); });
on('downloading-modules-finished', ({ failed }) => {
toSend = 1;
if (failed > 0) handleFail();
});
on('installing-module', ({ name, cur, total }) => { on('installing-module', ({ name, cur, total }) => {
installs.record(name, '', cur, total); installs.record(name, '', cur, total);
}); });
@ -215,10 +217,7 @@ const initOld = () => { // "Old" (not v2 / new, win32 only)
on('downloaded-module', segment(downloads)); on('downloaded-module', segment(downloads));
on('installed-module', segment(installs)); on('installed-module', segment(installs));
on('installing-modules-finished', check); on('manual', e => { // Host manual update required
on('manual', e => {
splashState.details = e.details; splashState.details = e.details;
sendState('manual'); sendState('manual');
}); });

View file

@ -76,9 +76,8 @@ exports.init = (endpoint, { releaseChannel, version }) => {
hostUpdater.on('update-available', () => { hostUpdater.on('update-available', () => {
log('Modules', 'Host available'); log('Modules', 'Host available');
events.emit('update-check-finished', { events.emit('checked', {
succeeded: true, count: 1
updateCount: 1
}); });
}); });
@ -103,7 +102,7 @@ exports.init = (endpoint, { releaseChannel, version }) => {
hostUpdater.on('error', () => { hostUpdater.on('error', () => {
log('Modules', 'Host error'); log('Modules', 'Host error');
events.emit('update-check-finished', { succeeded: false }); events.emit('checked', { failed: true });
}); });
const platform = process.platform === 'darwin' ? 'osx' : 'linux'; const platform = process.platform === 'darwin' ? 'osx' : 'linux';
@ -117,9 +116,8 @@ exports.init = (endpoint, { releaseChannel, version }) => {
}; };
const hostPassed = (skip = skipModule) => { const hostPassed = (skip = skipModule) => {
if (skip) return events.emit('update-check-finished', { if (skip) return events.emit('checked', {
succeeded: true, count: 0
updateCount: 0
}); });
log('Modules', 'Host good'); log('Modules', 'Host good');
@ -136,9 +134,8 @@ const checkModules = async () => {
} catch (e) { } catch (e) {
log('Modules', 'Check failed', e); log('Modules', 'Check failed', e);
return events.emit('update-check-finished', { return events.emit('checked', {
succeeded: false, failed: true
updateCount: 0
}); });
} }
@ -156,8 +153,7 @@ const checkModules = async () => {
} }
events.emit('update-check-finished', { events.emit('update-check-finished', {
succeeded: true, count: doing
updateCount: doing
}); });
}; };
@ -202,8 +198,7 @@ const downloadModule = async (name, ver) => {
downloading.done++; downloading.done++;
if (downloading.done === downloading.total) { if (downloading.done === downloading.total) {
events.emit('downloading-modules-finished', { events.emit('downloaded', {
succeeded: downloading.total - downloading.fail,
failed: downloading.fail failed: downloading.fail
}); });
} }
@ -289,8 +284,7 @@ const finishInstall = (name, ver, success) => {
if (installing.done === downloading.total) { if (installing.done === downloading.total) {
if (!installing.fail) last = Date.now(); if (!installing.fail) last = Date.now();
events.emit('installing-modules-finished', { events.emit('installed', {
succeeded: installing.total - installing.fail,
failed: installing.fail failed: installing.fail
}); });
@ -311,13 +305,13 @@ exports.checkForUpdates = () => {
exports.quitAndInstallUpdates = () => hostUpdater.quitAndInstall(); exports.quitAndInstallUpdates = () => hostUpdater.quitAndInstall();
const isInstalled = exports.isInstalled = (n, v) => installed[n] && !(v && installed[n].installedVersion !== v); exports.isInstalled = (n, v) => installed[n] && !(v && installed[n].installedVersion !== v);
exports.getInstalled = () => ({ ...installed }); exports.getInstalled = () => ({ ...installed });
const commitManifest = () => fs.writeFileSync(manifestPath, JSON.stringify(installed, null, 2)); const commitManifest = () => fs.writeFileSync(manifestPath, JSON.stringify(installed, null, 2));
exports.install = (name, def, { version } = {}) => { exports.install = (name, def, { version } = {}) => {
if (isInstalled(name, version)) { if (exports.isInstalled(name, version)) {
if (!def) events.emit('installed-module', { if (!def) events.emit('installed-module', {
name, name,
succeeded: true succeeded: true