import { contextBridge } from "electron";
import { electronAPI } from "@electron-toolkit/preload";
import "electron-log/preload";
import store from "../main/store/store";

// Custom APIs for renderer
interface Api {
  isTest: () => boolean;
}

const api: Api = {
  isTest: (): boolean => store.get("app.isTest") || false,
};

// 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("api", api);
  } catch (error) {
    console.error(error);
  }
} else {
  // @ts-ignore (define in dts)
  window.electron = electronAPI;
  // @ts-ignore (define in dts)
  window.api = api;
}
