add nexus api communication with verification for valide api key

This commit is contained in:
2026-02-03 18:49:56 +01:00
parent 16fc58e673
commit c038e92592
9 changed files with 715 additions and 13 deletions

53
main.js
View File

@@ -4,11 +4,16 @@ const Store = require('electron-store').default;
const fs = require('fs/promises');
const { createWriteStream } = require('fs');
const { pipeline } = require('stream/promises');
const extract = require("extract-zip");
const extract = require('extract-zip');
const Nexus = require('@nexusmods/nexus-api').default;
const store = new Store();
const userSavePath = app.getPath('userData')
let silksongPath = store.get('silksong-path')
let nexusAPI = store.get('nexus-api')
let nexus = undefined
createNexus()
let bepinexFolderPath = `${silksongPath}/BepInEx`
let bepinexBackupPath = `${silksongPath}/BepInEx-Backup`
@@ -65,6 +70,20 @@ ipcMain.handle('load-path', () => {
return silksongPath;
});
ipcMain.handle('load-nexus-api', () => {
nexusAPI = store.get('nexus-api');
if (nexusAPI == undefined) {
return "";
}
return nexusAPI;
});
ipcMain.handle('save-nexus-api', (event, api) => {
nexusAPI = api;
createNexus()
store.set('nexus-api', nexusAPI);
});
function saveBepinexVersion(version) {
bepinexVersion = version;
if (bepinexVersion == undefined) {
@@ -280,4 +299,34 @@ ipcMain.handle('delete-bepinex-backup', async () => {
await fs.rm(bepinexBackupPath, { recursive: true })
saveBepinexBackupVersion(undefined)
}
})
})
async function createNexus() {
if (nexusAPI == undefined) {
return
}
try {
nexus = await Nexus.create(
nexusAPI,
'silk-fly-launcher',
'1.0.0',
'hollowknightsilksong'
);
} catch (error) {
nexus = undefined
}
}
ipcMain.handle('verify-nexus-api', async () => {
return await verifyNexusAPI()
})
async function verifyNexusAPI() {
if (nexus == undefined) {
return false
}
if (await nexus.getValidationResult()) {
return true
}
}