|
@@ -1,8 +1,9 @@
|
|
|
import {app, BrowserWindow, ipcMain, dialog} from 'electron';
|
|
|
-import {exec} from 'child_process';
|
|
|
+import {exec, spawn} from 'child_process';
|
|
|
import path from 'path';
|
|
|
import {fileURLToPath} from 'url';
|
|
|
|
|
|
+
|
|
|
const __filename = fileURLToPath(import.meta.url);
|
|
|
const __dirname = path.dirname(__filename);
|
|
|
|
|
@@ -19,8 +20,8 @@ function createWindow() {
|
|
|
});
|
|
|
|
|
|
win.webContents.openDevTools(); // 打开开发者工具进行调试
|
|
|
- // win.loadURL('http://localhost:5173'); // 开发环境
|
|
|
- win.loadURL('http://36.110.106.156:81'); // 生产环境
|
|
|
+ win.loadURL('http://localhost:5173'); // 开发环境
|
|
|
+ // win.loadURL('http://36.110.106.156:81'); // 生产环境
|
|
|
console.log('Window created and URL loaded');
|
|
|
}
|
|
|
|
|
@@ -110,33 +111,68 @@ ipcMain.on('docker-import', (event, sudoPassword, filePath, tag) => {
|
|
|
});
|
|
|
});
|
|
|
|
|
|
+// ipcMain.on('generate-world', (event, rosbag_path) => {
|
|
|
+//
|
|
|
+// const serviceScript = 'nonhup bash /home/cicv/work/pji_desktop/run_map2gazabo.sh >/dev/null 2>&1 & '
|
|
|
+// const child1 = exec(serviceScript, (error, stdout, stderr) => {
|
|
|
+// if (error) {
|
|
|
+// console.error(`exec error: ${error}`);
|
|
|
+// return;
|
|
|
+// }
|
|
|
+// console.log(`stdout: ${stdout}`);
|
|
|
+// console.error(`stderr: ${stderr}`);
|
|
|
+//
|
|
|
+// // 启动第二个脚本
|
|
|
+// const script2 = exec('/home/cicv/work/pji_desktop/play_rosbag.sh /home/cicv/work/pji_desktop/map_bag/map_anqing.bag', (error, stdout, stderr) => {
|
|
|
+// if (error) {
|
|
|
+// console.error(`执行第二个脚本时出错: ${error}`);
|
|
|
+// return;
|
|
|
+// }
|
|
|
+// console.log(`第二个脚本的输出: ${stdout}`);
|
|
|
+// });
|
|
|
+// });
|
|
|
+// });
|
|
|
+
|
|
|
ipcMain.on('generate-world', (event, rosbag_path) => {
|
|
|
- // const command = 'sh /home/cicv/work/pji_desktop/run_map2gazabo.sh'
|
|
|
- //
|
|
|
- // exec(command, (error, stdout, stderr) => {
|
|
|
- // if (error) {
|
|
|
- // console.error(`exec error: ${error}`);
|
|
|
- // return;
|
|
|
- // }
|
|
|
- // console.log(`stdout: ${stdout}`);
|
|
|
- // console.error(`stderr: ${stderr}`);
|
|
|
- // });
|
|
|
-
|
|
|
- // 在 Electron 应用启动后执行本地脚本
|
|
|
- const serviceScript = 'sh /home/cicv/work/pji_desktop/run_map2gazabo.sh';
|
|
|
|
|
|
// 使用 spawn 启动脚本
|
|
|
- const serviceProcess = spawn(serviceScript, [], { detached: true });
|
|
|
+ const serviceProcess = spawn('bash', ["/home/cicv/work/pji_desktop/run_map2gazebo.sh"], { detached: true });
|
|
|
|
|
|
// 设置为后台进程
|
|
|
serviceProcess.unref();
|
|
|
|
|
|
// 监听输出
|
|
|
serviceProcess.stdout.on('data', (data) => {
|
|
|
- console.log(`Service output: ${data}`);
|
|
|
+ console.log(`第一个脚本的输出: ${data}`);
|
|
|
+ // 根据第一个脚本的输出判断其是否准备好
|
|
|
+ if (data.toString().includes('Service map2gazebo started')) {
|
|
|
+ startSecondScript();
|
|
|
+ }
|
|
|
});
|
|
|
|
|
|
+ // 监听错误
|
|
|
serviceProcess.stderr.on('data', (data) => {
|
|
|
- console.error(`Service error: ${data}`);
|
|
|
+ console.error(`执行第一个脚本时出错: ${data}`);
|
|
|
+ });
|
|
|
+
|
|
|
+ // 监听关闭
|
|
|
+ serviceProcess.on('close', (data) => {
|
|
|
+ console.log(`第二个脚本已关闭: ${data}`);
|
|
|
});
|
|
|
+
|
|
|
+ function startSecondScript() {
|
|
|
+ // 启动第二个脚本
|
|
|
+ const script2 = exec('bash /home/cicv/work/pji_desktop/play_rosbag.sh /home/cicv/work/pji_desktop/map_bag/map.bag', (error, stdout, stderr) => {
|
|
|
+ if (error) {
|
|
|
+ console.error(`执行第二个脚本时出错: ${error}`);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ console.log(`第二个脚本的输出: ${stdout}`);
|
|
|
+ });
|
|
|
+
|
|
|
+ script2.on('exit', (code) => {
|
|
|
+ console.log(`第二个脚本已退出,退出码: ${code}`);
|
|
|
+ });
|
|
|
+ }
|
|
|
});
|
|
|
+
|