import {BrowserWindow} from "electron";
import log from "electron-log/main";

const getMainWindow = (): Electron.BrowserWindow => {
  return BrowserWindow.getAllWindows()[0];
};

const sendIpcToRenderer = (ipcMessage: string, ...args: any[]): void => {
  const window = getMainWindow();
  if (window) {
    window.webContents.send(ipcMessage, ...args);
  } else {
    log.error(
      "Unable to find main window. Cannot send IPC message.",
      ipcMessage,
      args,
    );
  }
};
export { getMainWindow, sendIpcToRenderer };
