Enable nodeIntegration and put "fs" in window

This commit is contained in:
Quinten Kock 2025-11-24 22:07:44 +01:00
parent 4edac451e4
commit 990ae9a7da
3 changed files with 10 additions and 3 deletions

View File

@ -25,6 +25,8 @@ const createWindow = () => {
height: 720, height: 720,
webPreferences: { webPreferences: {
preload: path.join(__dirname, "preload.js"), preload: path.join(__dirname, "preload.js"),
nodeIntegration: true,
contextIsolation: false,
}, },
icon: "./resources/icon.png", icon: "./resources/icon.png",
}); });

View File

@ -3,6 +3,11 @@
import { contextBridge, ipcRenderer } from "electron"; import { contextBridge, ipcRenderer } from "electron";
import type { FolderTree } from "./types/global"; import type { FolderTree } from "./types/global";
import fs from "fs";
import * as pty from "node-pty";
window.fs = fs;
window.pty = pty;
// Centralized routing for terminal events: keep a single ipcRenderer listener // Centralized routing for terminal events: keep a single ipcRenderer listener
// and forward events to subscribed callbacks. Each `onTerminal*` returns an // and forward events to subscribed callbacks. Each `onTerminal*` returns an
@ -23,7 +28,7 @@ ipcRenderer.on("terminal:exit", (_ev, id: string, exitCode: number) => {
else console.warn(`No exit callback for terminal ${id}`); else console.warn(`No exit callback for terminal ${id}`);
}); });
contextBridge.exposeInMainWorld("electronAPI", { window.electronAPI = {
openFolder: () => openFolder: () =>
ipcRenderer.invoke("dialog:openFolder") as Promise<FolderTree | null>, ipcRenderer.invoke("dialog:openFolder") as Promise<FolderTree | null>,
@ -91,4 +96,4 @@ contextBridge.exposeInMainWorld("electronAPI", {
terminalExitCallbacks.set(id, callback); terminalExitCallbacks.set(id, callback);
return () => terminalExitCallbacks.delete(id); return () => terminalExitCallbacks.delete(id);
}, },
}); };

View File

@ -55,8 +55,8 @@ declare global {
id: string, id: string,
callback: (exitCode: number) => void, callback: (exitCode: number) => void,
) => () => void; ) => () => void;
removeAllTerminalListeners: () => void;
}; };
fs: typeof import("fs");
} }
} }