From 0577977182e7f4be2722f54ae50ff23aa8fe9032 Mon Sep 17 00:00:00 2001 From: 0neGal Date: Sat, 8 Jun 2024 18:36:27 +0200 Subject: convert js/launcher.js to a CommonJS module --- src/app/index.html | 19 +++++++++---------- src/app/js/gamepath.js | 3 ++- src/app/js/launcher.js | 40 ++++++++++++++++++++++------------------ src/app/main.js | 1 + 4 files changed, 34 insertions(+), 29 deletions(-) diff --git a/src/app/index.html b/src/app/index.html index 5d5f0fc..d6df23e 100644 --- a/src/app/index.html +++ b/src/app/index.html @@ -230,17 +230,17 @@
    -
  • %%viper.menu.main%%
  • -
  • %%viper.menu.release%%
  • -
  • %%viper.menu.info%%
  • +
  • %%viper.menu.main%%
  • +
  • %%viper.menu.release%%
  • +
  • %%viper.menu.info%%
@@ -269,9 +269,9 @@
    -
  • %%ns.menu.main%%
  • -
  • %%ns.menu.mods%%
  • -
  • %%ns.menu.release%%
  • +
  • %%ns.menu.main%%
  • +
  • %%ns.menu.mods%%
  • +
  • %%ns.menu.release%%
@@ -336,6 +336,5 @@ - diff --git a/src/app/js/gamepath.js b/src/app/js/gamepath.js index 80e3158..c3e5c2b 100644 --- a/src/app/js/gamepath.js +++ b/src/app/js/gamepath.js @@ -2,6 +2,7 @@ const ipcRenderer = require("electron").ipcRenderer; const lang = require("../../lang"); const process = require("./process"); +const launcher = require("./launcher"); const settings = require("./settings"); // frontend part of settings a new game path @@ -16,7 +17,7 @@ ipcRenderer.on("newpath", (_, newpath) => { // a previously valid gamepath no longer exists, and is therefore lost ipcRenderer.on("gamepath-lost", () => { - page(0); + launcher.change_page(0); set_buttons(false, true); alert(lang("gui.gamepath.lost")); }) diff --git a/src/app/js/launcher.js b/src/app/js/launcher.js index 6fe1686..913762b 100644 --- a/src/app/js/launcher.js +++ b/src/app/js/launcher.js @@ -1,11 +1,13 @@ const markdown = require("marked").parse; +let launcher = {}; + var servercount; var playercount; var masterserver; // changes the main page, this is the tabs in the sidebar -function page(page) { +launcher.change_page = (page) => { let btns = document.querySelectorAll(".gamesContainer button"); let pages = document.querySelectorAll(".mainContainer .contentContainer"); @@ -20,9 +22,9 @@ function page(page) { pages[page].classList.remove("hidden"); btns[page].classList.remove("inactive"); bgHolder.setAttribute("bg", page); -}; page(1) +}; launcher.change_page(1) -function formatRelease(notes) { +launcher.format_release = (notes) => { if (! notes) {return ""} let content = ""; @@ -61,7 +63,7 @@ function formatRelease(notes) { // sets content of `div` to a single release block with centered text // inside it, the text being `lang(lang_key)` -let set_error_content = (div, lang_key) => { +launcher.error = (div, lang_key) => { div.innerHTML = "
" + "

" + @@ -73,39 +75,39 @@ let set_error_content = (div, lang_key) => { // updates the Viper release notes ipcRenderer.on("vp-notes", (event, response) => { if (! response) { - return set_error_content( + return launcher.error( vpReleaseNotes, "request.no_vp_release_notes" ) } - vpReleaseNotes.innerHTML = formatRelease(response); + vpReleaseNotes.innerHTML = launcher.format_release(response); }); // updates the Northstar release notes ipcRenderer.on("ns-notes", (event, response) => { if (! response) { - return set_error_content( + return launcher.error( nsRelease, "request.no_ns_release_notes" ) } - nsRelease.innerHTML = formatRelease(response); + nsRelease.innerHTML = launcher.format_release(response); }); -async function loadVpReleases() { +launcher.load_vp_notes = async () => { ipcRenderer.send("get-vp-notes"); -}; loadVpReleases(); +}; launcher.load_vp_notes(); -async function loadNsReleases() { +launcher.load_ns_notes = async () => { ipcRenderer.send("get-ns-notes"); -}; loadNsReleases(); +}; launcher.load_ns_notes(); // TODO: We gotta make this more automatic instead of switch statements // it's both not pretty, but adding more sections requires way too much // effort, compared to how it should be. -function showVpSection(section) { +launcher.show_vp = (section) => { if (!["main", "release", "info", "credits"].includes(section)) throw new Error("unknown vp section"); vpMainBtn.removeAttribute("active"); vpReleaseBtn.removeAttribute("active"); @@ -131,8 +133,8 @@ function showVpSection(section) { } } -function showNsSection(section) { - if (!["main", "release", "mods"].includes(section)) { +launcher.show_ns = (section) => { + if (! ["main", "release", "mods"].includes(section)) { throw new Error("unknown ns section"); } @@ -161,7 +163,7 @@ function showNsSection(section) { } } -async function loadServers() { +launcher.check_servers = async () => { serverstatus.classList.add("checking"); try { @@ -205,9 +207,11 @@ async function loadServers() { serverstatus.innerHTML = lang("gui.server.offline"); } -}; loadServers() +}; launcher.check_servers() // refreshes every 5 minutes setInterval(() => { - loadServers(); + launcher.check_servers(); }, 300000) + +module.exports = launcher; diff --git a/src/app/main.js b/src/app/main.js index 9ad6344..b72c1f9 100644 --- a/src/app/main.js +++ b/src/app/main.js @@ -37,6 +37,7 @@ const request = require("./js/request"); const process = require("./js/process"); const settings = require("./js/settings"); const gamepath = require("./js/gamepath"); +const launcher = require("./js/launcher"); const is_running = require("./js/is_running"); const set_buttons = require("./js/set_buttons"); -- cgit v1.2.3