[Updater > Module] Don't recheck after just installed, also minor source cleanup
This commit is contained in:
parent
a4226a17a0
commit
b9ae3495fb
1 changed files with 28 additions and 38 deletions
|
@ -20,7 +20,7 @@ let settings,
|
||||||
hostUpdater,
|
hostUpdater,
|
||||||
baseUrl, baseQuery,
|
baseUrl, baseQuery,
|
||||||
inBackground,
|
inBackground,
|
||||||
checking, hostAvail;
|
checking, hostAvail, lastUpdate;
|
||||||
|
|
||||||
const resetTracking = () => {
|
const resetTracking = () => {
|
||||||
const base = {
|
const base = {
|
||||||
|
@ -71,15 +71,13 @@ exports.init = (endpoint, _settings, buildInfo) => {
|
||||||
hostAvail = true;
|
hostAvail = true;
|
||||||
events.emit('update-check-finished', {
|
events.emit('update-check-finished', {
|
||||||
succeeded: true,
|
succeeded: true,
|
||||||
updateCount: 1,
|
updateCount: 1
|
||||||
manualRequired: false
|
|
||||||
});
|
});
|
||||||
|
|
||||||
events.emit('downloading-module', {
|
events.emit('downloading-module', {
|
||||||
name: 'host',
|
name: 'host',
|
||||||
current: 1,
|
current: 1,
|
||||||
total: 1,
|
total: 1
|
||||||
foreground: !inBackground
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -97,8 +95,7 @@ exports.init = (endpoint, _settings, buildInfo) => {
|
||||||
|
|
||||||
events.emit('update-check-finished', {
|
events.emit('update-check-finished', {
|
||||||
succeeded: true,
|
succeeded: true,
|
||||||
updateCount: 1,
|
updateCount: 1
|
||||||
manualRequired: true
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -135,15 +132,14 @@ exports.init = (endpoint, _settings, buildInfo) => {
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
const hostPassed = () => {
|
const hostPassed = (skip = skipModule) => {
|
||||||
log('Modules', 'Host good');
|
if (skip) return events.emit('update-check-finished', {
|
||||||
|
|
||||||
if (skipModule) return events.emit('update-check-finished', {
|
|
||||||
succeeded: true,
|
succeeded: true,
|
||||||
updateCount: 0,
|
updateCount: 0
|
||||||
manualRequired: false
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
log('Modules', 'Host good');
|
||||||
|
|
||||||
checkModules();
|
checkModules();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -158,43 +154,39 @@ const checkModules = async () => {
|
||||||
|
|
||||||
log('Modules', 'Checking @', url);
|
log('Modules', 'Checking @', url);
|
||||||
|
|
||||||
let resp;
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
resp = await request.get({ url, qs, timeout: 15000 });
|
const { body } = await request.get({ url, qs, timeout: 15000 });
|
||||||
checking = false;
|
checking = false;
|
||||||
|
|
||||||
|
remote = JSON.parse(body);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
log('Modules', 'Check failed', e);
|
log('Modules', 'Check failed', e);
|
||||||
|
|
||||||
return events.emit('update-check-finished', {
|
return events.emit('update-check-finished', {
|
||||||
succeeded: false,
|
succeeded: false,
|
||||||
updateCount: 0,
|
updateCount: 0
|
||||||
manualRequired: false
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
remote = JSON.parse(resp.body);
|
remote = JSON.parse(body);
|
||||||
|
|
||||||
const todo = [];
|
let doing = 0;
|
||||||
for (const name in installed) {
|
for (const name in installed) {
|
||||||
const inst = installed[name].installedVersion;
|
const inst = installed[name].installedVersion;
|
||||||
const rem = remote[name];
|
const rem = remote[name];
|
||||||
|
|
||||||
if (inst !== rem) {
|
if (inst !== rem) {
|
||||||
log('Modules', 'Update:', name, '|', inst, '->', rem);
|
log('Modules', 'Update:', name, '|', inst, '->', rem);
|
||||||
todo.push({ name, version: rem });
|
doing++;
|
||||||
|
|
||||||
|
downloadModule(name, rem);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
events.emit('update-check-finished', {
|
events.emit('update-check-finished', {
|
||||||
succeeded: true,
|
succeeded: true,
|
||||||
updateCount: todo.length,
|
updateCount: doing
|
||||||
manualRequired: false
|
|
||||||
});
|
});
|
||||||
|
|
||||||
if (todo.length === 0) return log('Modules', 'Nothing todo');
|
|
||||||
|
|
||||||
for (const mod of todo) downloadModule(mod.name, mod.version);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const downloadModule = async (name, ver) => {
|
const downloadModule = async (name, ver) => {
|
||||||
|
@ -202,8 +194,7 @@ const downloadModule = async (name, ver) => {
|
||||||
events.emit('downloading-module', {
|
events.emit('downloading-module', {
|
||||||
name,
|
name,
|
||||||
current: downloading.total,
|
current: downloading.total,
|
||||||
total: downloading.total,
|
total: downloading.total
|
||||||
foreground: !inBackground
|
|
||||||
});
|
});
|
||||||
|
|
||||||
const url = baseUrl + '/' + name + '/' + ver;
|
const url = baseUrl + '/' + name + '/' + ver;
|
||||||
|
@ -251,9 +242,7 @@ const downloadModule = async (name, ver) => {
|
||||||
events.emit('downloaded-module', {
|
events.emit('downloaded-module', {
|
||||||
name: name,
|
name: name,
|
||||||
current: downloading.total,
|
current: downloading.total,
|
||||||
total: downloading.total,
|
total: downloading.total
|
||||||
succeeded: success,
|
|
||||||
receivedBytes: received
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
@ -279,10 +268,7 @@ const installModule = (name, ver, path) => {
|
||||||
events.emit('installing-module', {
|
events.emit('installing-module', {
|
||||||
name,
|
name,
|
||||||
current: installing.total,
|
current: installing.total,
|
||||||
total: installing.total,
|
total: installing.total
|
||||||
foreground: !inBackground,
|
|
||||||
oldVersion: currentVer,
|
|
||||||
newVersion: ver
|
|
||||||
});
|
});
|
||||||
|
|
||||||
log('Modules', 'Installing', `${name}@${ver}`, 'from', path);
|
log('Modules', 'Installing', `${name}@${ver}`, 'from', path);
|
||||||
|
@ -351,6 +337,8 @@ const finishInstall = (name, ver, success) => {
|
||||||
const succeeded = installing.total - installing.fail;
|
const succeeded = installing.total - installing.fail;
|
||||||
log('Modules', 'Done installs', `| ${succeeded}/${installing.total} success`);
|
log('Modules', 'Done installs', `| ${succeeded}/${installing.total} success`);
|
||||||
|
|
||||||
|
if (!installing.fail) lastUpdate = Date.now();
|
||||||
|
|
||||||
events.emit('installing-modules-finished', {
|
events.emit('installing-modules-finished', {
|
||||||
succeeded,
|
succeeded,
|
||||||
failed: installing.fail
|
failed: installing.fail
|
||||||
|
@ -369,9 +357,11 @@ exports.checkForUpdates = () => {
|
||||||
if (checking) return;
|
if (checking) return;
|
||||||
checking = true;
|
checking = true;
|
||||||
|
|
||||||
if (skipHost) {
|
const skipThis = lastUpdate > Date.now() - 10000;
|
||||||
|
|
||||||
|
if (skipHost || skipThis) {
|
||||||
events.emit('checking-for-updates');
|
events.emit('checking-for-updates');
|
||||||
hostPassed();
|
hostPassed(skipModule || skipThis);
|
||||||
} else {
|
} else {
|
||||||
hostUpdater.checkForUpdates();
|
hostUpdater.checkForUpdates();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue