From e8fcdcd303fd0443c0677d9f1347c8fd3a8aee1b Mon Sep 17 00:00:00 2001 From: Alystrasz Date: Sat, 8 Jan 2022 18:59:50 +0100 Subject: [feat] checking every 15 minutes for new Northstar version --- src/utils.js | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/src/utils.js b/src/utils.js index 68cd6c1..38aaf85 100644 --- a/src/utils.js +++ b/src/utils.js @@ -34,6 +34,24 @@ if (fs.existsSync("viper.json")) { console.log(lang("general.missingpath")); } + +// auto-updates +{ + setInterval(async _ => { + const localVersion = getNSVersion(); + const distantVersion = await requests.getLatestNsVersion(); + + if (localVersion !== distantVersion) { + console.log('Northstar update available'); + update(); + } + }, + + // update checking interval must be bigger than cache validity duration + 15 * 60 * 1000); +} + + function setpath(win) { if (! win) { settings.gamepath = cli.param("setpath"); -- cgit v1.2.3 From 3bb33d94b47764d8ee8b6b7df0aef1573e55078d Mon Sep 17 00:00:00 2001 From: Alystrasz Date: Sat, 8 Jan 2022 19:12:37 +0100 Subject: [feat] not checking for updates if settings.autoupdate is false --- src/utils.js | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/utils.js b/src/utils.js index 38aaf85..c06aca1 100644 --- a/src/utils.js +++ b/src/utils.js @@ -35,15 +35,19 @@ if (fs.existsSync("viper.json")) { } -// auto-updates -{ +northstar_auto_updates: { + if (!settings.autoupdate) break northstar_auto_updates; + setInterval(async _ => { const localVersion = getNSVersion(); const distantVersion = await requests.getLatestNsVersion(); + console.log('Checking for Northstar updates...'); if (localVersion !== distantVersion) { - console.log('Northstar update available'); + console.log('Northstar update available! Launching update process.'); update(); + } else { + console.log('No Northstar update available.') } }, -- cgit v1.2.3 From b71a948c8295bf1e55d2bd32f270b65280ba2b26 Mon Sep 17 00:00:00 2001 From: Remy Raes Date: Mon, 10 Jan 2022 17:07:10 +0100 Subject: [fix] checking for updates on viper launch --- src/utils.js | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/src/utils.js b/src/utils.js index c06aca1..eeeb1da 100644 --- a/src/utils.js +++ b/src/utils.js @@ -38,7 +38,7 @@ if (fs.existsSync("viper.json")) { northstar_auto_updates: { if (!settings.autoupdate) break northstar_auto_updates; - setInterval(async _ => { + async function _checkForUpdates() { const localVersion = getNSVersion(); const distantVersion = await requests.getLatestNsVersion(); console.log('Checking for Northstar updates...'); @@ -49,10 +49,14 @@ northstar_auto_updates: { } else { console.log('No Northstar update available.') } - }, - - // update checking interval must be bigger than cache validity duration - 15 * 60 * 1000); + + setTimeout( + _checkForUpdates, + 15 * 60 * 1000 // update checking interval must be bigger than cache validity duration + ); + } + + _checkForUpdates(); } -- cgit v1.2.3 From edbf9b25a4eb80d54d7a4ad4a1857bc6b8a3294d Mon Sep 17 00:00:00 2001 From: Alystrasz Date: Mon, 10 Jan 2022 20:14:22 +0100 Subject: [fix] not running auto-updates if viper.json does not exist --- src/utils.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/utils.js b/src/utils.js index eeeb1da..72c0ba2 100644 --- a/src/utils.js +++ b/src/utils.js @@ -36,7 +36,7 @@ if (fs.existsSync("viper.json")) { northstar_auto_updates: { - if (!settings.autoupdate) break northstar_auto_updates; + if (!settings.autoupdate || !fs.existsSync("viper.json")) break northstar_auto_updates; async function _checkForUpdates() { const localVersion = getNSVersion(); -- cgit v1.2.3 From 3d96636bb0bbdc271d49999f7a10216690a19157 Mon Sep 17 00:00:00 2001 From: Alystrasz Date: Mon, 10 Jan 2022 20:17:43 +0100 Subject: [fix] not running auto-updates if gamepath is not set --- src/utils.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/utils.js b/src/utils.js index 72c0ba2..faa0f13 100644 --- a/src/utils.js +++ b/src/utils.js @@ -36,7 +36,8 @@ if (fs.existsSync("viper.json")) { northstar_auto_updates: { - if (!settings.autoupdate || !fs.existsSync("viper.json")) break northstar_auto_updates; + if (!settings.autoupdate || !fs.existsSync("viper.json") || settings.gamepath.length === 0) + break northstar_auto_updates; async function _checkForUpdates() { const localVersion = getNSVersion(); -- cgit v1.2.3 From 2dd43ab44db1a9eb29bc1e53f69810f0e2bb6012 Mon Sep 17 00:00:00 2001 From: Alystrasz Date: Mon, 10 Jan 2022 20:34:58 +0100 Subject: [refactor] renaming exec to run --- src/utils.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/utils.js b/src/utils.js index faa0f13..b944a03 100644 --- a/src/utils.js +++ b/src/utils.js @@ -11,7 +11,7 @@ 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 { https } = require("follow-redirects"); process.chdir(app.getPath("appData")); @@ -191,11 +191,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; } } -- cgit v1.2.3 From b32ad187349b55f36b95ebf8a476c77a65c2af36 Mon Sep 17 00:00:00 2001 From: Alystrasz Date: Mon, 10 Jan 2022 20:41:19 +0100 Subject: [feat] adding code to check if a tf2 process is running --- src/utils.js | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/src/utils.js b/src/utils.js index b944a03..a0ce010 100644 --- a/src/utils.js +++ b/src/utils.js @@ -12,6 +12,7 @@ const requests = require("./requests"); const unzip = require("unzipper"); const run = require("child_process").spawn; +const exec = require("child_process").exec; const { https } = require("follow-redirects"); process.chdir(app.getPath("appData")); @@ -35,11 +36,36 @@ if (fs.existsSync("viper.json")) { } +async function _isGameRunning() { + return new Promise(resolve => { + let procs = ["Titanfall2.exe", "Titanfall2-unpacked.exe", "NorthstarLauncher2.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() { + console.log(await _isGameRunning()); + const localVersion = getNSVersion(); const distantVersion = await requests.getLatestNsVersion(); console.log('Checking for Northstar updates...'); -- cgit v1.2.3 From 6017ba7c3e73dba077b7ac4d4de392705f92c505 Mon Sep 17 00:00:00 2001 From: Alystrasz Date: Tue, 11 Jan 2022 16:15:50 +0100 Subject: [fix] not checking for NorthstarLauncher2.exe process anymore --- src/utils.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/utils.js b/src/utils.js index a0ce010..7256444 100644 --- a/src/utils.js +++ b/src/utils.js @@ -38,7 +38,7 @@ if (fs.existsSync("viper.json")) { async function _isGameRunning() { return new Promise(resolve => { - let procs = ["Titanfall2.exe", "Titanfall2-unpacked.exe", "NorthstarLauncher2.exe"]; + let procs = ["Titanfall2.exe", "Titanfall2-unpacked.exe", "NorthstarLauncher.exe"]; let cmd = (() => { switch (process.platform) { case "linux": return "ps -A"; -- cgit v1.2.3 From 62249076008a49082471e87df6aef4f4a3829290 Mon Sep 17 00:00:00 2001 From: Alystrasz Date: Tue, 11 Jan 2022 16:21:12 +0100 Subject: [feat] update process is not launched if game is currently running --- src/utils.js | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/utils.js b/src/utils.js index 7256444..014c601 100644 --- a/src/utils.js +++ b/src/utils.js @@ -64,15 +64,18 @@ northstar_auto_updates: { break northstar_auto_updates; async function _checkForUpdates() { - console.log(await _isGameRunning()); - const localVersion = getNSVersion(); const distantVersion = await requests.getLatestNsVersion(); console.log('Checking for Northstar updates...'); if (localVersion !== distantVersion) { - console.log('Northstar update available! Launching update process.'); - update(); + console.log('Northstar update available!'); + if (await _isGameRunning()) { + console.log('Not installing update since game is running.'); + } else { + console.log('Launching update process.'); + update(); + } } else { console.log('No Northstar update available.') } -- cgit v1.2.3 From 2682e37420b00d3c3add4ce22209205dab0af57f Mon Sep 17 00:00:00 2001 From: Alystrasz Date: Tue, 11 Jan 2022 16:35:30 +0100 Subject: [feat] sending a notification when an update is available during game session --- src/utils.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/utils.js b/src/utils.js index 014c601..acda691 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(); @@ -72,6 +72,10 @@ northstar_auto_updates: { console.log('Northstar update available!'); if (await _isGameRunning()) { console.log('Not installing update since game is running.'); + new Notification({ + title: "Northstar update available", + body: 'An update for Northstar is available.\nYou can force its installation after closing the game.' + }).show(); } else { console.log('Launching update process.'); update(); -- cgit v1.2.3 From fe6dd267136f09bab721d3f02d43b991ac2bad3d Mon Sep 17 00:00:00 2001 From: Alystrasz Date: Tue, 11 Jan 2022 16:40:35 +0100 Subject: [refactor] adding translations for notification texts --- src/lang/en.json | 3 +++ src/lang/fr.json | 3 +++ src/utils.js | 4 ++-- 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/src/lang/en.json b/src/lang/en.json index 68d46c7..2003bee 100644 --- a/src/lang/en.json +++ b/src/lang/en.json @@ -58,6 +58,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..ec4b263 100644 --- a/src/lang/fr.json +++ b/src/lang/fr.json @@ -58,6 +58,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 acda691..95e54e0 100644 --- a/src/utils.js +++ b/src/utils.js @@ -73,8 +73,8 @@ northstar_auto_updates: { if (await _isGameRunning()) { console.log('Not installing update since game is running.'); new Notification({ - title: "Northstar update available", - body: 'An update for Northstar is available.\nYou can force its installation after closing the game.' + title: lang("gui.nsupdate.gaming.title"), + body: lang("gui.nsupdate.gaming.body") }).show(); } else { console.log('Launching update process.'); -- cgit v1.2.3 From 84c62584f03126bf23b5c2899e05359d7bfc4471 Mon Sep 17 00:00:00 2001 From: 0neGal Date: Tue, 11 Jan 2022 20:06:41 +0100 Subject: formatting, and localized logs --- src/lang/en.json | 6 ++++++ src/utils.js | 22 ++++++++++++---------- 2 files changed, 18 insertions(+), 10 deletions(-) diff --git a/src/lang/en.json b/src/lang/en.json index 2003bee..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!", diff --git a/src/utils.js b/src/utils.js index 95e54e0..87499ae 100644 --- a/src/utils.js +++ b/src/utils.js @@ -36,7 +36,7 @@ if (fs.existsSync("viper.json")) { } -async function _isGameRunning() { +async function isGameRunning() { return new Promise(resolve => { let procs = ["Titanfall2.exe", "Titanfall2-unpacked.exe", "NorthstarLauncher.exe"]; let cmd = (() => { @@ -60,28 +60,29 @@ async function _isGameRunning() { } northstar_auto_updates: { - if (!settings.autoupdate || !fs.existsSync("viper.json") || settings.gamepath.length === 0) + if (!settings.autoupdate || !fs.existsSync("viper.json") || settings.gamepath.length === 0) { break northstar_auto_updates; + } async function _checkForUpdates() { - const localVersion = getNSVersion(); - const distantVersion = await requests.getLatestNsVersion(); - console.log('Checking for Northstar updates...'); + let localVersion = getNSVersion(); + let distantVersion = await requests.getLatestNsVersion(); + console.log(lang("cli.autoupdates.checking")); if (localVersion !== distantVersion) { - console.log('Northstar update available!'); - if (await _isGameRunning()) { - console.log('Not installing update since game is running.'); + 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('Launching update process.'); + console.log(lang("cli.autoupdates.updatingns")); update(); } } else { - console.log('No Northstar update available.') + console.log(lang("cli.autoupdates.noupdate")) } setTimeout( @@ -486,6 +487,7 @@ module.exports = { updatevp, settings, getNSVersion, + isGameRunning, setlang: (lang) => { settings.lang = lang; saveSettings(); -- cgit v1.2.3 From dd2786488c445fdd8bcc62a0ad735a7715f93d57 Mon Sep 17 00:00:00 2001 From: Alystrasz Date: Tue, 11 Jan 2022 23:03:07 +0100 Subject: [feat] adding missing translations --- src/lang/fr.json | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/lang/fr.json b/src/lang/fr.json index ec4b263..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é.", -- cgit v1.2.3