[Splash > Backend] Rewrite update init decision

This commit is contained in:
Ducko 2022-04-20 13:56:52 +01:00
parent 1898178e89
commit 2a44022608
1 changed files with 14 additions and 13 deletions

View File

@ -4,18 +4,17 @@ const moduleUpdater = require("../updater/moduleUpdater");
const updater = require("../updater/updater"); const updater = require("../updater/updater");
let splashState = {}, let splashState = {},
launched = false, launched,
win, newUpdater; win;
exports.initSplash = (startMin = false) => { exports.initSplash = (startMin) => {
newUpdater = updater.getUpdater(); const inst = updater.getUpdater();
if (inst) initNew(inst);
if (newUpdater == null) initModuleUpdater(); else initOld();
launchSplash(startMin); launchSplash(startMin);
if (newUpdater != null) updateUntilCurrent();
if (process.env.OPENASAR_QUICKSTART || oaConfig.quickstart) setTimeout(() => { if (process.env.OPENASAR_QUICKSTART || oaConfig.quickstart) setTimeout(() => {
destroySplash(); destroySplash();
@ -103,7 +102,7 @@ class UIProgress { // Generic class to track updating and sent states to splash
} }
send() { send() {
if ((newUpdater && this.progress.size > 0 && this.progress.size > this.done.size) || (!newUpdater && toSend === this.st)) { if ((toSend === -1 && this.progress.size > 0 && this.progress.size > this.done.size) || toSend === this.st) {
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;
@ -120,7 +119,9 @@ class UIProgress { // Generic class to track updating and sent states to splash
} }
} }
const updateUntilCurrent = async () => { const initNew = async (inst) => {
toSend = -1;
const retryOptions = { const retryOptions = {
skip_host_delta: false, skip_host_delta: false,
skip_module_delta: {} skip_module_delta: {}
@ -134,7 +135,7 @@ const updateUntilCurrent = async () => {
const downloads = new UIProgress(0); const downloads = new UIProgress(0);
const installs = new UIProgress(1); const installs = new UIProgress(1);
await newUpdater.updateToLatestWithOptions(retryOptions, ({ task, state, percent }) => { await inst.updateToLatestWithOptions(retryOptions, ({ task, state, percent }) => {
const download = task.HostDownload || task.ModuleDownload; const download = task.HostDownload || task.ModuleDownload;
const install = task.HostInstall || task.ModuleInstall; const install = task.HostInstall || task.ModuleInstall;
@ -157,8 +158,8 @@ const updateUntilCurrent = async () => {
}); });
if (!installedAnything) { if (!installedAnything) {
await newUpdater.startCurrentVersion(); await inst.startCurrentVersion();
newUpdater.collectGarbage(); inst.collectGarbage();
return launchMain(); return launchMain();
} }
@ -169,7 +170,7 @@ const updateUntilCurrent = async () => {
} }
}; };
const initModuleUpdater = () => { // "Old" (not v2 / new, win32 only) const initOld = () => { // "Old" (not v2 / new, win32 only)
const on = (k, v) => moduleUpdater.events.on(k, v); const on = (k, v) => moduleUpdater.events.on(k, v);
const check = () => moduleUpdater.checkForUpdates(); const check = () => moduleUpdater.checkForUpdates();