123456789101112131415161718192021222324 |
- const { contextBridge, ipcRenderer } = require("electron");
- // 使用 contextBridge 暴露渲染进程 API
- contextBridge.exposeInMainWorld("electronAPI", {
- // sendMessage: 用于发送消息到主进程
- sendMessage: (message) => {
- ipcRenderer.send("message", message);
- },
- // runPythonScript: 用于运行 Python 脚本
- runPythonExe: async (args) => {
- return await ipcRenderer.invoke("run-python-exe", args);
- },
- callPythonAPI: (apiName, params) =>
- ipcRenderer.invoke("run-python-exe", apiName, params),
- // 可以考虑增加更多的方法,如接收来自主进程的消息
- receiveMessage: (callback) => {
- ipcRenderer.on("response", (event, data) => {
- callback(data);
- });
- },
- getFilePath: () => ipcRenderer.invoke("get-file-path"), // ✅ 返回数组
- getInstallPath: () => ipcRenderer.invoke("get-install-path"), // ✅ 返回数组
- readCsv: (filePath) => ipcRenderer.invoke("read-csv", filePath),
- });
|