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/main.js | 29 +++++++++++++++-------------- 1 file changed, 15 insertions(+), 14 deletions(-) (limited to 'src/app/main.js') 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) => { -- cgit v1.2.3 From 1c06ab53f1cf2228e1034a66538f3a31a14e3743 Mon Sep 17 00:00:00 2001 From: 0neGal Date: Mon, 30 May 2022 22:48:39 +0200 Subject: refactored event names Quite a lot of them aren't in the same syntax/style, and it's quite bad to look at, this should fix them all without causing issues. --- src/app/browser.js | 6 +++--- src/app/main.js | 30 ++++++++++++++--------------- src/app/settings.js | 2 +- src/index.js | 54 +++++++++++++++++++++++++++-------------------------- src/utils.js | 26 +++++++++++++------------- 5 files changed, 60 insertions(+), 58 deletions(-) (limited to 'src/app/main.js') diff --git a/src/app/browser.js b/src/app/browser.js index 72ab24e..4b9f2e3 100644 --- a/src/app/browser.js +++ b/src/app/browser.js @@ -373,7 +373,7 @@ function BrowserEl(properties) { browserEntries.appendChild(entry); } -ipcRenderer.on("removedmod", (event, mod) => { +ipcRenderer.on("removed-mod", (event, mod) => { setButtons(true); Browser.setbutton(mod.name, lang("gui.browser.install")); if (mod.manifestname) { @@ -381,7 +381,7 @@ ipcRenderer.on("removedmod", (event, mod) => { } }) -ipcRenderer.on("failedmod", (event, modname) => { +ipcRenderer.on("failed-mod", (event, modname) => { setButtons(true); new Toast({ timeout: 10000, @@ -391,7 +391,7 @@ ipcRenderer.on("failedmod", (event, modname) => { }) }) -ipcRenderer.on("installedmod", (event, mod) => { +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 d132c35..647e5cd 100644 --- a/src/app/main.js +++ b/src/app/main.js @@ -76,12 +76,12 @@ function launch() { update(); shouldInstallNorthstar = false; } else { - ipcRenderer.send("launch"); + ipcRenderer.send("launch-ns"); } } // Tells the main process to launch the vanilla game -function launchVanilla() {ipcRenderer.send("launchVanilla")} +function launchVanilla() {ipcRenderer.send("launch-vanilla")} // In conjunction with utils.js' winLog(), it'll send log messages in // the devTools from utils.js @@ -105,11 +105,11 @@ function setButtons(state) { disablearray(document.querySelectorAll("#browser #browserEntries .text button")); } -ipcRenderer.on("setbuttons", (event, state) => { +ipcRenderer.on("set-buttons", (event, state) => { setButtons(state); }) -ipcRenderer.on("gamepathlost", (event, state) => { +ipcRenderer.on("gamepath-lost", (event, state) => { page(0); setButtons(false); alert(lang("gui.gamepath.lost")); @@ -175,7 +175,7 @@ function selected(all) { } } - ipcRenderer.send("removemod", selected); + ipcRenderer.send("remove-mod", selected); }, toggle: () => { if (selected.match(/^Northstar\./)) { @@ -188,7 +188,7 @@ function selected(all) { } } - ipcRenderer.send("togglemod", selected); + ipcRenderer.send("toggle-mod", selected); } } } @@ -198,13 +198,13 @@ let installqueue = []; // Tells the main process to install a mod through the file selector function installmod() { setButtons(false); - ipcRenderer.send("installmod"); + ipcRenderer.send("install-mod"); } // Tells the main process to directly install a mod from this path function installFromPath(path) { setButtons(false); - ipcRenderer.send("installfrompath", path); + ipcRenderer.send("install-from-path", path); } // Tells the main process to install a mod from a URL @@ -238,7 +238,7 @@ function installFromURL(url, dependencies, clearqueue) { } setButtons(false); - ipcRenderer.send("installfromurl", url, dependencies); + ipcRenderer.send("install-from-url", url, dependencies); if (dependencies) { installqueue = dependencies; @@ -263,7 +263,7 @@ function isModInstalled(modname) { // Frontend part of settings a new game path ipcRenderer.on("newpath", (event, newpath) => { settings.gamepath = newpath; - ipcRenderer.send("guigetmods"); + ipcRenderer.send("gui-getmods"); }) // Continuation of log() @@ -311,23 +311,23 @@ ipcRenderer.on("version", (event, versions) => { shouldInstallNorthstar = true; playNsBtn.innerText = lang("gui.installnorthstar"); } -}); ipcRenderer.send("getversion"); +}); ipcRenderer.send("get-version"); // When an update is available it'll ask the user about it -ipcRenderer.on("updateavailable", () => { +ipcRenderer.on("update-available", () => { if (confirm(lang("gui.update.available"))) { - ipcRenderer.send("updatenow"); + ipcRenderer.send("update-now"); } }) // Error out when no game path is set -ipcRenderer.on("nopathselected", () => { +ipcRenderer.on("no-path-selected", () => { alert(lang("gui.gamepath.must")); exit(); }); // Error out when game path is wrong -ipcRenderer.on("wrongpath", () => { +ipcRenderer.on("wrong-path", () => { alert(lang("gui.gamepath.wrong")); setpath(false); }); diff --git a/src/app/settings.js b/src/app/settings.js index 051d6a1..63b4b99 100644 --- a/src/app/settings.js +++ b/src/app/settings.js @@ -22,7 +22,7 @@ var Settings = { }, apply: () => { settings = {...settings, ...Settings.get()}; - ipcRenderer.send("savesettings", Settings.get()); + ipcRenderer.send("save-settings", Settings.get()); }, reloadSwitches: () => { let switches = document.querySelectorAll(".switch"); diff --git a/src/index.js b/src/index.js index 37ea11e..96976b7 100644 --- a/src/index.js +++ b/src/index.js @@ -51,18 +51,18 @@ function start() { ipcMain.on("relaunch", () => {app.relaunch();app.exit()}); // passthrough to renderer from main - ipcMain.on("winLog", (event, ...args) => {send("log", ...args)}); - ipcMain.on("winAlert", (event, ...args) => {send("alert", ...args)}); + ipcMain.on("win-log", (event, ...args) => {send("log", ...args)}); + ipcMain.on("win-alert", (event, ...args) => {send("alert", ...args)}); // mod states - ipcMain.on("failedmod", (event, modname) => {send("failedmod", modname)}); - ipcMain.on("removedmod", (event, modname) => {send("removedmod", modname)}); - ipcMain.on("guigetmods", (event, ...args) => {send("mods", utils.mods.list())}); - ipcMain.on("installedmod", (event, modname) => {send("installedmod", modname)}); + ipcMain.on("failed-mod", (event, modname) => {send("failed-mod", modname)}); + 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)}); // install calls - ipcMain.on("installfrompath", (event, path) => {utils.mods.install(path)}); - ipcMain.on("installfromurl", (event, url) => {utils.mods.installFromURL(url)}); + ipcMain.on("install-from-path", (event, path) => {utils.mods.install(path)}); + ipcMain.on("install-from-url", (event, url) => {utils.mods.installFromURL(url)}); win.webContents.on("dom-ready", () => { send("mods", utils.mods.list()); @@ -70,14 +70,14 @@ function start() { // ensures gamepath still exists and is valid on startup let gamepathlost = false; - ipcMain.on("gamepathlost", (event, ...args) => { + ipcMain.on("gamepath-lost", (event, ...args) => { if (! gamepathlost) { gamepathlost = true; - send("gamepathlost"); + send("gamepath-lost"); } }); - ipcMain.on("savesettings", (event, obj) => {utils.saveSettings(obj)}); + ipcMain.on("save-settings", (event, obj) => {utils.saveSettings(obj)}); // allows renderer to check for updates ipcMain.on("ns-update-event", (event) => {send("ns-update-event", event)}); @@ -99,19 +99,19 @@ function start() { } autoUpdater.on("update-downloaded", () => { - send("updateavailable"); + send("update-available"); }); // updates and restarts Viper, if user says yes to do so. // otherwise it'll do it on the next start up. - ipcMain.on("updatenow", () => { + ipcMain.on("update-now", () => { autoUpdater.quitAndInstall(); }) } // General events used to handle utils.js stuff without requiring the // module inside the file that sent the event. { -ipcMain.on("installmod", () => { +ipcMain.on("install-mod", () => { if (cli.hasArgs()) { utils.mods.install(cli.param("installmod")); } else { @@ -119,22 +119,22 @@ ipcMain.on("installmod", () => { if (res.filePaths.length != 0) { utils.mods.install(res.filePaths[0]); } else { - send("setbuttons", true); + send("set-buttons", true); } }).catch(err => {error(err)}); } }) -ipcMain.on("removemod", (event, mod) => {utils.mods.remove(mod)}); -ipcMain.on("togglemod", (event, mod) => {utils.mods.toggle(mod)}); +ipcMain.on("remove-mod", (event, mod) => {utils.mods.remove(mod)}); +ipcMain.on("toggle-mod", (event, mod) => {utils.mods.toggle(mod)}); -ipcMain.on("launch", () => {utils.launch()}); -ipcMain.on("launchVanilla", () => {utils.launch("vanilla")}); +ipcMain.on("launch-ns", () => {utils.launch()}); +ipcMain.on("launch-vanilla", () => {utils.launch("vanilla")}); ipcMain.on("setlang", (event, lang) => {utils.setlang(lang)}); ipcMain.on("update", () => {utils.update()}) -ipcMain.on("setpathcli", () => {utils.setpath()}); +ipcMain.on("setpath-cli", () => {utils.setpath()}); ipcMain.on("setpath", (event, value) => { if (! value) { if (! win.isVisible()) { @@ -157,10 +157,10 @@ function sendVersionsInfo() { } // sends the version info back to the renderer -ipcMain.on("getversion", () => {sendVersionsInfo()}); +ipcMain.on("get-version", () => {sendVersionsInfo()}); // prints out version info for the CLI -ipcMain.on("versioncli", () => { +ipcMain.on("version-cli", () => { log("Viper: v" + require("../package.json").version); log("Northstar: " + utils.getNSVersion()); log("Node: " + process.version); @@ -168,6 +168,7 @@ ipcMain.on("versioncli", () => { cli.exit(); }) +// sends installed mods info to renderer ipcMain.on("getmods", () => { let mods = utils.mods.list(); if (mods.all.length > 0) { @@ -191,17 +192,18 @@ ipcMain.on("getmods", () => { }) // } +// allows renderer to set a new renderer ipcMain.on("newpath", (event, newpath) => { - if (newpath === false && !win.isVisible()) { - win.send("nopathselected"); + if (newpath === false && ! win.isVisible()) { + win.send("no-path-selected"); } else { _sendVersionsInfo(); if (!win.isVisible()) { win.show(); } } -}); ipcMain.on("wrongpath", () => { - win.send("wrongpath"); +}); ipcMain.on("wrong-path", () => { + win.send("wrong-path"); }); // ensures PWD/CWD is the config folder where viper.json is located diff --git a/src/utils.js b/src/utils.js index d8e968c..b69a9a2 100644 --- a/src/utils.js +++ b/src/utils.js @@ -42,12 +42,12 @@ var settings = { // Logs into the dev tools of the renderer function winLog(msg) { - ipcMain.emit("winLog", msg, msg); + ipcMain.emit("win-log", msg, msg); } // Sends an alert to the renderer function winAlert(msg) { - ipcMain.emit("winAlert", msg, msg); + ipcMain.emit("win-alert", msg, msg); } // Creates the settings file with the base settings if it doesn't exist. @@ -187,7 +187,7 @@ async function setpath(win, forcedialog) { return; } if (! fs.existsSync(path.join(res.filePaths[0], "Titanfall2.exe"))) { - ipcMain.emit("wrongpath"); + ipcMain.emit("wrong-path"); return; } @@ -326,11 +326,11 @@ async function update() { fs.createReadStream(settings.zip).pipe(unzip.Extract({path: settings.gamepath})) .on("finish", () => { fs.writeFileSync(path.join(settings.gamepath, "ns_version.txt"), latestAvailableVersion); - ipcMain.emit("getversion"); + ipcMain.emit("get-version"); restoreExcludedFiles(); - ipcMain.emit("guigetmods"); + ipcMain.emit("gui-getmods"); ipcMain.emit("ns-update-event", "cli.update.uptodate.short"); winLog(lang("gui.update.finished")); console.log(lang("cli.update.finished")); @@ -603,11 +603,11 @@ const mods = { } } - ipcMain.emit("installedmod", "", { + ipcMain.emit("installed-mod", "", { name: modname, malformed: malformed, }); - ipcMain.emit("guigetmods"); + ipcMain.emit("gui-getmods"); return true; } @@ -679,7 +679,7 @@ const mods = { } if (files.length == 0) { - ipcMain.emit("failedmod"); + ipcMain.emit("failed-mod"); return notamod(); } } @@ -778,8 +778,8 @@ const mods = { fs.rmSync(modPath, {recursive: true}); console.log(lang("cli.mods.removed")); cli.exit(); - ipcMain.emit("guigetmods"); - ipcMain.emit("removedmod", "", { + ipcMain.emit("gui-getmods"); + ipcMain.emit("removed-mod", "", { name: mod.replace(/^.*(\\|\/|\:)/, ""), manifestname: manifestname }); @@ -818,17 +818,17 @@ const mods = { console.log(lang("cli.mods.toggled")); cli.exit(); } - ipcMain.emit("guigetmods"); + ipcMain.emit("gui-getmods"); } }; setInterval(() => { if (gamepathExists()) { - ipcMain.emit("guigetmods"); + ipcMain.emit("gui-getmods"); } else { if (fs.existsSync("viper.json")) { if (settings.gamepath != "") { - ipcMain.emit("gamepathlost"); + ipcMain.emit("gamepath-lost"); } } } -- cgit v1.2.3 From 59aa33289cebd63432904ac69fa7d9f4f2bc1b9c Mon Sep 17 00:00:00 2001 From: 0neGal Date: Tue, 7 Jun 2022 17:23:33 +0200 Subject: minor changes Mostly syntax, but also a few fixes with how the settings system work, and also a change in localization strings. --- .gitignore | 3 ++- src/app/main.js | 1 + src/index.js | 7 +++---- src/lang/en.json | 2 +- src/utils.js | 31 ++++++++++++++++++------------- 5 files changed, 25 insertions(+), 19 deletions(-) (limited to 'src/app/main.js') diff --git a/.gitignore b/.gitignore index ec12b74..32e527a 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ +.vscode/ + dist/ node_modules/ -.vscode/ \ No newline at end of file diff --git a/src/app/main.js b/src/app/main.js index 647e5cd..9fb3191 100644 --- a/src/app/main.js +++ b/src/app/main.js @@ -14,6 +14,7 @@ var settings = { autolang: true, forcedlang: "en", autoupdate: true, + originkill: false, zip: "/northstar.zip", lang: navigator.language, excludes: [ diff --git a/src/index.js b/src/index.js index a566b57..2c03529 100644 --- a/src/index.js +++ b/src/index.js @@ -6,7 +6,6 @@ const { app, ipcMain, BrowserWindow, dialog } = require("electron"); const utils = require("./utils"); const cli = require("./cli"); const requests = require("./extras/requests"); -const { settings } = require("./utils"); var log = console.log; @@ -48,7 +47,7 @@ function start() { }; send = win.send; ipcMain.on("exit", () => { - if (settings.originkill) { + if (utils.settings.originkill) { utils.isOriginRunning().then((running) => { if (running) { utils.killOrigin().then(process.exit(0)) @@ -60,8 +59,8 @@ function start() { process.exit(0) } }); - ipcMain.on("minimize", () => { win.minimize() }); - ipcMain.on("relaunch", () => { app.relaunch(); app.exit() }); + ipcMain.on("minimize", () => {win.minimize()}); + ipcMain.on("relaunch", () => {app.relaunch(); app.exit()}); // passthrough to renderer from main ipcMain.on("win-log", (event, ...args) => {send("log", ...args)}); diff --git a/src/lang/en.json b/src/lang/en.json index 3ae6ff1..72711b8 100644 --- a/src/lang/en.json +++ b/src/lang/en.json @@ -105,7 +105,7 @@ "gui.settings.excludes.title": "Retain files on update", "gui.settings.excludes.desc": "When Northstar is updated, files specified here will not be overwritten by files from the new Northstar update, unless you know what you're changing, you should probably not change anything here. Each file is separated with a space.", "gui.settings.originkill.title": "Automatically quit Origin", - "gui.settings.originkill.desc": "When Viper exits, automatically quit Origin client too. Mirrors behavior of launching the game through Steam.", + "gui.settings.originkill.desc": "When Viper exits, automatically quit Origin client too.", "gui.update.downloading": "Downloading...", "gui.update.extracting": "Extracting update...", diff --git a/src/utils.js b/src/utils.js index 2fea3ea..6114ef1 100644 --- a/src/utils.js +++ b/src/utils.js @@ -29,6 +29,7 @@ var settings = { autolang: true, forcedlang: "en", autoupdate: true, + originkill: false, nsargs: "-multiple", zip: "/northstar.zip", @@ -37,9 +38,7 @@ var settings = { excludes: [ "ns_startup_args.txt", "ns_startup_args_dedi.txt" - ], - - originkill: false + ] } // Logs into the dev tools of the renderer @@ -103,7 +102,7 @@ async function isGameRunning() { }); } -//Check if origin client is running +// checks if any origin processes are running async function isOriginRunning() { return new Promise(resolve => { let procs = ["Origin.exe", "OriginClientService.exe"]; @@ -126,7 +125,7 @@ async function isOriginRunning() { }); } -//Kill origin client +// kill origin processes async function killOrigin() { return new Promise(resolve => { let proc = "Origin.exe"; //I'm pretty sure we only have to kill this one @@ -138,7 +137,7 @@ async function killOrigin() { })(); exec(cmd, (err, stdout) => { - //just try and fail silently if we don't find it w/e + // just try and fail silently if we don't find it w/e resolve(true); }); }); @@ -879,21 +878,27 @@ setInterval(() => { module.exports = { mods, - lang, winLog, - launch, + update, - setpath, updatevp, - settings, - saveSettings, getNSVersion, getTF2Version, + handleNorthstarUpdating, + + launch, + killOrigin, isGameRunning, isOriginRunning, - killOrigin, + + + settings, + saveSettings, + + setpath, gamepathExists, - handleNorthstarUpdating, + + lang, setlang: (lang) => { settings.lang = lang; saveSettings(); -- cgit v1.2.3