diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/app/main.js | 7 | ||||
-rw-r--r-- | src/cli.js | 2 | ||||
-rw-r--r-- | src/index.js | 18 | ||||
-rw-r--r-- | src/lang/en.json | 2 | ||||
-rw-r--r-- | src/lang/fr.json | 2 | ||||
-rw-r--r-- | src/utils.js | 17 |
6 files changed, 47 insertions, 1 deletions
diff --git a/src/app/main.js b/src/app/main.js index a33ef72..d30489e 100644 --- a/src/app/main.js +++ b/src/app/main.js @@ -6,6 +6,7 @@ const lang = require("../lang"); var settings = { gamepath: "", + autoupdate: true, zip: "/northstar.zip", lang: navigator.language, excludes: [ @@ -58,6 +59,12 @@ ipcRenderer.on("version", (event, versions) => { nsversion.innerText = lang("gui.versions.northstar") + ": " + versions.ns; }); ipcRenderer.send("getversion"); +ipcRenderer.on("updateavailable", () => { + if (confirm(lang("gui.update.available"))) { + ipcRenderer.send("updatenow"); + } +}) + setlang(); setInterval(() => { ipcRenderer.send("setsize", document.querySelector(".lines").offsetHeight + 20); @@ -14,6 +14,7 @@ function hasArgs() { cli.hasSwitch("launch") || cli.hasSwitch("setpath") || cli.hasSwitch("version") || + cli.hasSwitch("updatevp") || cli.hasSwitch("gamepath")) { return true; } else {return false} @@ -32,6 +33,7 @@ async function init() { --cli ${lang("cli.help.cli")} --update ${lang("cli.help.update")} + --updatevp ${lang("cli.help.updatevp")} --setpath ${lang("cli.help.setpath")}`) // In the future --setpath should be able to understand // relative paths, instead of just absolute ones. diff --git a/src/index.js b/src/index.js index 198bc74..b43611d 100644 --- a/src/index.js +++ b/src/index.js @@ -1,5 +1,6 @@ const fs = require("fs"); const path = require("path"); +const { autoUpdater } = require("electron-updater"); const { app, dialog, ipcMain, BrowserWindow, ipcRenderer } = require("electron"); const Emitter = require("events"); @@ -41,6 +42,17 @@ function start() { ipcMain.on("ns-updated", () => {win.webContents.send("ns-updated")}) ipcMain.on("ns-updating", () => {win.webContents.send("ns-updating")}) ipcMain.on("winLog", (event, ...args) => {win.webContents.send("log", ...args)}) + + if (utils.settings.autoupdate) {utils.updatevp(false)} + + autoUpdater.on("update-downloaded", () => { + win.webContents.send("updateavailable") + }); + + ipcMain.on("updatenow", () => { + autoUpdater.quitAndInstall(); + }) + } ipcMain.on("launch", (event) => {utils.launch()}) @@ -68,7 +80,11 @@ ipcMain.on("versioncli", () => { process.chdir(app.getPath("appData")); if (cli.hasArgs()) { - cli.init(); + if (cli.hasParam("updatevp")) { + utils.updatevp(true); + } else { + cli.init(); + } } else { app.on("ready", () => { app.setPath("userData", path.join(app.getPath("cache"), app.name)); diff --git a/src/lang/en.json b/src/lang/en.json index 8f388ae..83f23f3 100644 --- a/src/lang/en.json +++ b/src/lang/en.json @@ -5,6 +5,7 @@ "cli.help.cli": "forces the CLI to enable", "cli.help.update": "updates Northstar from your set game path", "cli.help.setpath": "sets your game path", + "cli.help.updatevp": "updates Viper itself, if supported.", "cli.setpath.noarg": "No argument provided for --setpath", @@ -28,6 +29,7 @@ "gui.update.extracting": "Extracting update...", "gui.update.finished": "Done! Ready to play!", "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.launch": "Launch", "gui.launchvanilla": "Vanilla", diff --git a/src/lang/fr.json b/src/lang/fr.json index 26648c4..fe4d63c 100644 --- a/src/lang/fr.json +++ b/src/lang/fr.json @@ -5,6 +5,7 @@ "cli.help.cli": "force l'activation de la CLI", "cli.help.update": "met à jour Northstar sur le chemin du jeu précisé", "cli.help.setpath": "enregistre le chemin du client de jeu", + "cli.help.updatevp": "met à jour le client Viper, si le format actuel le permet.", "cli.setpath.noarg": "Aucun argument donné à --setpath", @@ -28,6 +29,7 @@ "gui.update.extracting": "Extraction des fichiers...", "gui.update.finished": "Terminé, vous pouvez jouer !", "gui.update.uptodate": "Déjà à jour !", + "gui.update.available": "Une mise à jour pour Viper est disponible, voulez-vous l'installer maintenant ?", "gui.launch": "Jouer", "gui.launchvanilla": "Vanilla", diff --git a/src/utils.js b/src/utils.js index 06acbdf..9e6154a 100644 --- a/src/utils.js +++ b/src/utils.js @@ -18,6 +18,7 @@ process.chdir(app.getPath("appData")); var settings = { gamepath: "", lang: "en-US", + autoupdate: true, zip: "/northstar.zip", excludes: [ "ns_startup_args.txt", @@ -125,6 +126,21 @@ function update() { }) } +function updatevp(autoinstall) { + const { autoUpdater } = require("electron-updater"); + + if (autoinstall) { + autoUpdater.on("update-downloaded", (info) => { + autoUpdater.quitAndInstall(); + }); + } + + autoUpdater.on("error", (info) => {cli.exit(1)}); + autoUpdater.on("update-not-available", (info) => {cli.exit()}); + + autoUpdater.checkForUpdatesAndNotify(); +} + function launch(version) { if (process.platform == "linux") { console.error("error:", lang("cli.launch.linuxerror")) @@ -153,6 +169,7 @@ module.exports = { launch, update, setpath, + updatevp, settings, getNSVersion, setlang: (lang) => { |