From 380b9a4604e1dd02ddaa17f7c1cca8744118f4a1 Mon Sep 17 00:00:00 2001 From: GabiZar Date: Sun, 1 Mar 2026 20:17:08 +0100 Subject: [PATCH] Add the possibility to activate and deactivate mods --- main.js | 114 ++++++++++++++++++++++++++++--------------- preload.js | 11 +++-- renderer/index.html | 7 ++- renderer/renderer.js | 32 +++++++++--- renderer/style.css | 16 +++--- 5 files changed, 122 insertions(+), 58 deletions(-) diff --git a/main.js b/main.js index 45bec86..8ff6e9b 100644 --- a/main.js +++ b/main.js @@ -38,7 +38,7 @@ let onlineCachedModList; let onlineTotalModsCount; const bepinexFiles = [".doorstop_version", "changelog.txt", "doorstop_config.ini", "winhttp.dll"]; -let bepinexVersion; +let bepinexVersion = bepinexStore.get("bepinex-version"); let bepinexBackupVersion; let mainWindow; @@ -120,6 +120,7 @@ app.on("open-url", (event, url) => { ipcMain.handle("save-path", (event, path) => { saveSilksongPath(path); }); + function saveSilksongPath(path) { store.set("silksong-path", path); } @@ -208,6 +209,7 @@ async function saveModInfo(modId, suppr = false) { } const modInfo = onlineCachedModList.find((mod) => mod.modId == modId); + modInfo.activated = true; installedModsStore.set(String(modId), modInfo); } @@ -310,9 +312,7 @@ async function installBepinex() { saveBepinexVersion(release.tag_name); } - if (await fileExists(modSavePath)) { - await fs.cp(modSavePath, path.join(silksongPath, "BepInEx", "plugins"), { recursive: true }); - } + checkInstalledMods(); } ipcMain.handle("install-bepinex", async () => { @@ -440,12 +440,12 @@ ipcMain.handle("get-mods", async (event, type) => { if (!installedCachedModList) { await searchInstalledMods(""); } - return { modsInfo: installedCachedModList, installedTotalCount: installedTotalModsCount }; + return { installedModsInfo: installedCachedModList, installedTotalCount: installedTotalModsCount }; } else if (type == "mods-online") { if (!onlineCachedModList) { await searchNexusMods(""); } - return { mods: onlineCachedModList, onlineTotalCount: onlineTotalModsCount }; + return { onlineModsInfo: onlineCachedModList, onlineTotalCount: onlineTotalModsCount }; } }); @@ -511,38 +511,6 @@ async function startDownload(modId, fileId, key, expires) { installedCachedModList = undefined; } -async function checkInstalledMods() { - const bepinexFolderPath = path.join(loadSilksongPath(), "BepInEx"); - - for (const [key, modInfo] of Object.entries(installedModsStore.store)) { - modInfo.modId = String(modInfo.modId); - if (!(await fileExists(path.join(modSavePath, modInfo.modId)))) { - saveModInfo(key, true); - await fs.rm(path.join(bepinexFolderPath, "plugins", modInfo.modId), { recursive: true }); - } - } -} - -ipcMain.handle("uninstall-mod", async (event, modId) => { - modId = String(modId); - const BepinexPluginsPath = path.join(loadSilksongPath(), "BepInEx", "plugins"); - const modPath = path.join(BepinexPluginsPath, modId); - if (await fileExists(path.join(modSavePath, modId))) { - await fs.rm(path.join(modSavePath, modId), { recursive: true }); - } - if (await fileExists(modPath)) { - await fs.rm(modPath, { recursive: true }); - } - - for (let i = 0; i < installedCachedModList.length; i++) { - if (installedCachedModList[i].modId == modId) { - installedCachedModList.splice(i, 1); - } - } - - saveModInfo(modId, true); -}); - ipcMain.handle("search-nexus-mods", async (event, keywords, offset, count, sortFilter, sortOrder) => { await searchNexusMods(keywords, offset, count, sortFilter, sortOrder); }); @@ -608,6 +576,9 @@ async function searchNexusMods(keywords, offset = 0, count = 10, sortFilter = "d onlineTotalModsCount = data.mods.totalCount; } +////////////////////////////////////////////////////// +//////////////////////// MODS //////////////////////// + ipcMain.handle("search-installed-mods", async (event, keywords, offset, count, sortFilter, sortOrder) => { await searchInstalledMods(keywords, offset, count, sortFilter, sortOrder); }); @@ -635,6 +606,73 @@ async function searchInstalledMods(keywords, offset = 0, count = 10, sortFilter installedCachedModList = modsInfoSorted.slice(offset, offset + count); } +async function checkInstalledMods() { + const bepinexPluginsPath = path.join(loadSilksongPath(), "BepInEx", "plugins"); + + for (const [key, modInfo] of Object.entries(installedModsStore.store)) { + modInfo.modId = String(modInfo.modId); + if (!(await fileExists(path.join(modSavePath, modInfo.modId)))) { + saveModInfo(key, true); + if (await fileExists(path.join(bepinexPluginsPath, modInfo.modId))) { + await fs.rm(path.join(bepinexPluginsPath, modInfo.modId), { recursive: true }); + } + continue; + } + + if (modInfo.activated) { + await fs.cp(path.join(modSavePath, modInfo.modId), path.join(bepinexPluginsPath, modInfo.modId), { recursive: true }); + } + } +} + +ipcMain.handle("uninstall-mod", async (event, modId) => { + modId = String(modId); + const BepinexPluginsPath = path.join(loadSilksongPath(), "BepInEx", "plugins"); + const modPath = path.join(BepinexPluginsPath, modId); + if (await fileExists(path.join(modSavePath, modId))) { + await fs.rm(path.join(modSavePath, modId), { recursive: true }); + } + if (await fileExists(modPath)) { + await fs.rm(modPath, { recursive: true }); + } + + for (let i = 0; i < installedCachedModList.length; i++) { + if (installedCachedModList[i].modId == modId) { + installedCachedModList.splice(i, 1); + } + } + + saveModInfo(modId, true); +}); + +ipcMain.handle("activate-mod", async (event, modId) => { + const BepinexPluginsPath = path.join(loadSilksongPath(), "BepInEx", "plugins"); + + if (!installedModsStore.get(`${modId}.activated`)) { + installedModsStore.set(`${modId}.activated`, true); + + if (bepinexVersion) { + if (!(await fileExists(path.join(BepinexPluginsPath, String(modId))))) { + await fs.cp(path.join(modSavePath, String(modId)), path.join(BepinexPluginsPath, String(modId)), { recursive: true }); + } + } + } +}); + +ipcMain.handle("deactivate-mod", async (event, modId) => { + const BepinexPluginsPath = path.join(loadSilksongPath(), "BepInEx", "plugins"); + + if (installedModsStore.get(`${modId}.activated`)) { + installedModsStore.set(`${modId}.activated`, false); + + if (bepinexVersion) { + if (await fileExists(path.join(BepinexPluginsPath, String(modId)))) { + await fs.rm(path.join(BepinexPluginsPath, String(modId)), { recursive: true }); + } + } + } +}); + ////////////////////////////////////////////////////// //////////////////// UNCATEGORIZE //////////////////// diff --git a/preload.js b/preload.js index c33f689..3e36b61 100644 --- a/preload.js +++ b/preload.js @@ -45,9 +45,14 @@ contextBridge.exposeInMainWorld("bepinex", { contextBridge.exposeInMainWorld("nexus", { verifyAPI: () => ipcRenderer.invoke("verify-nexus-api"), - getMods: (type) => ipcRenderer.invoke("get-mods", type), download: (link) => ipcRenderer.invoke("open-download", link), - uninstall: (modId) => ipcRenderer.invoke("uninstall-mod", modId), search: (keywords, offset, count, sortFilter, sortOrder) => ipcRenderer.invoke("search-nexus-mods", keywords, offset, count, sortFilter, sortOrder), - searchInstalled: (keywords, offset, count, sortFilter, sortOrder) => ipcRenderer.invoke("search-installed-mods", keywords, offset, count, sortFilter, sortOrder), +}); + +contextBridge.exposeInMainWorld("mods", { + searchInstalled: (keywords, offset, count, sortFilter, sortOrder) => ipcRenderer.invoke("search-installed-mods", keywords, offset, count, sortFilter, sortOrder), + uninstall: (modId) => ipcRenderer.invoke("uninstall-mod", modId), + getMods: (type) => ipcRenderer.invoke("get-mods", type), + activateMods: (modId) => ipcRenderer.invoke("activate-mod", modId), + deactivateMods: (modId) => ipcRenderer.invoke("deactivate-mod", modId), }); diff --git a/renderer/index.html b/renderer/index.html index a10b52f..76d85f5 100644 --- a/renderer/index.html +++ b/renderer/index.html @@ -170,6 +170,11 @@
Uninstall Website +

Activated:

+
@@ -221,7 +226,7 @@
  • Steel
  • -