From a4b11903979fdb4c8b0f6dda8f7343e14c1ebe17 Mon Sep 17 00:00:00 2001 From: GitExample Date: Thu, 3 Feb 2022 01:36:11 +0100 Subject: detection of installed mods, disabling buttons When a new mod has been installed through the browser UI it's button is changed from "Install" to "Re-Install" instantly. We also now disable modding related buttons when updating NS, or when installing mods. This should prevent issues. --- src/app/browser.js | 34 ++++++++++++++++++++++++++++++++-- src/app/main.js | 11 +++++++++++ src/index.js | 3 ++- src/utils.js | 5 ++++- 4 files changed, 49 insertions(+), 4 deletions(-) diff --git a/src/app/browser.js b/src/app/browser.js index 73eb6f7..f152a6a 100644 --- a/src/app/browser.js +++ b/src/app/browser.js @@ -55,16 +55,46 @@ function BrowserEl(properties) { browserEntries.innerHTML = ""; } + let installstring = "Install"; + if (normalize(modsdiv.innerText.split("\n")).includes(normalize(properties.title))) { + installstring = "Re-Install"; + } + browserEntries.innerHTML += ` -
+
${properties.title}
${properties.description} - ${lang("gui.browser.madeby")} ${properties.author}
- +
` } + +ipcRenderer.on("installedmod", (event, modname) => { + setButtons(true); + modname = normalize(modname); + + if (document.getElementById(modname)) { + document.getElementById(modname).querySelector(".text button").innerHTML = "Re-Install"; + } +}) + +function normalize(items) { + let main = (string) => { + return string.replaceAll(" ", "").replaceAll(".", "").toLowerCase() + } + if (typeof items == "string") { + return main(items) + } else { + let newArray = []; + for (let i = 0; i < items.length; i++) { + newArray.push(main(items[i])); + } + + return newArray; + } +} diff --git a/src/app/main.js b/src/app/main.js index b61b20a..fa7cea8 100644 --- a/src/app/main.js +++ b/src/app/main.js @@ -68,6 +68,15 @@ function log(msg) { // updating/installing Northstar. function setButtons(state) { playNsBtn.disabled = !state; + + let disablearray = (array) => { + for (let i = 0; i < array.length; i++) { + array[i].disabled = !state; + } + } + + disablearray(document.querySelectorAll("#nsMods .buttons.modbtns button")) + disablearray(document.querySelectorAll("#browser #browserEntries .text button")) } // Frontend part of updating Northstar @@ -150,11 +159,13 @@ function selected(all) { // Tells the main process to install a mod function installmod() { + setButtons(false); ipcRenderer.send("installmod") } // Tells the main process to install a mod from a URL function installFromURL(url) { + setButtons(false); ipcRenderer.send("installfromurl", url) } diff --git a/src/index.js b/src/index.js index 4849b72..a847020 100644 --- a/src/index.js +++ b/src/index.js @@ -43,11 +43,12 @@ function start() { ipcMain.on("exit", () => {process.exit(0)}) ipcMain.on("minimize", () => {win.minimize()}) + 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)); ipcMain.on("guigetmods", (event, ...args) => {win.webContents.send("mods", utils.mods.list())}); - ipcMain.on("installfromurl", (event, url) => {utils.mods.installFromURL(url)}) + ipcMain.on("installedmod", (event, modname) => {console.log(modname);win.webContents.send("installedmod", modname)}) win.webContents.on("dom-ready", () => { win.webContents.send("mods", utils.mods.list()); diff --git a/src/utils.js b/src/utils.js index d1cc345..b54808d 100644 --- a/src/utils.js +++ b/src/utils.js @@ -444,12 +444,15 @@ const mods = { if (fs.existsSync(path.join(mod, "mod.json")) && fs.statSync(path.join(mod, "mod.json")).isFile()) { - copy.sync(mod, path.join(modpath, mod.replace(/^.*(\\|\/|\:)/, "")), { + let modname = mod.replace(/^.*(\\|\/|\:)/, ""); + copy.sync(mod, path.join(modpath, modname), { mode: true, cover: true, utimes: true, }); + ipcMain.emit("installedmod", "", modname); + return installed(); } else { files = fs.readdirSync(mod); -- cgit v1.2.3