/*
 * 如果启用了上下文隔离，渲染进程无法使用electron的api，
 * 可通过contextBridge 导出api给渲染进程使用
 */

const { contextBridge, ipcRenderer } = require("electron");
const os = require("os");
const path = require("path");
const isDev = process.env.NODE_ENV === "development";

contextBridge.exposeInMainWorld("electronApi", {
  getComputerName: () => {
    return os.hostname();
  },
  changeWinSize: (type: "big" | "small") => {
    ipcRenderer.send("change-win-size", type);
  },
  windowMin: () => {
    ipcRenderer.send("window-min");
  },
  startScanExe: () => {
    let scanExeFold: string = isDev
      ? process.cwd()
      : process.env.PORTABLE_EXECUTABLE_DIR || "";
    const exePath = path.join(scanExeFold as string, "test.exe");
    console.log("exePath", exePath);
    ipcRenderer.send("startExe", exePath + " 参数1 参数2 参数3");
  },
});
