From d6697b13c6a593d72481569e49971d61009bc4b1 Mon Sep 17 00:00:00 2001 From: GabiZar Date: Thu, 22 Jan 2026 18:47:40 +0100 Subject: [PATCH] Show version of bepinex installation in settings --- main.js | 24 ++++++++++++++++++++---- preload.js | 12 ++++++------ renderer/renderer.js | 21 +++++++++++---------- 3 files changed, 37 insertions(+), 20 deletions(-) diff --git a/main.js b/main.js index 3ee996c..9494a4e 100644 --- a/main.js +++ b/main.js @@ -41,14 +41,31 @@ app.on('window-all-closed', () => { ipcMain.handle('save-path', (event, path) => { silksongPath = path; - store.set('silksong-path', path); + store.set('silksong-path', silksongPath); }); ipcMain.handle('load-path', () => { silksongPath = store.get('silksong-path'); + if (silksongPath == undefined) { + return ""; + } return silksongPath; }); +function saveBepinexVersion(version) { + bepinexVersion = version; + if (bepinexVersion == undefined) { + store.delete('bepinex-version'); + return; + } + store.set('bepinex-version', version); +}; + +ipcMain.handle('load-bepinex-version', () => { + bepinexVersion = store.get('bepinex-version'); + return bepinexVersion; +}); + async function fileExists(filePath) { try { await fs.access(filePath); @@ -133,7 +150,6 @@ ipcMain.handle('install-bepinex', async () => { throw new Error("Download error"); } const filePath = `${userSavePath}\\bepinex.zip` - console.log(filePath) await pipeline( download.body, @@ -143,7 +159,7 @@ ipcMain.handle('install-bepinex', async () => { await extract(filePath, { dir: silksongPath}) await fs.unlink(filePath) - return bepinexVersion + saveBepinexVersion(bepinexVersion) }) ipcMain.handle('uninstall-bepinex', async () => { @@ -166,5 +182,5 @@ ipcMain.handle('uninstall-bepinex', async () => { } } bepinexVersion = undefined - return bepinexVersion + saveBepinexVersion(bepinexVersion) }) \ No newline at end of file diff --git a/preload.js b/preload.js index 519dd17..25dc5fe 100644 --- a/preload.js +++ b/preload.js @@ -6,17 +6,17 @@ contextBridge.exposeInMainWorld('versions', { electron: () => process.versions.electron }); -contextBridge.exposeInMainWorld('save', { - saveSilksongPath: (path) => ipcRenderer.invoke('save-path', path), - loadSilksongPath: () => ipcRenderer.invoke('load-path') -}); - contextBridge.exposeInMainWorld('files', { fileExists: (path) => ipcRenderer.invoke('file-exists', path), userSavePath: () => ipcRenderer.invoke('get-userSavePath'), delete: (path) => ipcRenderer.invoke('delete-data', path), export: () => ipcRenderer.invoke('export-data'), - import: () => ipcRenderer.invoke('import-data') + import: () => ipcRenderer.invoke('import-data'), + + saveSilksongPath: (path) => ipcRenderer.invoke('save-path', path), + loadSilksongPath: () => ipcRenderer.invoke('load-path'), + saveBepinexVersion: (version) => ipcRenderer.invoke('save-bepinex-version', version), + loadBepinexVersion: () => ipcRenderer.invoke('load-bepinex-version') }); contextBridge.exposeInMainWorld('electronAPI', { diff --git a/renderer/renderer.js b/renderer/renderer.js index fdcf550..ffaf29e 100644 --- a/renderer/renderer.js +++ b/renderer/renderer.js @@ -8,7 +8,6 @@ const settingsTemplate = document.getElementById("settings-template"); const modTemplate = document.getElementById("mod-template"); const versionText = HomeTemplate.content.getElementById("version-text"); -let bepinexVersion navigate("home") @@ -66,14 +65,15 @@ async function navigate(page) { const settingsTemplateCopy = settingsTemplate.content.cloneNode(true) const silksongPathInput = settingsTemplateCopy.getElementById("silksong-path-input") - silksongPathInput.value = await save.loadSilksongPath() + silksongPathInput.value = await files.loadSilksongPath() silksongPathInput.addEventListener('input', async function(event) { let silksongPath = silksongPathInput.value - await save.saveSilksongPath(silksongPath) + await files.saveSilksongPath(silksongPath) }); view.appendChild(settingsTemplateCopy) + setBepinexVersion() } } @@ -90,9 +90,9 @@ async function autoDetectGamePath() { for (let i = 'A'.charCodeAt(0); i <= 'Z'.charCodeAt(0); i++) { const fullPath = `${String.fromCharCode(i)}${path}` if (await files.fileExists(fullPath)) { - await save.saveSilksongPath(fullPath) + await files.saveSilksongPath(fullPath) if (document.getElementById("silksong-path-input")) { - document.getElementById("silksong-path-input").value = await save.loadSilksongPath() + document.getElementById("silksong-path-input").value = await files.loadSilksongPath() } return } @@ -102,7 +102,7 @@ async function autoDetectGamePath() { async function deleteData() { await files.delete(savePath) - document.getElementById("silksong-path-input").value = await save.loadSilksongPath() + document.getElementById("silksong-path-input").value = await files.loadSilksongPath() } async function exportData() { @@ -111,7 +111,7 @@ async function exportData() { async function importData() { await files.import() - document.getElementById("silksong-path-input").value = await save.loadSilksongPath() + document.getElementById("silksong-path-input").value = await files.loadSilksongPath() } async function downloadMod() { @@ -119,18 +119,19 @@ async function downloadMod() { } async function installBepinex() { - bepinexVersion = await bepinex.install() + await bepinex.install() setBepinexVersion() } async function uninstallBepinex() { - bepinexVersion = await bepinex.uninstall() + await bepinex.uninstall() setBepinexVersion() } async function setBepinexVersion() { + const bepinexVersion = await files.loadBepinexVersion() const bepinexVersionText = document.getElementById("bepinex-version-text") - if(await bepinexVersion == undefined) { + if(bepinexVersion == undefined) { bepinexVersionText.innerText = "BepInEx is not installed" } else {