eigent/electron/main/utils/safeWebContentsSend.ts
2025-09-19 13:38:52 +03:00

20 lines
No EOL
605 B
TypeScript

import log from 'electron-log'
import { getMainWindow } from "../init";
/**
* Safely send message to main window if it exists and is not destroyed
* @param channel - The IPC channel to send message to
* @param data - The data to send
*/
function safeMainWindowSend(channel: string, data?: any) {
const mainWindow = getMainWindow();
if (mainWindow && !mainWindow.isDestroyed()) {
mainWindow.webContents.send(channel, data);
return true;
} else {
log.warn(`[WEBCONTENTS SEND] Cannot send message to main window: ${channel}`, data);
return false;
}
}
export {safeMainWindowSend}