// main/ipc/files.js const { ipcMain } = require('electron') const fsp = require('node:fs/promises') const { normalizePath } = require('../utils/paths') function registerFileIpc() { ipcMain.removeHandler('file-exists') ipcMain.handle('file-exists', async (_evt, targetPath, baseDir) => { try { const full = normalizePath(targetPath, baseDir) const stat = await fsp.stat(full).catch(err => (err?.code === 'ENOENT' ? null : Promise.reject(err))) if (!stat) return { ok: true, exists: false, path: full } return { ok: true, exists: true, path: full, isFile: stat.isFile(), isDirectory: stat.isDirectory(), size: stat.size, mtimeMs: stat.mtimeMs } } catch (e) { return { ok: false, error: e.message || String(e) } } }) } module.exports = { registerFileIpc }