aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/lang/en.json9
-rw-r--r--src/lang/fr.json9
-rw-r--r--src/utils.js70
3 files changed, 84 insertions, 4 deletions
diff --git a/src/lang/en.json b/src/lang/en.json
index 68d46c7..bb5cf09 100644
--- a/src/lang/en.json
+++ b/src/lang/en.json
@@ -19,6 +19,12 @@
"cli.update.finished": "Installation/Update finished!",
"cli.update.uptodate": "Latest version (%s) is already installed, skipping update.",
+ "cli.autoupdates.checking": "Checking for Northstar updates...",
+ "cli.autoupdates.available": "Northstar update available!",
+ "cli.autoupdates.gamerunning": "Game is running, refusing to update Northstar",
+ "cli.autoupdates.updatingns": "Launching update process...",
+ "cli.autoupdates.noupdate": "No Northstar update available.",
+
"cli.launch.linuxerror": "Launching the game is not currently supported on Linux",
"cli.mods.failed": "Failed to install mod!",
@@ -58,6 +64,9 @@
"gui.update.uptodate": "Already up to date!",
"gui.update.available": "A new update for Viper is available, do you want to restart and apply it?",
+ "gui.nsupdate.gaming.title": "Northstar update available!",
+ "gui.nsupdate.gaming.body": "An update for Northstar is available.\nYou can force its installation after closing the game.",
+
"gui.launch": "Launch",
"gui.launchvanilla": "Vanilla",
"gui.launchnorthstar": "Northstar",
diff --git a/src/lang/fr.json b/src/lang/fr.json
index 22afa9a..0eb083c 100644
--- a/src/lang/fr.json
+++ b/src/lang/fr.json
@@ -19,6 +19,12 @@
"cli.update.finished": "Mise à jour terminée !",
"cli.update.uptodate": "La dernière version (%s) est déjà installée.",
+ "cli.autoupdates.checking": "Vérifications des mises à jour de Northstar...",
+ "cli.autoupdates.available": "Une mise à jour de Northstar est disponible !",
+ "cli.autoupdates.gamerunning": "Le jeu est en cours d'exécution, impossible de lancer la mise à jour.",
+ "cli.autoupdates.updatingns": "Lancement de la mise à jour...",
+ "cli.autoupdates.noupdate": "Pas de mise à jour de Northstar disponible.",
+
"cli.launch.linuxerror": "Le support du jeu sur Linux n'est pas encore implémenté.",
"cli.mods.failed": "L'installation du mod a échoué.",
@@ -58,6 +64,9 @@
"gui.update.uptodate": "Déjà à jour !",
"gui.update.available": "Une mise à jour pour Viper est disponible, voulez-vous l'installer maintenant ?",
+ "gui.nsupdate.gaming.title": "Mise à jour Northstar disponible !",
+ "gui.nsupdate.gaming.body": "Une mise à jour pour Northstar est disponible.\nVous pourrez l'installer après avoir fermé le jeu.",
+
"gui.launch": "Jouer",
"gui.launchvanilla": "Vanilla",
"gui.launchnorthstar": "Northstar",
diff --git a/src/utils.js b/src/utils.js
index 68cd6c1..87499ae 100644
--- a/src/utils.js
+++ b/src/utils.js
@@ -1,7 +1,7 @@
const path = require("path");
const fs = require("fs-extra");
const copy = require("copy-dir");
-const { app, dialog, ipcMain } = require("electron");
+const { app, dialog, ipcMain, Notification } = require("electron");
const Emitter = require("events");
const events = new Emitter();
@@ -11,7 +11,8 @@ const lang = require("./lang");
const requests = require("./requests");
const unzip = require("unzipper");
-const exec = require("child_process").spawn;
+const run = require("child_process").spawn;
+const exec = require("child_process").exec;
const { https } = require("follow-redirects");
process.chdir(app.getPath("appData"));
@@ -34,6 +35,66 @@ if (fs.existsSync("viper.json")) {
console.log(lang("general.missingpath"));
}
+
+async function isGameRunning() {
+ return new Promise(resolve => {
+ let procs = ["Titanfall2.exe", "Titanfall2-unpacked.exe", "NorthstarLauncher.exe"];
+ let cmd = (() => {
+ switch (process.platform) {
+ case "linux": return "ps -A";
+ case "win32": return "tasklist";
+ }
+ })();
+
+ exec(cmd, (err, stdout) => {
+ for (let i = 0; i < procs.length; i++) {
+ if (stdout.includes(procs[i])) {
+ resolve(true);
+ break
+ }
+
+ if (i == procs.length - 1) {resolve(false)}
+ }
+ });
+ });
+}
+
+northstar_auto_updates: {
+ if (!settings.autoupdate || !fs.existsSync("viper.json") || settings.gamepath.length === 0) {
+ break northstar_auto_updates;
+ }
+
+ async function _checkForUpdates() {
+ let localVersion = getNSVersion();
+ let distantVersion = await requests.getLatestNsVersion();
+ console.log(lang("cli.autoupdates.checking"));
+
+ if (localVersion !== distantVersion) {
+ console.log(lang("cli.autoupdates.available"));
+ if (await isGameRunning()) {
+ console.log(lang("cli.autoupdates.gamerunning"));
+ new Notification({
+ title: lang("gui.nsupdate.gaming.title"),
+ body: lang("gui.nsupdate.gaming.body")
+ }).show();
+ } else {
+ console.log(lang("cli.autoupdates.updatingns"));
+ update();
+ }
+ } else {
+ console.log(lang("cli.autoupdates.noupdate"))
+ }
+
+ setTimeout(
+ _checkForUpdates,
+ 15 * 60 * 1000 // update checking interval must be bigger than cache validity duration
+ );
+ }
+
+ _checkForUpdates();
+}
+
+
function setpath(win) {
if (! win) {
settings.gamepath = cli.param("setpath");
@@ -164,11 +225,11 @@ function launch(version) {
switch(version) {
case "vanilla":
console.log(lang("general.launching"), "Vanilla...")
- exec(path.join(settings.gamepath + "/Titanfall2.exe"))
+ run(path.join(settings.gamepath + "/Titanfall2.exe"))
break;
default:
console.log(lang("general.launching"), "Northstar...")
- exec(path.join(settings.gamepath + "/NorthstarLauncher.exe"))
+ run(path.join(settings.gamepath + "/NorthstarLauncher.exe"))
break;
}
}
@@ -426,6 +487,7 @@ module.exports = {
updatevp,
settings,
getNSVersion,
+ isGameRunning,
setlang: (lang) => {
settings.lang = lang;
saveSettings();