Show version of bepinex installation in settings

This commit is contained in:
2026-01-22 18:47:40 +01:00
parent 118a2fd84e
commit d6697b13c6
3 changed files with 37 additions and 20 deletions

24
main.js
View File

@@ -41,14 +41,31 @@ app.on('window-all-closed', () => {
ipcMain.handle('save-path', (event, path) => { ipcMain.handle('save-path', (event, path) => {
silksongPath = path; silksongPath = path;
store.set('silksong-path', path); store.set('silksong-path', silksongPath);
}); });
ipcMain.handle('load-path', () => { ipcMain.handle('load-path', () => {
silksongPath = store.get('silksong-path'); silksongPath = store.get('silksong-path');
if (silksongPath == undefined) {
return "";
}
return silksongPath; 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) { async function fileExists(filePath) {
try { try {
await fs.access(filePath); await fs.access(filePath);
@@ -133,7 +150,6 @@ ipcMain.handle('install-bepinex', async () => {
throw new Error("Download error"); throw new Error("Download error");
} }
const filePath = `${userSavePath}\\bepinex.zip` const filePath = `${userSavePath}\\bepinex.zip`
console.log(filePath)
await pipeline( await pipeline(
download.body, download.body,
@@ -143,7 +159,7 @@ ipcMain.handle('install-bepinex', async () => {
await extract(filePath, { dir: silksongPath}) await extract(filePath, { dir: silksongPath})
await fs.unlink(filePath) await fs.unlink(filePath)
return bepinexVersion saveBepinexVersion(bepinexVersion)
}) })
ipcMain.handle('uninstall-bepinex', async () => { ipcMain.handle('uninstall-bepinex', async () => {
@@ -166,5 +182,5 @@ ipcMain.handle('uninstall-bepinex', async () => {
} }
} }
bepinexVersion = undefined bepinexVersion = undefined
return bepinexVersion saveBepinexVersion(bepinexVersion)
}) })

View File

@@ -6,17 +6,17 @@ contextBridge.exposeInMainWorld('versions', {
electron: () => process.versions.electron electron: () => process.versions.electron
}); });
contextBridge.exposeInMainWorld('save', {
saveSilksongPath: (path) => ipcRenderer.invoke('save-path', path),
loadSilksongPath: () => ipcRenderer.invoke('load-path')
});
contextBridge.exposeInMainWorld('files', { contextBridge.exposeInMainWorld('files', {
fileExists: (path) => ipcRenderer.invoke('file-exists', path), fileExists: (path) => ipcRenderer.invoke('file-exists', path),
userSavePath: () => ipcRenderer.invoke('get-userSavePath'), userSavePath: () => ipcRenderer.invoke('get-userSavePath'),
delete: (path) => ipcRenderer.invoke('delete-data', path), delete: (path) => ipcRenderer.invoke('delete-data', path),
export: () => ipcRenderer.invoke('export-data'), 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', { contextBridge.exposeInMainWorld('electronAPI', {

View File

@@ -8,7 +8,6 @@ const settingsTemplate = document.getElementById("settings-template");
const modTemplate = document.getElementById("mod-template"); const modTemplate = document.getElementById("mod-template");
const versionText = HomeTemplate.content.getElementById("version-text"); const versionText = HomeTemplate.content.getElementById("version-text");
let bepinexVersion
navigate("home") navigate("home")
@@ -66,14 +65,15 @@ async function navigate(page) {
const settingsTemplateCopy = settingsTemplate.content.cloneNode(true) const settingsTemplateCopy = settingsTemplate.content.cloneNode(true)
const silksongPathInput = settingsTemplateCopy.getElementById("silksong-path-input") const silksongPathInput = settingsTemplateCopy.getElementById("silksong-path-input")
silksongPathInput.value = await save.loadSilksongPath() silksongPathInput.value = await files.loadSilksongPath()
silksongPathInput.addEventListener('input', async function(event) { silksongPathInput.addEventListener('input', async function(event) {
let silksongPath = silksongPathInput.value let silksongPath = silksongPathInput.value
await save.saveSilksongPath(silksongPath) await files.saveSilksongPath(silksongPath)
}); });
view.appendChild(settingsTemplateCopy) view.appendChild(settingsTemplateCopy)
setBepinexVersion()
} }
} }
@@ -90,9 +90,9 @@ async function autoDetectGamePath() {
for (let i = 'A'.charCodeAt(0); i <= 'Z'.charCodeAt(0); i++) { for (let i = 'A'.charCodeAt(0); i <= 'Z'.charCodeAt(0); i++) {
const fullPath = `${String.fromCharCode(i)}${path}` const fullPath = `${String.fromCharCode(i)}${path}`
if (await files.fileExists(fullPath)) { if (await files.fileExists(fullPath)) {
await save.saveSilksongPath(fullPath) await files.saveSilksongPath(fullPath)
if (document.getElementById("silksong-path-input")) { 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 return
} }
@@ -102,7 +102,7 @@ async function autoDetectGamePath() {
async function deleteData() { async function deleteData() {
await files.delete(savePath) 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() { async function exportData() {
@@ -111,7 +111,7 @@ async function exportData() {
async function importData() { async function importData() {
await files.import() await files.import()
document.getElementById("silksong-path-input").value = await save.loadSilksongPath() document.getElementById("silksong-path-input").value = await files.loadSilksongPath()
} }
async function downloadMod() { async function downloadMod() {
@@ -119,18 +119,19 @@ async function downloadMod() {
} }
async function installBepinex() { async function installBepinex() {
bepinexVersion = await bepinex.install() await bepinex.install()
setBepinexVersion() setBepinexVersion()
} }
async function uninstallBepinex() { async function uninstallBepinex() {
bepinexVersion = await bepinex.uninstall() await bepinex.uninstall()
setBepinexVersion() setBepinexVersion()
} }
async function setBepinexVersion() { async function setBepinexVersion() {
const bepinexVersion = await files.loadBepinexVersion()
const bepinexVersionText = document.getElementById("bepinex-version-text") const bepinexVersionText = document.getElementById("bepinex-version-text")
if(await bepinexVersion == undefined) { if(bepinexVersion == undefined) {
bepinexVersionText.innerText = "BepInEx is not installed" bepinexVersionText.innerText = "BepInEx is not installed"
} }
else { else {