diff options
-rw-r--r-- | src/app/index.html | 10 | ||||
-rw-r--r-- | src/app/main.js | 59 | ||||
-rw-r--r-- | src/index.js | 8 | ||||
-rw-r--r-- | src/lang/en.json | 2 | ||||
-rw-r--r-- | src/utils.js | 38 |
5 files changed, 99 insertions, 18 deletions
diff --git a/src/app/index.html b/src/app/index.html index ffc31a6..88cfbb5 100644 --- a/src/app/index.html +++ b/src/app/index.html @@ -31,11 +31,11 @@ <div class="line"> <div class="text" id="modcount">%%gui.mods%%</div> <div class="buttons"> - <button id="removemod">%%gui.mods.remove%%</button> - <button id="removeall">%%gui.mods.removeall%%</button> - <button id="togglemod">%%gui.mods.toggle%%</button> - <button id="toggleall">%%gui.mods.toggleall%%</button> - <button id="installmod">%%gui.mods.install%%</button> + <button id="removemod" onclick="selected().remove()">%%gui.mods.remove%%</button> + <button id="removeall" onclick="selected(true).remove()">%%gui.mods.removeall%%</button> + <button id="togglemod" onclick="selected().toggle()">%%gui.mods.toggle%%</button> + <button id="toggleall" onclick="selected(true).toggle(true)">%%gui.mods.toggleall%%</button> + <button id="installmod" onclick="installmod()">%%gui.mods.install%%</button> </div> </div> </div> diff --git a/src/app/main.js b/src/app/main.js index c500ba3..f903c29 100644 --- a/src/app/main.js +++ b/src/app/main.js @@ -45,18 +45,57 @@ function setButtons(state) { } } +let lastselected = ""; function select(entry) { - let entries = document.querySelectorAll("#modsdiv .mod"); + let entries = document.querySelectorAll("#modsdiv .mod span"); for (let i = 0; i < entries.length; i++) { if (entries[i].innerHTML == entry) { - entries[i].classList.add("selected"); + lastselected = entry; + entries[i].parentElement.classList.add("selected"); } else { - entries[i].classList.remove("selected"); + entries[i].parentElement.classList.remove("selected"); } } } +function selected(all) { + let selected = ""; + if (all) { + selected = "allmods" + } else { + selected = document.querySelector(".mod.selected span"); + if (selected != null) { + selected = selected.innerHTML; + } else { + alert(lang("gui.mods.nothingselected")); + return { + remove: () => {}, + toggle: () => {}, + } + } + } + + return { + remove: () => { + if (selected == "allmods") { + if (! confirm(lang("gui.mods.removeall.confirm"))) { + return; + } + } + + ipcRenderer.send("removemod", selected) + }, + toggle: () => { + ipcRenderer.send("togglemod", selected) + } + } +} + +function installmod() { + ipcRenderer.send("installmod") +} + ipcRenderer.on("ns-updated", () => {setButtons(true)}) ipcRenderer.on("ns-updating", () => {setButtons(false)}) @@ -67,15 +106,19 @@ ipcRenderer.on("newpath", (event, newpath) => { ipcRenderer.on("log", (event, msg) => {log(msg)}) ipcRenderer.on("mods", (event, mods) => { + console.log("refreshed mods") modcount.innerHTML = `${lang("gui.mods.count")} ${mods.all.length}`; modsdiv.innerHTML = ""; - for (let i = 0; i < mods.enabled.length; i++) { - modsdiv.innerHTML += `<div onclick="select('${mods.enabled[i].Name}')" class="mod">${mods.enabled[i].Name}</div>`; + + let newmod = (name, extra) => { + if (! extra) {extra = ""} + modsdiv.innerHTML += `<div onclick="select('${name}')" class="mod"><span>${name}</span>${extra}</div>`; } - for (let i = 0; i < mods.disabled.length; i++) { - modsdiv.innerHTML += `<div onclick="select('${mods.disabled[i].Name} - Disabled')" class="mod">${mods.disabled[i].Name} - Disabled</div>`; - } + for (let i = 0; i < mods.enabled.length; i++) {newmod(mods.enabled[i].Name)} + for (let i = 0; i < mods.disabled.length; i++) {newmod(mods.disabled[i].Name, " - Disabled")} + + select(lastselected); }) ipcRenderer.on("version", (event, versions) => { diff --git a/src/index.js b/src/index.js index 161092a..7ef9321 100644 --- a/src/index.js +++ b/src/index.js @@ -57,6 +57,14 @@ function start() { ipcMain.on("updatenow", () => { autoUpdater.quitAndInstall(); }) + + ipcMain.on("removemod", (event, mod) => {utils.mods.remove(mod)}) + ipcMain.on("togglemod", (event, mod) => {utils.mods.toggle(mod)}) + ipcMain.on("installmod", () => { + dialog.showOpenDialog({properties: ["openDirectory"]}).then(res => { + utils.mods.install(res.filePaths[0]); + }).catch(err => {console.error(err)}) + }) } ipcMain.on("launch", (event) => {utils.launch()}) diff --git a/src/lang/en.json b/src/lang/en.json index c5e0d77..20f97f2 100644 --- a/src/lang/en.json +++ b/src/lang/en.json @@ -35,6 +35,8 @@ "gui.mods.toggleall": "Toggle All", "gui.mods.remove": "Remove Mod", "gui.mods.removeall": "Remove All", + "gui.mods.nothingselected": "You've not selected a mod.", + "gui.mods.removeall.confirm": "Removing all mods will usually require you to reinstall Northstar, are you sure?", "gui.update.downloading": "Downloading...", "gui.update.extracting": "Extracting update...", diff --git a/src/utils.js b/src/utils.js index 88e5f3a..ef8b586 100644 --- a/src/utils.js +++ b/src/utils.js @@ -117,6 +117,7 @@ function update() { } } + ipcMain.emit("guigetmods"); ipcMain.emit("ns-updated"); winLog(lang("gui.update.finished")); console.log(lang("cli.update.finished")); @@ -194,7 +195,7 @@ const mods = { disabled.push({...require(path.join(disabledPath, file, "mod.json")), FolderName: file, Disabled: true}) }catch(err) { console.log("error: " + lang("cli.mods.improperjson"), file) - disabled.push({Name: file, FolderName: file, Version: "unknown", Disabled: false}) + disabled.push({Name: file, FolderName: file, Version: "unknown", Disabled: true}) } } } @@ -220,15 +221,13 @@ const mods = { install: (mod) => { if (fs.statSync(mod).isDirectory()) { if (fs.statSync(path.join(mod, "mod.json"))) { - copy(mod, path.join(modpath, mod.replace(/^.*(\\|\/|\:)/, "")), { + copy.sync(mod, path.join(modpath, mod.replace(/^.*(\\|\/|\:)/, "")), { mode: true, cover: true, utimes: true, - }, (err) => { - if(err) {console.log("error:", err)}; - console.log(); }); cli.exit(); + ipcMain.emit("guigetmods"); return } else { console.log("error: " + lang("cli.mods.notamod")) @@ -240,19 +239,47 @@ const mods = { fs.createReadStream(mod).pipe(unzip.Extract({path: modpath})) .on("finish", () => { cli.exit(); + ipcMain.emit("guigetmods"); }); }, remove: (mod) => { + if (mod == "allmods") { + let modlist = mods.list().all; + for (let i = 0; i < modlist.length; i++) { + mods.remove(modlist[i].Name) + } + return + } + + let disabled = path.join(modpath, "disabled"); + if (! fs.existsSync(disabled)) { + fs.mkdirSync(disabled) + } + let modName = mods.get(mod).FolderName; let modPath = path.join(modpath, modName); + + if (mods.get(mod).Disabled) { + modPath = path.join(disabled, modName); + } + if (fs.statSync(modPath).isDirectory()) { fs.rmSync(modPath, {recursive: true}); cli.exit(); + ipcMain.emit("guigetmods"); } else { cli.exit(1); } }, toggle: (mod) => { + if (mod == "allmods") { + let modlist = mods.list().all; + for (let i = 0; i < modlist.length; i++) { + mods.toggle(modlist[i].Name) + } + return + } + let disabled = path.join(modpath, "disabled"); if (! fs.existsSync(disabled)) { fs.mkdirSync(disabled) @@ -268,6 +295,7 @@ const mods = { } fs.moveSync(modPath, dest) + ipcMain.emit("guigetmods"); } }; |