[Splash > Backend] Rewrite state handling to use function args
This commit is contained in:
parent
e9a794565a
commit
f4c097e086
|
@ -3,9 +3,7 @@ const { app, ipcMain } = require('electron');
|
||||||
const moduleUpdater = require("../updater/moduleUpdater");
|
const moduleUpdater = require("../updater/moduleUpdater");
|
||||||
const updater = require("../updater/updater");
|
const updater = require("../updater/updater");
|
||||||
|
|
||||||
let splashState = {},
|
let launched, win;
|
||||||
launched,
|
|
||||||
win;
|
|
||||||
|
|
||||||
|
|
||||||
exports.initSplash = (startMin) => {
|
exports.initSplash = (startMin) => {
|
||||||
|
@ -53,10 +51,10 @@ const launchMain = () => {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const sendState = (status) => {
|
const sendState = (status, s = {}) => {
|
||||||
try {
|
try {
|
||||||
win.webContents.send('state', { status, ...splashState });
|
win.webContents.send('state', { status, ...s });
|
||||||
} catch (_e) {}
|
} catch { }
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@ -109,13 +107,11 @@ class UIProgress { // Generic class to track updating and sent states to splash
|
||||||
const progress = [...this.progress.values()].reduce((a, x) => a + x[0], 0) / [...this.progress.values()].reduce((a, x) => a + x[1], 0) * 100;
|
const progress = [...this.progress.values()].reduce((a, x) => a + x[0], 0) / [...this.progress.values()].reduce((a, x) => a + x[1], 0) * 100;
|
||||||
if (progress > 100) return true;
|
if (progress > 100) return true;
|
||||||
|
|
||||||
splashState = {
|
sendState(this.st ? 'installing' : 'downloading', {
|
||||||
current: this.done.size + 1,
|
current: this.done.size + 1,
|
||||||
total: this.total.size,
|
total: this.total.size,
|
||||||
progress
|
progress
|
||||||
};
|
});
|
||||||
|
|
||||||
sendState(this.st ? 'installing' : 'downloading');
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -217,9 +213,8 @@ 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('manual', e => { // Host manual update required
|
on('manual', ({ details }) => { // Host manual update required
|
||||||
splashState.details = e.details;
|
sendState('manual', { details });
|
||||||
sendState('manual');
|
|
||||||
});
|
});
|
||||||
|
|
||||||
sendState(CHECKING_FOR_UPDATES);
|
sendState(CHECKING_FOR_UPDATES);
|
||||||
|
@ -228,9 +223,7 @@ const initOld = () => { // "Old" (not v2 / new, win32 only)
|
||||||
};
|
};
|
||||||
|
|
||||||
const fail = (c) => {
|
const fail = (c) => {
|
||||||
const s = 10;
|
sendState('fail', { seconds: 10 });
|
||||||
splashState.seconds = s;
|
|
||||||
sendState('fail');
|
|
||||||
|
|
||||||
setTimeout(c, s * 1000);
|
setTimeout(c, 10000);
|
||||||
};
|
};
|
Loading…
Reference in New Issue