presenton/electron/app/ipc/read_file.ts
2026-02-20 12:02:23 +05:45

15 lines
No EOL
453 B
TypeScript

import { ipcMain } from "electron";
import fs from "fs";
import path from "path";
export function setupReadFile() {
ipcMain.handle("read-file", async (_, filePath: string) => {
try {
const normalizedPath = path.normalize(filePath);
const content = fs.readFileSync(normalizedPath, 'utf-8');
return { content };
} catch (error) {
console.error('Error reading file:', error);
throw error;
}
});
}