aboutsummaryrefslogtreecommitdiff
path: root/src/app/launcher.js
diff options
context:
space:
mode:
Diffstat (limited to 'src/app/launcher.js')
-rw-r--r--src/app/launcher.js99
1 files changed, 76 insertions, 23 deletions
diff --git a/src/app/launcher.js b/src/app/launcher.js
index e0d7619..e1dbbe0 100644
--- a/src/app/launcher.js
+++ b/src/app/launcher.js
@@ -1,10 +1,14 @@
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) {
- 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");
@@ -19,36 +23,39 @@ 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) {
- content += "# " + release.name + "\n\n"
- + release.body.replaceAll("\r\n", "\n") + "\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, `<a href="https://github.com/$1">@$1</a>`);
}
- 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) {
- content += "# " + release.name + "\n\n"
- + release.body.replaceAll("\r\n", "\nhtmlbreak") + "\n\n\n";
- }
-
- nsRelease.innerHTML = markdown(content).replaceAll("htmlbreak", "<br>");
+ nsRelease.innerHTML = formatRelease(response);
});
+async function loadVpReleases() {
+ ipcRenderer.send("get-vp-notes");
+}; loadVpReleases();
+
async function loadNsReleases() {
ipcRenderer.send("get-ns-notes");
}; loadNsReleases();
@@ -83,7 +90,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");
@@ -108,3 +118,46 @@ 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;
+
+ playercount = 0;
+ servercount = servers.length;
+
+ for (let i = 0; i < servers.length; i++) {
+ playercount += servers[i].playerCount
+ }
+ }catch (err) {
+ playercount = 0;
+ servercount = 0;
+ masterserver = false;
+ }
+
+ serverstatus.classList.remove("checking");
+
+ 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");
+ serverstatus.innerHTML = `${servercount} ${lang("gui.server.servers")} - ${playercount} ${playerstr}`;
+ } else {
+ serverstatus.classList.add("down");
+ serverstatus.innerHTML = lang("gui.server.offline");
+
+ }
+}; loadServers()
+
+// Refreshes every 5 minutes
+setInterval(() => {
+ loadServers();
+}, 300000)