[Splash > Backend] Minor source cleanup
This commit is contained in:
parent
b20b3a1566
commit
53f2767b28
2 changed files with 12 additions and 14 deletions
|
@ -10,7 +10,6 @@ let splashState = {};
|
||||||
let modulesListeners = {};
|
let modulesListeners = {};
|
||||||
let launchedMainWindow = false;
|
let launchedMainWindow = false;
|
||||||
let updateAttempt = 0;
|
let updateAttempt = 0;
|
||||||
let restartRequired = false;
|
|
||||||
let splashWindow, updateTimeout, newUpdater;
|
let splashWindow, updateTimeout, newUpdater;
|
||||||
|
|
||||||
|
|
||||||
|
@ -210,6 +209,8 @@ const updateUntilCurrent = async () => {
|
||||||
};
|
};
|
||||||
|
|
||||||
const initModuleUpdater = () => { // "Old" (not v2 / new, win32 only)
|
const initModuleUpdater = () => { // "Old" (not v2 / new, win32 only)
|
||||||
|
let restartRequired;
|
||||||
|
|
||||||
const add = (event, listener) => {
|
const add = (event, listener) => {
|
||||||
modulesListeners[event] = listener;
|
modulesListeners[event] = listener;
|
||||||
moduleUpdater.events.on(event, listener);
|
moduleUpdater.events.on(event, listener);
|
||||||
|
@ -270,14 +271,11 @@ const initModuleUpdater = () => { // "Old" (not v2 / new, win32 only)
|
||||||
add('installing-modules-finished', callbackCheck);
|
add('installing-modules-finished', callbackCheck);
|
||||||
add('no-pending-updates', callbackCheck);
|
add('no-pending-updates', callbackCheck);
|
||||||
|
|
||||||
|
const progressCallback = (tracker) => ({ name, cur, total }) => tracker.record(name, '', cur, total);
|
||||||
|
|
||||||
add('downloading-module-progress', ({ name, recv, total }) => {
|
add('downloading-module-progress', progressCallback(downloads));
|
||||||
downloads.record(name, '', recv, total);
|
add('installing-module-progress', progressCallback(installs));
|
||||||
});
|
|
||||||
|
|
||||||
add('installing-module-progress', ({ name, entries, total }) => {
|
|
||||||
installs.record(name, '', entries, total);
|
|
||||||
});
|
|
||||||
|
|
||||||
add('update-manually', (e) => {
|
add('update-manually', (e) => {
|
||||||
splashState.newVersion = e.newVersion;
|
splashState.newVersion = e.newVersion;
|
||||||
|
|
|
@ -195,13 +195,13 @@ const downloadModule = async (name, ver) => {
|
||||||
const path = join(downloadPath, name + '-' + ver + '.zip');
|
const path = join(downloadPath, name + '-' + ver + '.zip');
|
||||||
const stream = fs.createWriteStream(path);
|
const stream = fs.createWriteStream(path);
|
||||||
|
|
||||||
stream.on('progress', ([recv, total]) => {
|
stream.on('progress', ([cur, total]) => {
|
||||||
const progress = Math.min(100, Math.floor(100 * (recv / total)));
|
const progress = Math.min(100, Math.floor(100 * (cur / total)));
|
||||||
|
|
||||||
events.emit('downloading-module-progress', {
|
events.emit('downloading-module-progress', {
|
||||||
name,
|
name,
|
||||||
progress,
|
progress,
|
||||||
recv,
|
cur,
|
||||||
total
|
total
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -299,17 +299,17 @@ const installModule = async (name, ver, path) => {
|
||||||
|
|
||||||
proc.stderr.on('data', handleErr);
|
proc.stderr.on('data', handleErr);
|
||||||
|
|
||||||
let entries = 0;
|
let cur = 0;
|
||||||
proc.stdout.on('data', (x) => x.toString().split('\n').forEach((x) => {
|
proc.stdout.on('data', (x) => x.toString().split('\n').forEach((x) => {
|
||||||
if (!x.includes('inflating')) return;
|
if (!x.includes('inflating')) return;
|
||||||
|
|
||||||
entries++;
|
cur++;
|
||||||
const progress = Math.min(100, Math.floor(entries / total * 100));
|
const progress = Math.min(100, Math.floor(cur / total * 100));
|
||||||
|
|
||||||
events.emit('installing-module-progress', {
|
events.emit('installing-module-progress', {
|
||||||
name,
|
name,
|
||||||
progress,
|
progress,
|
||||||
entries,
|
cur,
|
||||||
total
|
total
|
||||||
});
|
});
|
||||||
}));
|
}));
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue