// src/main/ipc/renderer-broadcast.ts // 메인/전체 렌더러 창으로 안전하게 IPC 이벤트를 송신하는 공용 헬퍼. import { BrowserWindow } from 'electron' import { getMainWindow } from '../windows/WindowManager' function canSendToWindow(win: BrowserWindow | null | undefined): win is BrowserWindow { if (!win || win.isDestroyed()) return false const contents = win.webContents as { isDestroyed?: () => boolean } | undefined if (!contents) return false return typeof contents.isDestroyed === 'function' ? !contents.isDestroyed() : true } /** 메인 창이 살아 있을 때만 IPC 채널로 데이터를 전송한다. */ export function safeSendToRenderer(channel: string, data: unknown): void { const win = getMainWindow() if (canSendToWindow(win)) { win.webContents.send(channel, data) } } /** 파괴되지 않은 모든 BrowserWindow 렌더러에 IPC 이벤트를 브로드캐스트한다. */ export function broadcastToAllWindows(channel: string, payload: unknown): void { for (const win of BrowserWindow.getAllWindows()) { if (canSendToWindow(win)) { win.webContents.send(channel, payload) } } }