From 944363c06995196f68a57997973b11eac93d7d59 Mon Sep 17 00:00:00 2001 From: Alystrasz Date: Fri, 5 Aug 2022 01:12:59 +0200 Subject: feat: handle release notes fetching with no internet When release notes (either Northstar or Viper) fetching fails, if cache contains data, we display it even if it's outdated; if cache is empty, we display an error message in place of release notes. --- src/app/launcher.js | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) (limited to 'src/app') diff --git a/src/app/launcher.js b/src/app/launcher.js index fbeb703..e1dbbe0 100644 --- a/src/app/launcher.js +++ b/src/app/launcher.js @@ -26,13 +26,17 @@ function page(page) { function formatRelease(notes) { let content = ""; - for (let release of notes) { - if (release.prerelease) {continue} - content += "# " + release.name + "\n\n" + release.body + "\n\n\n"; + if (notes.length === 1) { + content = notes[0]; + } else { + for (let release of notes) { + if (release.prerelease) {continue} + content += "# " + release.name + "\n\n" + release.body + "\n\n\n"; + } + + content = content.replaceAll(/\@(\S+)/g, `@$1`); } - content = content.replaceAll(/\@(\S+)/g, `@$1`); - return markdown(content, { breaks: true }); -- cgit v1.2.3 From 64fb444ad72bdba342a7345644a5b55d94c7f696 Mon Sep 17 00:00:00 2001 From: Alystrasz Date: Sat, 6 Aug 2022 22:47:27 +0200 Subject: feat: prevent Northstar update and update download link text if no Internet --- src/app/main.js | 1 + src/lang/en.json | 1 + src/lang/fr.json | 1 + src/utils.js | 5 +++++ 4 files changed, 8 insertions(+) (limited to 'src/app') diff --git a/src/app/main.js b/src/app/main.js index 9fb3191..4288d1d 100644 --- a/src/app/main.js +++ b/src/app/main.js @@ -122,6 +122,7 @@ ipcRenderer.on("ns-update-event", (event, key) => { console.log(lang(key)); switch(key) { case "cli.update.uptodate.short": + case "cli.update.noInternet": setButtons(true); playNsBtn.innerText = lang("gui.launch"); break; diff --git a/src/lang/en.json b/src/lang/en.json index 8cece10..9817a70 100644 --- a/src/lang/en.json +++ b/src/lang/en.json @@ -22,6 +22,7 @@ "cli.update.finished": "Installation/Update finished!", "cli.update.uptodate": "Latest version (%s) is already installed, skipping update.", "cli.update.uptodate.short": "Up-to-date", + "cli.update.noInternet": "No Internet connection", "cli.autoupdates.checking": "Checking for Northstar updates...", "cli.autoupdates.available": "Northstar update available!", diff --git a/src/lang/fr.json b/src/lang/fr.json index 1fde982..9d45e1a 100644 --- a/src/lang/fr.json +++ b/src/lang/fr.json @@ -22,6 +22,7 @@ "cli.update.finished": "Mise à jour terminée !", "cli.update.uptodate": "La dernière version (%s) est déjà installée.", "cli.update.uptodate.short": "Votre client est à jour", + "cli.update.noInternet": "Pas de connexion Internet", "cli.autoupdates.checking": "Vérifications des mises à jour de Northstar...", "cli.autoupdates.available": "Une mise à jour de Northstar est disponible !", diff --git a/src/utils.js b/src/utils.js index e8d14cc..b5978b6 100644 --- a/src/utils.js +++ b/src/utils.js @@ -155,6 +155,7 @@ function handleNorthstarUpdating() { async function _checkForUpdates() { let localVersion = getNSVersion(); let distantVersion = await requests.getLatestNsVersion(); + if (distantVersion == false) return; console.log(lang("cli.autoupdates.checking")); // Checks if NS is outdated @@ -361,6 +362,10 @@ async function update() { const latestAvailableVersion = await requests.getLatestNsVersion(); console.log(latestAvailableVersion) + if (latestAvailableVersion == false) { + ipcMain.emit("ns-update-event", "cli.update.noInternet"); + return; + } // Makes sure it is not already the latest version if (version === latestAvailableVersion) { -- cgit v1.2.3 From 26034ec3475a61682a17c95cb2bffdbc9e52af54 Mon Sep 17 00:00:00 2001 From: Alystrasz Date: Sat, 6 Aug 2022 23:13:24 +0200 Subject: feat: display a toast message if no Internet at launch --- src/app/browser.js | 11 +++++++++++ src/app/main.js | 7 ++++++- src/index.js | 1 + src/lang/en.json | 3 +++ src/lang/fr.json | 3 +++ 5 files changed, 24 insertions(+), 1 deletion(-) (limited to 'src/app') diff --git a/src/app/browser.js b/src/app/browser.js index 4b9f2e3..b1576a9 100644 --- a/src/app/browser.js +++ b/src/app/browser.js @@ -391,6 +391,17 @@ ipcRenderer.on("failed-mod", (event, modname) => { }) }) +ipcRenderer.on("no-internet", (event, modname) => { + console.log('yo') + setButtons(true); + new Toast({ + timeout: 10000, + scheme: "error", + title: lang("gui.toast.noInternet.title"), + description: lang("gui.toast.noInternet.desc") + }) +}) + ipcRenderer.on("installed-mod", (event, mod) => { setButtons(true); Browser.setbutton(mod.name, lang("gui.browser.reinstall")); diff --git a/src/app/main.js b/src/app/main.js index 4288d1d..163c63d 100644 --- a/src/app/main.js +++ b/src/app/main.js @@ -1,6 +1,6 @@ const fs = require("fs"); const path = require("path"); -const { ipcRenderer, shell } = require("electron"); +const { ipcRenderer, shell, ipcMain } = require("electron"); const lang = require("../lang"); var modsobj = {}; @@ -62,6 +62,11 @@ if (fs.existsSync("viper.json")) { setpath(); } + +// Show a toast message if no Internet connection has been detected. +if (!navigator.onLine) + ipcRenderer.send("no-internet"); + function exit() {ipcRenderer.send("exit")} function update() {ipcRenderer.send("update")} diff --git a/src/index.js b/src/index.js index 148e30a..e01a635 100644 --- a/src/index.js +++ b/src/index.js @@ -71,6 +71,7 @@ function start() { ipcMain.on("removed-mod", (event, modname) => {send("removed-mod", modname)}); ipcMain.on("gui-getmods", (event, ...args) => {send("mods", utils.mods.list())}); ipcMain.on("installed-mod", (event, modname) => {send("installed-mod", modname)}); + ipcMain.on("no-internet", () => {send("no-internet")}); // install calls ipcMain.on("install-from-path", (event, path) => {utils.mods.install(path)}); diff --git a/src/lang/en.json b/src/lang/en.json index 9817a70..d48b3b6 100644 --- a/src/lang/en.json +++ b/src/lang/en.json @@ -139,6 +139,9 @@ "gui.toast.desc.malformed": "has an incorrect folder structure, if you're the developer, you should fix this.", "gui.toast.desc.failed": "An unknown error occurred while trying to install the mod. This may be the author's fault, and it may also be Viper's fault.", + "gui.toast.noInternet.title": "No Internet", + "gui.toast.noInternet.desc": "Viper may not work properly.", + "viper.menu.main": "Viper", "viper.menu.release": "Release Notes", "viper.menu.info": "Extras", diff --git a/src/lang/fr.json b/src/lang/fr.json index 9d45e1a..cd4e4dc 100644 --- a/src/lang/fr.json +++ b/src/lang/fr.json @@ -139,6 +139,9 @@ "gui.toast.desc.malformed": "a une structure de dossier incorrecte ; si vous êtes son développeur, vous devriez réparer ça.", "gui.toast.desc.failed": "Une erreur inconnue est survenue lors de l'installation du mod. Cela peut être du ressort de l'auteur du mod ou de Viper.", + "gui.toast.noInternet.title": "Pas de connexion Internet", + "gui.toast.noInternet.desc": "Viper ne fonctionnera pas correctement tant que la connexion n'est pas rétablie.", + "viper.menu.main": "Viper", "viper.menu.release": "Notes de mises à jour", "viper.menu.info": "Informations", -- cgit v1.2.3 From f36176a3649a082c99afef552a87559632536e16 Mon Sep 17 00:00:00 2001 From: Alystrasz Date: Sun, 7 Aug 2022 21:40:27 +0200 Subject: fix: lint --- src/app/browser.js | 1 - src/app/main.js | 3 ++- src/utils.js | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) (limited to 'src/app') diff --git a/src/app/browser.js b/src/app/browser.js index b1576a9..db68d31 100644 --- a/src/app/browser.js +++ b/src/app/browser.js @@ -392,7 +392,6 @@ ipcRenderer.on("failed-mod", (event, modname) => { }) ipcRenderer.on("no-internet", (event, modname) => { - console.log('yo') setButtons(true); new Toast({ timeout: 10000, diff --git a/src/app/main.js b/src/app/main.js index 163c63d..d6a57d6 100644 --- a/src/app/main.js +++ b/src/app/main.js @@ -64,8 +64,9 @@ if (fs.existsSync("viper.json")) { // Show a toast message if no Internet connection has been detected. -if (!navigator.onLine) +if (!navigator.onLine) { ipcRenderer.send("no-internet"); +} function exit() {ipcRenderer.send("exit")} function update() {ipcRenderer.send("update")} diff --git a/src/utils.js b/src/utils.js index b5978b6..31a2b28 100644 --- a/src/utils.js +++ b/src/utils.js @@ -155,7 +155,7 @@ function handleNorthstarUpdating() { async function _checkForUpdates() { let localVersion = getNSVersion(); let distantVersion = await requests.getLatestNsVersion(); - if (distantVersion == false) return; + if (distantVersion == false) { return; } console.log(lang("cli.autoupdates.checking")); // Checks if NS is outdated -- cgit v1.2.3