preload.mjs 1.3 KB

12345678910111213141516171819202122232425262728293031323334
  1. const { contextBridge, ipcRenderer } = require("electron");
  2. contextBridge.exposeInMainWorld("electronAPI", {
  3. // ✅ 运行 Python 脚本
  4. runPythonExe: async (args) => ipcRenderer.invoke("run-python-exe", args),
  5. callPythonAPI: (apiName, params) =>
  6. ipcRenderer.invoke("run-python-exe", apiName, params),
  7. // ✅ 发送 / 接收消息
  8. sendMessage: (message) => ipcRenderer.send("message", message),
  9. receiveMessage: (callback) => {
  10. ipcRenderer.on("response", (event, data) => callback(data));
  11. },
  12. // ✅ 文件操作
  13. getFilePath: () => ipcRenderer.invoke("get-file-path"),
  14. getInstallPath: () => ipcRenderer.invoke("get-install-path"),
  15. readCsv: (filePath) => ipcRenderer.invoke("read-csv", filePath),
  16. // ✅ 保存 / 读取 提交文件
  17. saveSubmission: (payload) => ipcRenderer.invoke("save-submission", payload),
  18. readTextFile: (filePath) => ipcRenderer.invoke("read-text-file", filePath),
  19. readJsonFile: (filePath) => ipcRenderer.invoke("read-json-file", filePath),
  20. // ✅ 打开文件夹(调用主进程 open-path)
  21. //
  22. openPath: (filePath) => ipcRenderer.invoke("open-path", filePath),
  23. // ✅ 删除单个数据文件夹
  24. deleteFolder: (folderPath) => ipcRenderer.invoke("delete-folder", folderPath),
  25. // ✅ 清空所有数据文件夹
  26. clearAllFolders: () => ipcRenderer.invoke("clear-all-folders"),
  27. });