Kaynağa Gözat

fix: 修复多次运行仿真测试返回多次响应的问题

HeWang 9 ay önce
ebeveyn
işleme
c37023bac0
1 değiştirilmiş dosya ile 12 ekleme ve 9 silme
  1. 12 9
      electron/preload.js

+ 12 - 9
electron/preload.js

@@ -35,16 +35,19 @@ contextBridge.exposeInMainWorld('electronAPI', {
     },
     onDockerImportResponse: (callback) => ipcRenderer.on('docker-import-response', callback),
     runSimulation: async (obstacle_flag, default_start_flag, default_end_flag, start_point, end_point) => {
-        // ipcRenderer.send('run-simulation', {obstacle_flag, default_start_flag, default_end_flag, start_point, end_point});
-        try {
-            const result = ipcRenderer.invoke('run-simulation', {obstacle_flag, default_start_flag, default_end_flag, start_point, end_point});
-            return result;
-        } catch (error) {
-            console.error('执行仿真测试出错:', error);
-            throw error;
-        }
+        // 异步
+        ipcRenderer.send('run-simulation', {obstacle_flag, default_start_flag, default_end_flag, start_point, end_point});
+
+        // 同步
+        // try {
+        //     const result = ipcRenderer.invoke('run-simulation', {obstacle_flag, default_start_flag, default_end_flag, start_point, end_point});
+        //     return result;
+        // } catch (error) {
+        //     console.error('执行仿真测试出错:', error);
+        //     throw error;
+        // }
     },
-    onRunSimulationResponse: (callback) => ipcRenderer.on('run-simulation-response', callback),
+    onRunSimulationResponse: (callback) => ipcRenderer.once('run-simulation-response', callback),
     generateWorld: (rosbag_path) => {
         // 发送事件到主进程
         ipcRenderer.send('generate-world', {rosbag_path});