From 66afc000c07d8cf30caaff4439b57d1bd1a4b386 Mon Sep 17 00:00:00 2001 From: 0neGal Date: Mon, 29 Jan 2024 17:45:17 +0100 Subject: prevent multiple updates running simultaneously We're the renderer to request for an update multiple times, then it'd simply start both updates, at the same time, causing all kinds of issues. This was only really realistically possible to happen if you were to manually check for updates whilst an update automatically were to be checked from right before then. As an example, when Viper starts up, it'll by default check for updates for itself, then Northstar, if you within that time frame checked for updates manually, it'll run both. Now however, we check if an existing update is occurring, and do nothing if so, this is both for Viper and Northstar updates. --- src/modules/update.js | 44 ++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 42 insertions(+), 2 deletions(-) (limited to 'src/modules') diff --git a/src/modules/update.js b/src/modules/update.js index 458b511..0876993 100644 --- a/src/modules/update.js +++ b/src/modules/update.js @@ -112,9 +112,18 @@ async function northstar_update_available() { // simply fetches it from GitHub and updates if it's outdated, very // useful. Not much we have to do on our side. update.viper = (autoinstall) => { + // stop if we're already in the process of updating + if (update.viper.updating) { + return; + } + + update.viper.updating = true; + const { autoUpdater } = require("electron-updater"); if (! autoUpdater.isUpdaterActive()) { + update.viper.updating = false; + if (settings.nsupdate) { update.northstar_autoupdate(); } @@ -125,22 +134,32 @@ update.viper = (autoinstall) => { if (autoinstall) { autoUpdater.on("update-downloaded", (info) => { autoUpdater.quitAndInstall(); + update.viper.updating = false; }); } - autoUpdater.on("error", (info) => {cli.exit(1)}); + autoUpdater.on("error", (info) => { + update.viper.updating = false; + cli.exit(1) + }); + autoUpdater.on("update-not-available", (info) => { + update.viper.updating = false; + // only check for NS updates if Viper itself has no updates and // if NS auto updates is enabled. if (settings.nsupdate || cli.hasArgs()) { update.northstar_autoupdate(); } + cli.exit(); }); autoUpdater.checkForUpdatesAndNotify(); } +update.viper.updating = false; + // removes all mods in "R2Northstar/mods" starting with "Northstar." function remove_core_mods() { if (! gamepath.exists()) {return} @@ -182,12 +201,23 @@ function remove_core_mods() { // `force_install` makes this function not care about whether or not // we're already up-to-date, forcing the install update.northstar = async (force_install) => { + // stop if we're already in the process of updating + if (update.northstar.updating) { + return; + } + + update.northstar.updating = true; + if (await is_running.game()) { + update.northstar.updating = false; console.error(lang("general.auto_updates.game_running")); return false; } - if (! gamepath.exists()) {return} + if (! gamepath.exists()) { + update.northstar.updating = false; + return; + } ipcMain.emit("ns-update-event", "cli.update.checking"); console.info(lang("cli.update.checking")); @@ -196,6 +226,7 @@ update.northstar = async (force_install) => { let latest = await releases.latest.northstar(); if (latest && latest.version == false) { + update.northstar.updating = false; ipcMain.emit("ns-update-event", "cli.update.noInternet"); return; } @@ -206,6 +237,9 @@ update.northstar = async (force_install) => { console.ok(lang("cli.update.uptodate").replace("%s", ns_version)); win.log(lang("gui.update.uptodate")); + + update.northstar.updating = false; + cli.exit(); return; } else { @@ -222,6 +256,7 @@ update.northstar = async (force_install) => { if (res.statusCode !== 200) { ipcMain.emit("ns-update-event", "cli.update.uptodate_short"); console.ok(lang("cli.update.uptodate"), ns_version); + update.northstar.updating = false; return false; } @@ -336,10 +371,15 @@ update.northstar = async (force_install) => { ipcMain.emit("ns-update-event", "cli.update.uptodate_short"); win.log(lang("gui.update.finished")); console.ok(lang("cli.update.finished")); + + update.northstar.updating = false; + cli.exit(); }) }) }) } +update.northstar.updating = false; + module.exports = update; -- cgit v1.2.3