diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/app/browser.js | 23 | ||||
-rw-r--r-- | src/index.js | 4 | ||||
-rw-r--r-- | src/utils.js | 37 |
3 files changed, 42 insertions, 22 deletions
diff --git a/src/app/browser.js b/src/app/browser.js index a9a36f9..ff9ec87 100644 --- a/src/app/browser.js +++ b/src/app/browser.js @@ -55,6 +55,17 @@ var Browser = { for (let i = 0; i < res.length; i++) { new BrowserElFromObj(res[i].item); } + }, + setbutton: (mod, string) => { + mod = normalize(mod); + console.log(mod) + if (document.getElementById(mod)) { + let elems = document.querySelectorAll(`#${mod}`); + + for (let i = 0; i < elems.length; i++) { + elems[i].querySelector(".text button").innerHTML = string; + } + } } }; Browser.toggle() Browser.loadfront() @@ -123,13 +134,15 @@ function BrowserEl(properties) { ` } -ipcRenderer.on("installedmod", (event, modname) => { +ipcRenderer.on("removedmod", (event, modname) => { setButtons(true); - modname = normalize(modname); + console.log("test" + modname) + Browser.setbutton(modname, lang("gui.browser.install")); +}) - if (document.getElementById(modname)) { - document.getElementById(modname).querySelector(".text button").innerHTML = lang("gui.browser.reinstall"); - } +ipcRenderer.on("installedmod", (event, modname) => { + setButtons(true); + Browser.setbutton(modname, lang("gui.browser.reinstall")); }) function normalize(items) { diff --git a/src/index.js b/src/index.js index a847020..a0cb4db 100644 --- a/src/index.js +++ b/src/index.js @@ -47,8 +47,10 @@ function start() { 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("failedmod", (event, modname) => {win.webContents.send("failedmod", modname)}); + ipcMain.on("removedmod", (event, modname) => {win.webContents.send("removedmod", modname)}); + ipcMain.on("installedmod", (event, modname) => {win.webContents.send("installedmod", modname)}); ipcMain.on("guigetmods", (event, ...args) => {win.webContents.send("mods", utils.mods.list())}); - 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 1456467..39e86be 100644 --- a/src/utils.js +++ b/src/utils.js @@ -413,6 +413,8 @@ const mods = { // inside the zip or folder to see if buried in another folder or // not, as sometimes that's the case. install: (mod) => { + let modname = mod.replace(/^.*(\\|\/|\:)/, ""); + if (getNSVersion() == "unknown") { winLog(lang("general.notinstalled")) console.log("error: " + lang("general.notinstalled")) @@ -432,6 +434,8 @@ const mods = { cli.exit(); winLog(lang("gui.mods.installedmod")) + + ipcMain.emit("installedmod", "", modname); ipcMain.emit("guigetmods"); return true; } @@ -444,9 +448,7 @@ const mods = { if (fs.existsSync(path.join(mod, "mod.json")) && fs.statSync(path.join(mod, "mod.json")).isFile()) { - let modname = mod.replace(/^.*(\\|\/|\:)/, ""); copy(mod, path.join(modpath, modname)) - ipcMain.emit("installedmod", "", modname); return installed(); } else { @@ -479,23 +481,25 @@ const mods = { try { fs.createReadStream(mod).pipe(unzip.Extract({path: cache})) .on("finish", () => { - if (fs.existsSync(path.join(cache, "manifest.json"))) { - files = fs.readdirSync(path.join(cache, "mods")); - - for (let i = 0; i < files.length; i++) { - let mod = path.join(cache, "mods", files[i]); - if (fs.statSync(mod).isDirectory()) { - setTimeout(() => { - if (mods.install(mod)) {return true}; - }, 1000) + setTimeout(() => { + if (fs.existsSync(path.join(cache, "manifest.json"))) { + files = fs.readdirSync(path.join(cache, "mods")); + + for (let i = 0; i < files.length; i++) { + let mod = path.join(cache, "mods", files[i]); + if (fs.statSync(mod).isDirectory()) { + setTimeout(() => { + if (mods.install(mod)) {return true}; + }, 1000) + } } + return notamod(); } - return notamod(); - } - if (mods.install(cache)) { - installed(); - } else {return notamod()} + if (mods.install(cache)) { + installed(); + } else {return notamod()} + }, 1000) }); }catch(err) {return notamod()} } @@ -582,6 +586,7 @@ const mods = { console.log(lang("cli.mods.removed")); cli.exit(); ipcMain.emit("guigetmods"); + ipcMain.emit("removedmod", "", mod.replace(/^.*(\\|\/|\:)/, "")); } else { cli.exit(1); } |