import { electronAPI } from '@electron-toolkit/preload';
import { contextBridge, ipcRenderer } from 'electron';

if (process.contextIsolated) {
  try {
    contextBridge.exposeInMainWorld('electron', electronAPI);
    contextBridge.exposeInMainWorld('relay', {
      start: (encryptionKey: string) => ipcRenderer.invoke('relay:start', encryptionKey),
      stop: () => ipcRenderer.invoke('relay:stop'),
      getStatus: () => ipcRenderer.invoke('relay:status'),
      getLogs: () => ipcRenderer.invoke('relay:logs'),
      reset: () => ipcRenderer.invoke('relay:reset'),
    });
  } catch (error) {
    console.error(error);
  }
} else {
  // @ts-ignore (define in dts)
  window.electron = electronAPI;
}
