2025-03-21 14:30:13 +00:00
|
|
|
import { BrowserWindow, IpcMainInvokeEvent, ipcMain } from "electron";
|
|
|
|
|
import { FsJob, FsJobHandler } from "./fsjob.js";
|
2025-04-07 03:30:47 +00:00
|
|
|
import { ModLoader } from "./mods/loader.js";
|
2025-03-21 14:30:13 +00:00
|
|
|
|
|
|
|
|
export class IpcHandler {
|
2025-06-10 09:15:38 +00:00
|
|
|
private readonly savesHandler = new FsJobHandler("saves");
|
2025-04-07 03:30:47 +00:00
|
|
|
private readonly modLoader: ModLoader;
|
2025-03-21 14:30:13 +00:00
|
|
|
|
2025-04-14 22:57:00 +00:00
|
|
|
constructor(modLoader: ModLoader) {
|
2025-04-07 03:30:47 +00:00
|
|
|
this.modLoader = modLoader;
|
2025-03-21 14:30:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
install(window: BrowserWindow) {
|
|
|
|
|
ipcMain.handle("fs-job", this.handleFsJob.bind(this));
|
|
|
|
|
ipcMain.handle("get-mods", this.getMods.bind(this));
|
|
|
|
|
ipcMain.handle("set-fullscreen", this.setFullscreen.bind(this, window));
|
|
|
|
|
|
|
|
|
|
// Not implemented
|
|
|
|
|
// ipcMain.handle("open-mods-folder", ...)
|
|
|
|
|
}
|
|
|
|
|
|
2025-06-10 09:15:38 +00:00
|
|
|
private handleFsJob(_event: IpcMainInvokeEvent, job: FsJob) {
|
2025-04-14 22:57:00 +00:00
|
|
|
if (job.id !== "saves") {
|
|
|
|
|
throw new Error("Storages other than saves/ are not implemented yet");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return this.savesHandler.handleJob(job);
|
2025-03-21 14:30:13 +00:00
|
|
|
}
|
|
|
|
|
|
2025-04-07 03:30:47 +00:00
|
|
|
private async getMods() {
|
|
|
|
|
// TODO: Split mod reloads into a different IPC request
|
|
|
|
|
await this.modLoader.loadMods();
|
|
|
|
|
return this.modLoader.getAllMods();
|
2025-03-21 14:30:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private setFullscreen(window: BrowserWindow, _event: IpcMainInvokeEvent, flag: boolean) {
|
2025-04-05 22:41:56 +00:00
|
|
|
if (window.isFullScreen() != flag) {
|
|
|
|
|
window.setFullScreen(flag);
|
|
|
|
|
}
|
2025-03-21 14:30:13 +00:00
|
|
|
}
|
|
|
|
|
}
|