[Updater > Module] Minor rewrite to integrate -progress events to not be separate
This commit is contained in:
parent
d3fe05b22e
commit
042e495b7b
2 changed files with 15 additions and 32 deletions
|
@ -185,15 +185,12 @@ const initOld = () => { // "Old" (not v2 / new, win32 only)
|
|||
installs.reset();
|
||||
downloads.reset();
|
||||
|
||||
if (!succeeded) {
|
||||
handleFail();
|
||||
} else if (updateCount === 0) {
|
||||
launchMain();
|
||||
}
|
||||
if (!succeeded) handleFail();
|
||||
else if (updateCount === 0) launchMain();
|
||||
});
|
||||
|
||||
on('downloading-module', ({ name }) => {
|
||||
downloads.record(name, 'Waiting');
|
||||
on('downloading-module', ({ name, cur, total }) => {
|
||||
downloads.record(name, '', cur, total);
|
||||
installs.record(name, 'Waiting');
|
||||
});
|
||||
|
||||
|
@ -203,8 +200,8 @@ const initOld = () => { // "Old" (not v2 / new, win32 only)
|
|||
if (failed > 0) handleFail();
|
||||
});
|
||||
|
||||
on('installing-module', ({ name }) => {
|
||||
installs.record(name, 'Waiting');
|
||||
on('installing-module', ({ name, cur, total }) => {
|
||||
installs.record(name, '', cur, total);
|
||||
});
|
||||
|
||||
const segmentCallback = (tracker) => (({ name }) => {
|
||||
|
@ -217,11 +214,6 @@ const initOld = () => { // "Old" (not v2 / new, win32 only)
|
|||
|
||||
on('installing-modules-finished', check);
|
||||
|
||||
const progressCallback = (tracker) => ({ name, cur, total }) => tracker.record(name, '', cur, total);
|
||||
|
||||
on('downloading-module-progress', progressCallback(downloads));
|
||||
on('installing-module-progress', progressCallback(installs));
|
||||
|
||||
|
||||
on('update-manually', e => {
|
||||
splashState.newVersion = e.newVersion;
|
||||
|
|
|
@ -171,32 +171,30 @@ const checkModules = async () => {
|
|||
|
||||
const downloadModule = async (name, ver) => {
|
||||
downloading.total++;
|
||||
events.emit('downloading-module', {
|
||||
name
|
||||
});
|
||||
|
||||
const url = baseUrl + '/' + name + '/' + ver;
|
||||
|
||||
const path = join(downloadPath, name + '-' + ver + '.zip');
|
||||
const stream = fs.createWriteStream(path);
|
||||
const file = fs.createWriteStream(path);
|
||||
|
||||
// log('Modules', 'Downloading', `${name}@${ver}`);
|
||||
|
||||
let success, total, cur = 0;
|
||||
request({ url, qs }).on('response', (res) => {
|
||||
request({
|
||||
url: baseUrl + '/' + name + '/' + ver,
|
||||
qs
|
||||
}).on('response', (res) => {
|
||||
success = res.statusCode === 200;
|
||||
total = parseInt(res.headers['content-length'] ?? 1, 10);
|
||||
|
||||
res.pipe(stream);
|
||||
res.pipe(file);
|
||||
|
||||
res.on('data', c => {
|
||||
cur += c.length;
|
||||
|
||||
events.emit('downloading-module-progress', { name, cur, total });
|
||||
events.emit('downloading-module', { name, cur, total });
|
||||
});
|
||||
});
|
||||
|
||||
await new Promise((res) => stream.on('close', res));
|
||||
await new Promise((res) => file.on('close', res));
|
||||
|
||||
|
||||
if (!installed[name]) installed[name] = {};
|
||||
|
@ -223,9 +221,6 @@ const downloadModule = async (name, ver) => {
|
|||
|
||||
const installModule = async (name, ver, path) => {
|
||||
installing.total++;
|
||||
events.emit('installing-module', {
|
||||
name
|
||||
});
|
||||
|
||||
// log('Modules', 'Installing', `${name}@${ver}`);
|
||||
|
||||
|
@ -275,11 +270,7 @@ const installModule = async (name, ver, path) => {
|
|||
if (!y.includes('inflating')) return;
|
||||
|
||||
cur++;
|
||||
events.emit('installing-module-progress', {
|
||||
name,
|
||||
cur,
|
||||
total
|
||||
});
|
||||
events.emit('installing-module', { name, cur, total });
|
||||
}));
|
||||
|
||||
proc.on('close', () => {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue