From 66162ef4d101ad54badc804893c15739a252a71b Mon Sep 17 00:00:00 2001 From: 0neGal Date: Sat, 23 Apr 2022 01:01:55 +0200 Subject: prereleases no longer show up in the release notes --- src/app/launcher.js | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'src/app/launcher.js') diff --git a/src/app/launcher.js b/src/app/launcher.js index e0d7619..7b49dc4 100644 --- a/src/app/launcher.js +++ b/src/app/launcher.js @@ -25,6 +25,8 @@ ipcRenderer.on("vp-notes", (event, response) => { let content = ""; for (const release of response) { + if (release.prerelease) {continue} + content += "# " + release.name + "\n\n" + release.body.replaceAll("\r\n", "\n") + "\n\n\n"; } @@ -42,6 +44,8 @@ ipcRenderer.on("ns-notes", (event, response) => { let content = ""; for (let release of response) { + if (release.prerelease) {continue} + content += "# " + release.name + "\n\n" + release.body.replaceAll("\r\n", "\nhtmlbreak") + "\n\n\n"; } -- cgit v1.2.3 From fc88fc0af4ea3139b81378a03f337a55055a5245 Mon Sep 17 00:00:00 2001 From: 0neGal Date: Tue, 3 May 2022 14:59:11 +0200 Subject: fixes markdown not rendering properly (#108) Simplifies the parsing of Markdown, whilst also solving problems that the previous parser for Markdown caused. --- src/app/launcher.js | 39 ++++++++++++++++----------------------- 1 file changed, 16 insertions(+), 23 deletions(-) (limited to 'src/app/launcher.js') diff --git a/src/app/launcher.js b/src/app/launcher.js index 7b49dc4..ed6a513 100644 --- a/src/app/launcher.js +++ b/src/app/launcher.js @@ -19,40 +19,33 @@ function page(page) { bgHolder.setAttribute("bg", page); }; page(1) - -// Updates the Viper release notes -ipcRenderer.on("vp-notes", (event, response) => { +function formatRelease(notes) { let content = ""; - for (const release of response) { + for (let release of notes) { if (release.prerelease) {continue} - - content += "# " + release.name + "\n\n" - + release.body.replaceAll("\r\n", "\n") + "\n\n\n"; + content += "# " + release.name + "\n\n" + release.body + "\n\n\n"; } - vpReleaseNotes.innerHTML = markdown(content); -}); - -async function loadVpReleases() { - ipcRenderer.send("get-vp-notes"); -}; loadVpReleases(); + return markdown(content, { + breaks: true + }); +} +// Updates the Viper release notes +ipcRenderer.on("vp-notes", (event, response) => { + vpReleaseNotes.innerHTML = formatRelease(response); +}); // Updates the Northstar release notes ipcRenderer.on("ns-notes", (event, response) => { - let content = ""; - - for (let release of response) { - if (release.prerelease) {continue} - - content += "# " + release.name + "\n\n" - + release.body.replaceAll("\r\n", "\nhtmlbreak") + "\n\n\n"; - } - - nsRelease.innerHTML = markdown(content).replaceAll("htmlbreak", "
"); + nsRelease.innerHTML = formatRelease(response); }); +async function loadVpReleases() { + ipcRenderer.send("get-vp-notes"); +}; loadVpReleases(); + async function loadNsReleases() { ipcRenderer.send("get-ns-notes"); }; loadNsReleases(); -- cgit v1.2.3 From 5426a3182395eb0ab6bd4e02b67cef1df9af6ced Mon Sep 17 00:00:00 2001 From: 0neGal Date: Tue, 3 May 2022 15:04:14 +0200 Subject: re-implements user links in release notes (#88) Instead of updating the branch it was easier to simply add this, I don't plan to add the issue/PR support, as it's complicated with no real benefit, as NS seems to already link the PR's themselves. --- src/app/launcher.js | 2 ++ 1 file changed, 2 insertions(+) (limited to 'src/app/launcher.js') diff --git a/src/app/launcher.js b/src/app/launcher.js index ed6a513..51d3a63 100644 --- a/src/app/launcher.js +++ b/src/app/launcher.js @@ -27,6 +27,8 @@ function formatRelease(notes) { content += "# " + release.name + "\n\n" + release.body + "\n\n\n"; } + content = content.replaceAll(/\@(\S+)/g, `@$1`); + return markdown(content, { breaks: true }); -- cgit v1.2.3 From a844a146e88faa0c5f7239b5d05869868f2a2aab Mon Sep 17 00:00:00 2001 From: 0neGal Date: Sat, 28 May 2022 01:52:03 +0200 Subject: initial commit for master server status This doesn't fully implement everything as the master server is down whilst making this commit, so I can't fully implement it. --- src/app/css/launcher.css | 29 +++++++++++++++++++++++++++++ src/app/index.html | 3 ++- src/app/launcher.js | 40 ++++++++++++++++++++++++++++++++++++++++ src/lang/en.json | 4 ++++ 4 files changed, 75 insertions(+), 1 deletion(-) (limited to 'src/app/launcher.js') diff --git a/src/app/css/launcher.css b/src/app/css/launcher.css index 03812c6..ce54ddf 100644 --- a/src/app/css/launcher.css +++ b/src/app/css/launcher.css @@ -297,3 +297,32 @@ code { margin-top: calc(var(--spacing) / 2); margin-bottom: calc(var(--spacing) / 2); } + +#serverstatus { + --spacing: calc(var(--padding) / 5); + + transition-duration: 0.2s; + transition-timing-function: ease-in-out; + transition-property: background, opacity; + + opacity: 0.0; + display: block; + margin: 0 auto; + font-weight: 700; + width: fit-content; + color: transparent; + border-radius: 50px; + flex-basis: max-content; + background: transparent; + margin-top: calc(var(--spacing) * 2); + padding: var(--spacing) calc(var(--spacing) * 3); +} + +#serverstatus.up, +#serverstatus.down { + color: white; + opacity: 1.0; +} + +#serverstatus.up {background: rgb(var(--blue));} +#serverstatus.down {background: rgb(var(--red));} diff --git a/src/app/index.html b/src/app/index.html index f67a7a8..2305e4c 100644 --- a/src/app/index.html +++ b/src/app/index.html @@ -197,6 +197,7 @@ @@ -240,4 +241,4 @@ - +< diff --git a/src/app/launcher.js b/src/app/launcher.js index 51d3a63..f426775 100644 --- a/src/app/launcher.js +++ b/src/app/launcher.js @@ -1,5 +1,9 @@ const markdown = require("marked").parse; +var servercount; +var playercount; +var masterserver; + // Changes the main page // This is the tabs in the sidebar function page(page) { @@ -107,3 +111,39 @@ function showNsSection(section) { break; } } + +async function loadServers() { + serverstatus.classList.add("checking"); + + try { + let servers = await (await fetch("https://northstar.tf/client/servers/")).json(); + masterserver = true; + }catch (err) { + playercount = 0; + servercount = 0; + masterserver = false; + } + + serverstatus.classList.remove("checking"); + + if (servercount == 0) {masterserver = false} + + if (masterserver) { + serverstatus.classList.add("up"); + // servercount and playercount don't actually get set anywhere, + // the reason for this is, while writing this code, the master + // server is down so I don't have anyway to test the code... + // + // it'll be added whenever the masterserver comes online again. + serverstatus.innerHTML = `${servercount} ${lang("gui.server.servers")} - ${playercount} ${lang("gui.server.players")}`; + } else { + serverstatus.classList.add("down"); + serverstatus.innerHTML = lang("gui.server.offline"); + + } +}; loadServers() + +// Refreshes every 5 minutes +setInterval(() => { + loadServers(); +}, 300000) diff --git a/src/lang/en.json b/src/lang/en.json index 2c068ac..045517d 100644 --- a/src/lang/en.json +++ b/src/lang/en.json @@ -113,6 +113,10 @@ "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.server.servers": "servers", + "gui.server.players": "players", + "gui.server.offline": "Masterserver is Offline", + "gui.launch": "Launch", "gui.launchvanilla": "Vanilla", "gui.launchnorthstar": "Northstar", -- cgit v1.2.3 From 45bf3b862d45bd925380f9d5be68b823b6df4998 Mon Sep 17 00:00:00 2001 From: 0neGal Date: Sat, 28 May 2022 03:00:00 +0200 Subject: fully implement server+player counts --- src/app/launcher.js | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) (limited to 'src/app/launcher.js') diff --git a/src/app/launcher.js b/src/app/launcher.js index f426775..719048e 100644 --- a/src/app/launcher.js +++ b/src/app/launcher.js @@ -116,8 +116,15 @@ async function loadServers() { serverstatus.classList.add("checking"); try { - let servers = await (await fetch("https://northstar.tf/client/servers/")).json(); + let servers = await (await fetch("https://northstar.tf/client/servers")).json(); masterserver = true; + + playercount = 0; + servercount = servers.length; + + for (let i = 0; i < servers.length; i++) { + playercount += servers[i].playerCount + } }catch (err) { playercount = 0; servercount = 0; @@ -126,7 +133,7 @@ async function loadServers() { serverstatus.classList.remove("checking"); - if (servercount == 0) {masterserver = false} + if (servercount == 0 || ! servercount || ! playercount) {masterserver = false} if (masterserver) { serverstatus.classList.add("up"); -- cgit v1.2.3 From 6e7b66060e8655e013b74140b30f41f6d5ee52e8 Mon Sep 17 00:00:00 2001 From: 0neGal Date: Mon, 30 May 2022 18:15:13 +0200 Subject: support for singular players While it's unlikely we'll ever get down to 1 player, it's best to be on the safe side :p --- src/app/launcher.js | 12 ++++++------ src/lang/en.json | 3 ++- 2 files changed, 8 insertions(+), 7 deletions(-) (limited to 'src/app/launcher.js') diff --git a/src/app/launcher.js b/src/app/launcher.js index 719048e..569d0fe 100644 --- a/src/app/launcher.js +++ b/src/app/launcher.js @@ -135,14 +135,14 @@ async function loadServers() { if (servercount == 0 || ! servercount || ! playercount) {masterserver = false} + let playerstr = lang("gui.server.players"); + if (playercount == 1) { + playerstr = lang("gui.server.player"); + } + if (masterserver) { serverstatus.classList.add("up"); - // servercount and playercount don't actually get set anywhere, - // the reason for this is, while writing this code, the master - // server is down so I don't have anyway to test the code... - // - // it'll be added whenever the masterserver comes online again. - serverstatus.innerHTML = `${servercount} ${lang("gui.server.servers")} - ${playercount} ${lang("gui.server.players")}`; + serverstatus.innerHTML = `${servercount} ${lang("gui.server.servers")} - ${playercount} ${playerstr}`; } else { serverstatus.classList.add("down"); serverstatus.innerHTML = lang("gui.server.offline"); diff --git a/src/lang/en.json b/src/lang/en.json index 045517d..34c4619 100644 --- a/src/lang/en.json +++ b/src/lang/en.json @@ -113,8 +113,9 @@ "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.server.servers": "servers", + "gui.server.player": "player", "gui.server.players": "players", + "gui.server.servers": "servers", "gui.server.offline": "Masterserver is Offline", "gui.launch": "Launch", -- cgit v1.2.3 From 7ddfd200abad2de370d49f6a58862a71c148111d Mon Sep 17 00:00:00 2001 From: 0neGal Date: Mon, 30 May 2022 21:53:41 +0200 Subject: fixed missing commas and various syntax stuff I know, commas aren't needed, however, going in and out of using commas and not using them also looks bad, so generally I try to always use them, with exceptions. --- src/app/browser.js | 35 ++++++++++----------- src/app/lang.js | 2 +- src/app/launcher.js | 9 ++++-- src/app/main.js | 29 +++++++++--------- src/app/settings.js | 12 ++++---- src/extras/findgame.js | 12 ++++---- src/index.js | 62 ++++++++++++++++++-------------------- src/utils.js | 82 +++++++++++++++++++++++++------------------------- 8 files changed, 123 insertions(+), 120 deletions(-) (limited to 'src/app/launcher.js') diff --git a/src/app/browser.js b/src/app/browser.js index a292cf6..72ab24e 100644 --- a/src/app/browser.js +++ b/src/app/browser.js @@ -18,7 +18,6 @@ var Browser = { } } - console.log(other) return pkgs; }, get: () => { @@ -88,8 +87,8 @@ var Browser = { toggle: (state) => { if (state) { browser.scrollTo(0, 0); - overlay.classList.add("shown") - browser.classList.add("shown") + overlay.classList.add("shown"); + browser.classList.add("shown"); if (browserEntries.querySelectorAll(".el").length == 0) { Browser.loadfront(); @@ -98,16 +97,16 @@ var Browser = { } else if (! state) { if (state != undefined) { Browser.filters.toggle(false); - overlay.classList.remove("shown") - browser.classList.remove("shown") - preview.classList.remove("shown") + overlay.classList.remove("shown"); + browser.classList.remove("shown"); + preview.classList.remove("shown"); return } } browser.scrollTo(0, 0); - overlay.classList.toggle("shown") - browser.classList.toggle("shown") + overlay.classList.toggle("shown"); + browser.classList.toggle("shown"); }, loadfront: async () => { Browser.loading(); @@ -162,11 +161,11 @@ var Browser = { } if (pkgs.length == 0 || isEnd) { - Browser.msg(`${lang('gui.browser.endoflist')}`) + Browser.msg(`${lang('gui.browser.endoflist')}`); return } - Browser.msg(``) + Browser.msg(``); loadmore.addEventListener("click", () => { Browser.loadpkgs(pkgs); Browser.endoflist(pkgs); @@ -177,7 +176,7 @@ var Browser = { let res = fuse.search(string); if (res.length < 1) { - Browser.loading(lang("gui.browser.noresults")) + Browser.loading(lang("gui.browser.noresults")); return } @@ -244,12 +243,11 @@ var Browser = { } Browser.endoflist(); - console.log(pkgs) break } try { - new BrowserElFromObj(pkgs[i]) + new BrowserElFromObj(pkgs[i]); }catch(e) {} count++; @@ -420,10 +418,12 @@ ipcRenderer.on("installedmod", (event, mod) => { function normalize(items) { let main = (string) => { - return string.replaceAll(" ", "").replaceAll(".", "").replaceAll("-", "").replaceAll("_", "").toLowerCase() + return string.replaceAll(" ", "") + .replaceAll(".", "").replaceAll("-", "") + .replaceAll("_", "").toLowerCase(); } if (typeof items == "string") { - return main(items) + return main(items); } else { let newArray = []; for (let i = 0; i < items.length; i++) { @@ -462,7 +462,6 @@ events.forEach((event) => { let mouseAt = document.elementsFromPoint(mouseX, mouseY); if (! mouseAt.includes(document.querySelector("#filter")) && ! mouseAt.includes(document.querySelector(".overlay"))) { - console.log(mouseAt) Browser.filters.toggle(false); } }) @@ -498,5 +497,7 @@ browser.addEventListener("mousemove", (event) => { let checks = document.querySelectorAll(".check"); for (let i = 0; i < checks.length; i++) { - checks[i].setAttribute("onclick", "this.classList.toggle('checked');Browser.loadfront();search.value = ''") + checks[i].setAttribute("onclick", + "this.classList.toggle('checked');Browser.loadfront();search.value = ''" + ) } diff --git a/src/app/lang.js b/src/app/lang.js index 6fdcd8d..f1c31d3 100644 --- a/src/app/lang.js +++ b/src/app/lang.js @@ -10,7 +10,7 @@ function setlang() { if (html[i][0] != " " && html[i][html[i].length - 1] != " ") { // Replaces it with it's string - html[i] = lang(html[i]) + html[i] = lang(html[i]); } } diff --git a/src/app/launcher.js b/src/app/launcher.js index 51d3a63..e0b56db 100644 --- a/src/app/launcher.js +++ b/src/app/launcher.js @@ -3,8 +3,8 @@ const markdown = require("marked").parse; // Changes the main page // This is the tabs in the sidebar function page(page) { - let pages = document.querySelectorAll(".mainContainer .contentContainer") - let btns = document.querySelectorAll(".gamesContainer button") + let btns = document.querySelectorAll(".gamesContainer button"); + let pages = document.querySelectorAll(".mainContainer .contentContainer"); for (let i = 0; i < pages.length; i++) { pages[i].classList.add("hidden"); @@ -82,7 +82,10 @@ function showVpSection(section) { } function showNsSection(section) { - if (!["main", "release", "mods"].includes(section)) throw new Error("unknown ns section"); + if (!["main", "release", "mods"].includes(section)) { + throw new Error("unknown ns section"); + } + nsMainBtn.removeAttribute("active"); nsModsBtn.removeAttribute("active"); nsReleaseBtn.removeAttribute("active"); diff --git a/src/app/main.js b/src/app/main.js index 362450a..d132c35 100644 --- a/src/app/main.js +++ b/src/app/main.js @@ -36,9 +36,9 @@ if (fs.existsSync("viper.json")) { }catch (e) { let reset = confirm(lang("general.invalidconfig", navigator.language) + e); if (! reset) { - ipcRenderer.send("exit") + ipcRenderer.send("exit"); } else { - fs.writeFileSync("viper.json", "{}") + fs.writeFileSync("viper.json", "{}"); ipcRenderer.send("relaunch"); } @@ -100,12 +100,15 @@ function setButtons(state) { } } - disablearray(document.querySelectorAll(".playBtnContainer .playBtn")) - disablearray(document.querySelectorAll("#nsMods .buttons.modbtns button")) - disablearray(document.querySelectorAll("#browser #browserEntries .text button")) + disablearray(document.querySelectorAll(".playBtnContainer .playBtn")); + disablearray(document.querySelectorAll("#nsMods .buttons.modbtns button")); + disablearray(document.querySelectorAll("#browser #browserEntries .text button")); } -ipcRenderer.on("setbuttons", (event, state) => {setButtons(state)}) +ipcRenderer.on("setbuttons", (event, state) => { + setButtons(state); +}) + ipcRenderer.on("gamepathlost", (event, state) => { page(0); setButtons(false); @@ -172,7 +175,7 @@ function selected(all) { } } - ipcRenderer.send("removemod", selected) + ipcRenderer.send("removemod", selected); }, toggle: () => { if (selected.match(/^Northstar\./)) { @@ -185,7 +188,7 @@ function selected(all) { } } - ipcRenderer.send("togglemod", selected) + ipcRenderer.send("togglemod", selected); } } } @@ -195,19 +198,18 @@ let installqueue = []; // Tells the main process to install a mod through the file selector function installmod() { setButtons(false); - ipcRenderer.send("installmod") + ipcRenderer.send("installmod"); } // Tells the main process to directly install a mod from this path function installFromPath(path) { setButtons(false); - ipcRenderer.send("installfrompath", path) + ipcRenderer.send("installfrompath", path); } // Tells the main process to install a mod from a URL function installFromURL(url, dependencies, clearqueue) { if (clearqueue) {installqueue = []}; - console.log(installqueue) let prettydepends = []; @@ -215,7 +217,6 @@ function installFromURL(url, dependencies, clearqueue) { let newdepends = []; for (let i = 0; i < dependencies.length; i++) { let depend = dependencies[i].toLowerCase(); - console.log(depend) if (! depend.match(/northstar-northstar-.*/)) { depend = dependencies[i].replaceAll("-", "/"); let pkg = depend.split("/"); @@ -237,7 +238,7 @@ function installFromURL(url, dependencies, clearqueue) { } setButtons(false); - ipcRenderer.send("installfromurl", url, dependencies) + ipcRenderer.send("installfromurl", url, dependencies); if (dependencies) { installqueue = dependencies; @@ -355,7 +356,7 @@ document.addEventListener("drop", (e) => { event.stopPropagation(); dragUI.classList.remove("shown"); - installFromPath(event.dataTransfer.files[0].path) + installFromPath(event.dataTransfer.files[0].path); }); document.body.addEventListener("keyup", (e) => { diff --git a/src/app/settings.js b/src/app/settings.js index 23b38c9..051d6a1 100644 --- a/src/app/settings.js +++ b/src/app/settings.js @@ -3,22 +3,22 @@ var Settings = { if (state) { Settings.load(); options.scrollTo(0, 0); - overlay.classList.add("shown") - options.classList.add("shown") + overlay.classList.add("shown"); + options.classList.add("shown"); return } else if (! state) { if (state != undefined) { - overlay.classList.remove("shown") - options.classList.remove("shown") + overlay.classList.remove("shown"); + options.classList.remove("shown"); return } } Settings.load(); options.scrollTo(0, 0); - overlay.classList.toggle("shown") - options.classList.toggle("shown") + overlay.classList.toggle("shown"); + options.classList.toggle("shown"); }, apply: () => { settings = {...settings, ...Settings.get()}; diff --git a/src/extras/findgame.js b/src/extras/findgame.js index 3beca23..615c5b4 100644 --- a/src/extras/findgame.js +++ b/src/extras/findgame.js @@ -38,13 +38,13 @@ module.exports = async () => { // `.length - 1` This is because the last value is `contentstatsid` for (let i = 0; i < values.length; i++) { - let data_array = Object.values(values[i]) + let data_array = Object.values(values[i]); if (fs.existsSync(data_array[0] + "/steamapps/common/Titanfall2/Titanfall2.exe")) { - console.log("Found game in:", data_array[0]) + console.log("Found game in:", data_array[0]); return data_array[0] + "/steamapps/common/Titanfall2"; } else { - console.log("Game not in:", data_array[0]) + console.log("Game not in:", data_array[0]); } } } @@ -69,10 +69,10 @@ module.exports = async () => { if (folders.length > 0) { for (let i = 0; i < folders.length; i++) { if (! fs.existsSync(folders[i])) {continue} - console.log("Searching VDF file at:", folders[i]) + console.log("Searching VDF file at:", folders[i]); - let data = fs.readFileSync(folders[i]) - let read_vdf = readvdf(data.toString()) + let data = fs.readFileSync(folders[i]); + let read_vdf = readvdf(data.toString()); if (read_vdf) {return read_vdf} } } diff --git a/src/index.js b/src/index.js index e718ef9..259d8ad 100644 --- a/src/index.js +++ b/src/index.js @@ -3,9 +3,6 @@ const path = require("path"); const { autoUpdater } = require("electron-updater"); const { app, ipcMain, BrowserWindow, dialog } = require("electron"); -const Emitter = require("events"); -const events = new Emitter(); - const utils = require("./utils"); const cli = require("./cli"); const requests = require("./extras/requests"); @@ -16,17 +13,18 @@ function start() { win = new BrowserWindow({ width: 1000, height: 600, + title: "Viper", // Hides the window initially, it'll be shown when the DOM is // loaded, as to not cause visual issues. show: false, - title: "Viper", // In the future we may want to allow the user to resize the window, // as it's fairly responsive, but for now we won't allow that. resizable: false, - titleBarStyle: "hidden", + frame: false, + titleBarStyle: "hidden", icon: path.join(__dirname, "assets/icons/512x512.png"), webPreferences: { webviewTag: true, @@ -42,12 +40,11 @@ function start() { win.removeMenu(); win.loadFile(__dirname + "/app/index.html"); - - ipcMain.on("exit", () => {process.exit(0)}) - ipcMain.on("minimize", () => {win.minimize()}) - ipcMain.on("relaunch", () => {app.relaunch();app.exit()}) - ipcMain.on("installfrompath", (event, path) => {utils.mods.install(path)}) - ipcMain.on("installfromurl", (event, url) => {utils.mods.installFromURL(url)}) + ipcMain.on("exit", () => {process.exit(0)}); + ipcMain.on("minimize", () => {win.minimize()}); + ipcMain.on("relaunch", () => {app.relaunch();app.exit()}); + ipcMain.on("installfrompath", (event, path) => {utils.mods.install(path)}); + ipcMain.on("installfromurl", (event, url) => {utils.mods.installFromURL(url)}); ipcMain.on("winLog", (event, ...args) => {win.webContents.send("log", ...args)}); ipcMain.on("winAlert", (event, ...args) => {win.webContents.send("alert", ...args)}); ipcMain.on("ns-update-event", (event) => win.webContents.send("ns-update-event", event)); @@ -64,11 +61,11 @@ function start() { } }); - ipcMain.on("savesettings", (event, obj) => {utils.saveSettings(obj)}) + ipcMain.on("savesettings", (event, obj) => {utils.saveSettings(obj)}); - ipcMain.on("can-autoupdate", (event) => { - if (! require("electron-updater").autoUpdater.isUpdaterActive() || cli.hasParam("no-vp-updates")) { - win.webContents.send("cant-autoupdate") + ipcMain.on("can-autoupdate", () => { + if (! autoUpdater.isUpdaterActive() || cli.hasParam("no-vp-updates")) { + win.webContents.send("cant-autoupdate"); } }) @@ -87,7 +84,7 @@ function start() { } autoUpdater.on("update-downloaded", () => { - win.webContents.send("updateavailable") + win.webContents.send("updateavailable"); }); // Updates and restarts Viper, if user says yes to do so. @@ -101,7 +98,7 @@ function start() { // module inside the file that sent the event. { ipcMain.on("installmod", () => { if (cli.hasArgs()) { - utils.mods.install(cli.param("installmod")) + utils.mods.install(cli.param("installmod")); } else { dialog.showOpenDialog({properties: ["openFile"]}).then(res => { if (res.filePaths.length != 0) { @@ -109,19 +106,20 @@ ipcMain.on("installmod", () => { } else { win.webContents.send("setbuttons", true); } - }).catch(err => {console.error(err)}) + }).catch(err => {console.error(err)}); } }) -ipcMain.on("removemod", (event, mod) => {utils.mods.remove(mod)}) -ipcMain.on("togglemod", (event, mod) => {utils.mods.toggle(mod)}) +ipcMain.on("removemod", (event, mod) => {utils.mods.remove(mod)}); +ipcMain.on("togglemod", (event, mod) => {utils.mods.toggle(mod)}); + +ipcMain.on("launch", () => {utils.launch()}); +ipcMain.on("launchVanilla", () => {utils.launch("vanilla")}); -ipcMain.on("launch", (event) => {utils.launch()}) -ipcMain.on("setlang", (event, lang) => {utils.setlang(lang)}) -ipcMain.on("launchVanilla", (event) => {utils.launch("vanilla")}) +ipcMain.on("setlang", (event, lang) => {utils.setlang(lang)}); -ipcMain.on("update", (event) => {utils.update()}) -ipcMain.on("setpathcli", (event) => {utils.setpath()}); +ipcMain.on("update", () => {utils.update()}) +ipcMain.on("setpathcli", () => {utils.setpath()}); ipcMain.on("setpath", (event, value) => { if (! value) { if (! win.isVisible()) { @@ -154,19 +152,19 @@ ipcMain.on("versioncli", () => { cli.exit(); }) -ipcMain.on("getmods", (event) => { +ipcMain.on("getmods", () => { let mods = utils.mods.list(); if (mods.all.length > 0) { - console.log(`${utils.lang("general.mods.installed")} ${mods.all.length}`) - console.log(`${utils.lang("general.mods.enabled")} ${mods.enabled.length}`) + console.log(`${utils.lang("general.mods.installed")} ${mods.all.length}`); + console.log(`${utils.lang("general.mods.enabled")} ${mods.enabled.length}`); for (let i = 0; i < mods.enabled.length; i++) { - console.log(` ${mods.enabled[i].Name} ${mods.enabled[i].Version}`) + console.log(` ${mods.enabled[i].Name} ${mods.enabled[i].Version}`); } if (mods.disabled.length > 0) { - console.log(`${utils.lang("general.mods.disabled")} ${mods.disabled.length}`) + console.log(`${utils.lang("general.mods.disabled")} ${mods.disabled.length}`); for (let i = 0; i < mods.disabled.length; i++) { - console.log(` ${mods.disabled[i].Name} ${mods.disabled[i].Version}`) + console.log(` ${mods.disabled[i].Name} ${mods.disabled[i].Version}`); } } cli.exit(0); @@ -186,7 +184,7 @@ ipcMain.on("newpath", (event, newpath) => { win.show(); } } -}); ipcMain.on("wrongpath", (event) => { +}); ipcMain.on("wrongpath", () => { win.webContents.send("wrongpath"); }); diff --git a/src/utils.js b/src/utils.js index de052f5..d8e968c 100644 --- a/src/utils.js +++ b/src/utils.js @@ -129,7 +129,7 @@ function handleNorthstarUpdating() { update(); } } else { - console.log(lang("cli.autoupdates.noupdate")) + console.log(lang("cli.autoupdates.noupdate")); } setTimeout( @@ -191,7 +191,7 @@ async function setpath(win, forcedialog) { return; } - setGamepath(res.filePaths[0]) + setGamepath(res.filePaths[0]); cli.exit(); return; @@ -254,7 +254,7 @@ function restoreExcludedFiles() { for (let i = 0; i < settings.excludes.length; i++) { let exclude = path.join(settings.gamepath + "/" + settings.excludes[i]); if (fs.existsSync(exclude + ".excluded")) { - fs.renameSync(exclude + ".excluded", exclude) + fs.renameSync(exclude + ".excluded", exclude); } } } @@ -299,7 +299,7 @@ async function update() { for (let i = 0; i < settings.excludes.length; i++) { let exclude = path.join(settings.gamepath + "/" + settings.excludes[i]); if (fs.existsSync(exclude)) { - fs.renameSync(exclude, exclude + ".excluded") + fs.renameSync(exclude, exclude + ".excluded"); } } @@ -380,8 +380,8 @@ function updatevp(autoinstall) { // however it'll be added at some point. function launch(version) { if (process.platform == "linux") { - winAlert(lang("cli.launch.linuxerror")) - console.error("error:", lang("cli.launch.linuxerror")) + winAlert(lang("cli.launch.linuxerror")); + console.error("error:", lang("cli.launch.linuxerror")); cli.exit(1); return; } @@ -389,12 +389,12 @@ function launch(version) { process.chdir(settings.gamepath); switch(version) { case "vanilla": - console.log(lang("general.launching"), "Vanilla...") - run(path.join(settings.gamepath + "/Titanfall2.exe")) + console.log(lang("general.launching"), "Vanilla..."); + run(path.join(settings.gamepath + "/Titanfall2.exe")); break; default: - console.log(lang("general.launching"), "Northstar...") - run(path.join(settings.gamepath + "/NorthstarLauncher.exe")) + console.log(lang("general.launching"), "Northstar..."); + run(path.join(settings.gamepath + "/NorthstarLauncher.exe")); break; } } @@ -420,8 +420,8 @@ const mods = { let modpath = path.join(settings.gamepath, "R2Northstar/mods"); if (getNSVersion() == "unknown") { - winLog(lang("general.notinstalled")) - console.log("error: " + lang("general.notinstalled")) + winLog(lang("general.notinstalled")); + console.log("error: " + lang("general.notinstalled")); cli.exit(1); return false; } @@ -430,7 +430,7 @@ const mods = { let disabled = []; if (! fs.existsSync(modpath)) { - fs.mkdirSync(path.join(modpath), {recursive: true}) + fs.mkdirSync(path.join(modpath), {recursive: true}); return { enabled: [], disabled: [], @@ -438,7 +438,7 @@ const mods = { }; } - files = fs.readdirSync(modpath) + files = fs.readdirSync(modpath); files.forEach((file) => { if (fs.statSync(path.join(modpath, file)).isDirectory()) { let modjson = path.join(modpath, file, "mod.json"); @@ -489,8 +489,8 @@ const mods = { let modpath = path.join(settings.gamepath, "R2Northstar/mods"); if (getNSVersion() == "unknown") { - winLog(lang("general.notinstalled")) - console.log("error: " + lang("general.notinstalled")) + winLog(lang("general.notinstalled")); + console.log("error: " + lang("general.notinstalled")); cli.exit(1); return false; } @@ -515,11 +515,11 @@ const mods = { let file = path.join(modpath, "..", "enabledmods.json"); if (! fs.existsSync(modpath)) { - fs.mkdirSync(path.join(modpath), {recursive: true}) + fs.mkdirSync(path.join(modpath), {recursive: true}); } if (! fs.existsSync(file)) { - fs.writeFileSync(file, "{}") + fs.writeFileSync(file, "{}"); } return { @@ -530,7 +530,7 @@ const mods = { names[list[i].Name] = true } - fs.writeFileSync(file, JSON.stringify(names)) + fs.writeFileSync(file, JSON.stringify(names)); }, disable: (mod) => { let data = JSON.parse(repair(fs.readFileSync(file, "utf8"))); @@ -576,15 +576,15 @@ const mods = { let modname = mod.replace(/^.*(\\|\/|\:)/, ""); if (getNSVersion() == "unknown") { - winLog(lang("general.notinstalled")) - console.log("error: " + lang("general.notinstalled")) + winLog(lang("general.notinstalled")); + console.log("error: " + lang("general.notinstalled")); cli.exit(1); return false; } let notamod = () => { - winLog(lang("gui.mods.notamod")) - console.log("error: " + lang("cli.mods.notamod")) + winLog(lang("gui.mods.notamod")); + console.log("error: " + lang("cli.mods.notamod")); cli.exit(1); return false; } @@ -593,10 +593,10 @@ const mods = { console.log(lang("cli.mods.installed")); cli.exit(); - winLog(lang("gui.mods.installedmod")) + winLog(lang("gui.mods.installedmod")); if (modname == "mods") { - let manifest = path.join(app.getPath("userData"), "Archives/manifest.json") + let manifest = path.join(app.getPath("userData"), "Archives/manifest.json"); if (fs.existsSync(manifest)) { modname = require(manifest).name; @@ -614,7 +614,7 @@ const mods = { if (! fs.existsSync(mod)) {return notamod()} if (fs.statSync(mod).isDirectory()) { - winLog(lang("gui.mods.installing")) + winLog(lang("gui.mods.installing")); files = fs.readdirSync(mod); if (fs.existsSync(path.join(mod, "mod.json")) && fs.statSync(path.join(mod, "mod.json")).isFile()) { @@ -624,8 +624,8 @@ const mods = { } let copydest = path.join(modpath, modname); if (typeof destname == "string") {copydest = path.join(modpath, destname)} - copy(mod, copydest) - copy(manifestfile, path.join(copydest, "manifest.json")) + copy(mod, copydest); + copy(manifestfile, path.join(copydest, "manifest.json")); return installed(); } else { @@ -636,7 +636,7 @@ const mods = { if (fs.existsSync(path.join(mod, files[i], "mod.json")) && fs.statSync(path.join(mod, files[i], "mod.json")).isFile()) { - mods.install(path.join(mod, files[i])) + mods.install(path.join(mod, files[i])); if (mods.install(path.join(mod, files[i]))) {return true}; } } @@ -647,7 +647,7 @@ const mods = { return notamod(); } else { - winLog(lang("gui.mods.extracting")) + winLog(lang("gui.mods.extracting")); let cache = path.join(app.getPath("userData"), "Archives"); if (fs.existsSync(cache)) { fs.rmSync(cache, {recursive: true}); @@ -710,12 +710,12 @@ const mods = { if (fs.existsSync(tmp)) { if (! fs.statSync(tmp).isDirectory()) { - fs.rmSync(tmp) + fs.rmSync(tmp); } } else { - fs.mkdirSync(tmp) + fs.mkdirSync(tmp); if (fs.existsSync(modlocation)) { - fs.rmSync(modlocation) + fs.rmSync(modlocation); } } @@ -737,8 +737,8 @@ const mods = { let modpath = path.join(settings.gamepath, "R2Northstar/mods"); if (getNSVersion() == "unknown") { - winLog(lang("general.notinstalled")) - console.log("error: " + lang("general.notinstalled")) + winLog(lang("general.notinstalled")); + console.log("error: " + lang("general.notinstalled")); cli.exit(1); return false; } @@ -746,19 +746,19 @@ const mods = { if (mod == "allmods") { let modlist = mods.list().all; for (let i = 0; i < modlist.length; i++) { - mods.remove(modlist[i].Name) + mods.remove(modlist[i].Name); } return } let disabled = path.join(modpath, "disabled"); if (! fs.existsSync(disabled)) { - fs.mkdirSync(disabled) + fs.mkdirSync(disabled); } let modName = mods.get(mod).FolderName; if (! modName) { - console.log("error: " + lang("cli.mods.cantfind")) + console.log("error: " + lang("cli.mods.cantfind")); cli.exit(1); return; } @@ -796,8 +796,8 @@ const mods = { // function. However we currently have no need for that. toggle: (mod, fork) => { if (getNSVersion() == "unknown") { - winLog(lang("general.notinstalled")) - console.log("error: " + lang("general.notinstalled")) + winLog(lang("general.notinstalled")); + console.log("error: " + lang("general.notinstalled")); cli.exit(1); return false; } @@ -805,7 +805,7 @@ const mods = { if (mod == "allmods") { let modlist = mods.list().all; for (let i = 0; i < modlist.length; i++) { - mods.toggle(modlist[i].Name, true) + mods.toggle(modlist[i].Name, true); } console.log(lang("cli.mods.toggledall")); -- cgit v1.2.3 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 +++++++++----- src/extras/requests.js | 28 ++++++++++++++++++++++++++++ 2 files changed, 37 insertions(+), 5 deletions(-) (limited to 'src/app/launcher.js') 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 }); diff --git a/src/extras/requests.js b/src/extras/requests.js index 16b1330..c609da3 100644 --- a/src/extras/requests.js +++ b/src/extras/requests.js @@ -103,6 +103,20 @@ async function getNsReleaseNotes() { _saveCache(cache); resolve( cache[NORTHSTAR_RELEASE_NOTES_KEY]["body"] ); }); + }) + + // When GitHub cannot be reached (when user doesn't have Internet + // access for instance), we return latest cache content even if + // it's not up-to-date, or display an error message if cache + // is empty. + .on('error', () => { + if ( cache[NORTHSTAR_RELEASE_NOTES_KEY] ) { + console.warn("Couldn't fetch Northstar release notes, returning data from cache."); + resolve( cache[NORTHSTAR_RELEASE_NOTES_KEY]["body"] ); + } else { + console.error("Couldn't fetch Northstar release notes, cache is empty."); + resolve( ["Couldn't fetch Northstar release notes.\nTry again later!"] ); + } }); } }); @@ -140,6 +154,20 @@ async function getVpReleaseNotes() { _saveCache(cache); resolve( cache[VIPER_RELEASE_NOTES_KEY]["body"] ); }); + }) + + // When GitHub cannot be reached (when user doesn't have Internet + // access for instance), we return latest cache content even if + // it's not up-to-date, or display an error message if cache + // is empty. + .on('error', () => { + if ( cache[VIPER_RELEASE_NOTES_KEY] ) { + console.warn("Couldn't fetch Viper release notes, returning data from cache."); + resolve( cache[VIPER_RELEASE_NOTES_KEY]["body"] ); + } else { + console.error("Couldn't fetch Viper release notes, cache is empty."); + resolve( ["Couldn't fetch Viper release notes.\nTry again later!"] ); + } }); } }); -- cgit v1.2.3