// ============================================================ // 日志 IPC 通道注册 — 主进程接收渲染进程日志 // ============================================================ import { ipcMain } from 'electron'; import { RENDERER_TO_MAIN } from '../../../shared/constants/ipc/base'; import { writeRendererLog } from '../logger'; import type { LogEntry } from '../../../shared/types/logging'; /** * 注册日志 IPC 监听器 * 使用 ipcMain.on(fire-and-forget)而非 handle(无需响应) * 在 app.whenReady() 中调用 */ export function registerLogIpcHandlers(): void { ipcMain.on(RENDERER_TO_MAIN.LOG_MESSAGE, (_event, entry: LogEntry) => { // 基础校验:防御渲染进程异常数据 if (!entry || !entry.level || !entry.category || !entry.message) return; writeRendererLog(entry); }); }