import { contextBridge } from 'electron';
import electronApi from './apiElectron';
import dbApi from './apiDb';
import api from './api';

// Use `contextBridge` APIs to expose Electron APIs to
// renderer only if context isolation is enabled, otherwise
// just add to the DOM global.
if (process.contextIsolated) {
  try {
    contextBridge.exposeInMainWorld('electron', electronApi);
    contextBridge.exposeInMainWorld('db', dbApi);
    contextBridge.exposeInMainWorld('api', api);
  } catch (error) {
    console.error(error);
  }
} else {
  // @ts-ignore (define in dts)
  window.electron = electronApi;
  // @ts-ignore (define in dts)
  window.db = dbApi;
  // @ts-ignore (define in dts)
  window.api = api;
}
