修改
This commit is contained in:
@ -4,10 +4,12 @@ import {electronApp, optimizer, is} from '@electron-toolkit/utils'
|
||||
import icon from '../../resources/earth.png?asset'
|
||||
import {Recorder} from "../preload/recorder";
|
||||
import fs from 'fs'
|
||||
import {exec} from 'child_process'
|
||||
import { exec, spawn } from 'child_process'
|
||||
import dayjs from 'dayjs'
|
||||
import {GetHomeDir} from './config'
|
||||
import {start, getServer} from "./app";
|
||||
import os from "os";
|
||||
import { GetHomeDir } from './config'
|
||||
import { start, getServer } from "./app";
|
||||
const yaml = require("js-yaml");
|
||||
|
||||
|
||||
// 开发环境路径处理 - 确保添加正确的file协议
|
||||
@ -114,13 +116,28 @@ function createWindow(): void {
|
||||
allowRunningInsecureContent: true
|
||||
}
|
||||
})
|
||||
let ymlBatPath = process.env.NODE_ENV === 'development' ? path.resolve(app.getAppPath(), 'resources', 'java', 'app', 'application.yml') : path.join(process.resourcesPath, 'app.asar.unpacked', 'resources', 'java', 'app', 'application.yml')
|
||||
ymlBatPath = process.platform === 'win32' ? ymlBatPath.replace(/^(\w:)/, '/$1') : ymlBatPath
|
||||
ipcMain.on("getIniConfig", (event, option) => {
|
||||
let ymlPath = ymlBatPath.substring(1, 200)
|
||||
console.log("iniPath", ymlPath);
|
||||
|
||||
const ymlContent = yaml.load(fs.readFileSync(ymlPath, 'utf8'));
|
||||
|
||||
if(option) {
|
||||
ymlContent.server.port = option.port
|
||||
fs.writeFileSync(ymlPath, yaml.dump(ymlContent));
|
||||
}
|
||||
|
||||
event.sender.send("YmlConfig", ymlContent);
|
||||
});
|
||||
ipcMain.on("restart", () => {
|
||||
// app.relaunch();
|
||||
// app.quit();
|
||||
// cleanupProcess.kill();
|
||||
// app.relaunch();
|
||||
isRestart = true
|
||||
windowAllClosed()
|
||||
closeAllWindows()
|
||||
});
|
||||
// 监听启动页完成的消息
|
||||
ipcMain.on('splash-completed', () => {
|
||||
@ -259,11 +276,6 @@ function createWindow(): void {
|
||||
|
||||
event.sender.send("dirFiles", data);
|
||||
});
|
||||
ipcMain.on("restart", (e) => {
|
||||
closeChild();
|
||||
app.relaunch();
|
||||
app.exit();
|
||||
});
|
||||
|
||||
let _winMap = new Map();
|
||||
// 监听渲染进程创建新窗口的请求
|
||||
@ -294,6 +306,45 @@ function createWindow(): void {
|
||||
ipcMain.handle('get-_winMap', () => {
|
||||
return _winMap
|
||||
})
|
||||
ipcMain.on("openFFPlay", (e, obj) => {
|
||||
let cmd = "";
|
||||
let platform = os.platform();
|
||||
if (platform === "win32") {
|
||||
cmd = "ffplay.exe";
|
||||
} else {
|
||||
cmd = "ffplay";
|
||||
}
|
||||
let title = obj.name;
|
||||
let child = spawn(
|
||||
path.join(GetHomeDir(), `/ffplay/${cmd}`),
|
||||
[
|
||||
"-window_title",
|
||||
title,
|
||||
"-x",
|
||||
"1300",
|
||||
"-y",
|
||||
"730",
|
||||
"-rtsp_transport",
|
||||
"tcp",
|
||||
obj.url,
|
||||
],
|
||||
{
|
||||
cwd: path.join(GetHomeDir(), "/ffplay/"),
|
||||
stdio: "ignore",
|
||||
// shell: true,
|
||||
}
|
||||
).on("exit", (err) => {
|
||||
console.log("out");
|
||||
console.log(err);
|
||||
e.sender.send("openFFPlayOut", err);
|
||||
});
|
||||
|
||||
/* .on("stdout", function(err, m) {
|
||||
console.log(m);
|
||||
});*/
|
||||
console.log("child", child.pid);
|
||||
child.unref();
|
||||
});
|
||||
// 设置窗口标题和图标
|
||||
mainWindow.webContents.setWindowOpenHandler((details) => {
|
||||
shell.openExternal(details.url)
|
||||
@ -404,7 +455,7 @@ function windowAllClosed() {
|
||||
console.log('所有窗口已关闭,执行清理脚本...');
|
||||
getServer().close(() => {
|
||||
// 执行批处理文件
|
||||
const cleanupProcess = exec(stopBatPath.substring(1, 200), (error, stdout, stderr) => {
|
||||
const cleanupProcess = exec('D:/project/electron-4.0/electron-4/resources/java/stop.bat', (error, stdout, stderr) => {
|
||||
if (error) {
|
||||
console.error(`清理脚本执行失败: ${error.message}`);
|
||||
}
|
||||
@ -414,17 +465,14 @@ function windowAllClosed() {
|
||||
if (stdout) {
|
||||
console.log(`清理脚本输出: ${stdout}`);
|
||||
}
|
||||
|
||||
// 脚本执行完成后强制退出
|
||||
forceQuit();
|
||||
if (isQuitting) {
|
||||
forceQuit();
|
||||
}
|
||||
});
|
||||
|
||||
// 监听子进程退出事件(确保即使脚本出错也能退出)
|
||||
cleanupProcess.on('exit', (code) => {
|
||||
console.log(`清理脚本退出,代码: ${code}`);
|
||||
if (isQuitting) {
|
||||
forceQuit();
|
||||
}
|
||||
});
|
||||
|
||||
// 超时保护:防止脚本卡住导致应用无法退出
|
||||
@ -434,7 +482,7 @@ function windowAllClosed() {
|
||||
cleanupProcess.kill(); // 终止卡住的脚本
|
||||
forceQuit();
|
||||
}
|
||||
}, 2000); // 2秒超时
|
||||
}, 3000); // 3秒超时
|
||||
})
|
||||
}
|
||||
|
||||
@ -447,19 +495,34 @@ function forceQuit() {
|
||||
// isRestart = false
|
||||
// app.relaunch();
|
||||
// }
|
||||
let child = exec('taskkill /F /T /PID ' + process.pid, (error) => {
|
||||
if (error) console.error('强制终止失败:', error);
|
||||
child.kill();
|
||||
});
|
||||
// let child = exec('taskkill /F /T /PID ' + process.pid, (error) => {
|
||||
// if (error) console.error('强制终止失败:', error);
|
||||
// child.kill();
|
||||
// });
|
||||
if (isRestart) {
|
||||
app.relaunch();
|
||||
}
|
||||
console.log('------退出-------');
|
||||
app.exit();
|
||||
app.quit();
|
||||
} else {
|
||||
// 其他系统
|
||||
process.exit(0);
|
||||
}
|
||||
}
|
||||
|
||||
function closeAllWindows() {
|
||||
// 1. 获取所有已打开的窗口
|
||||
const allWindows = BrowserWindow.getAllWindows();
|
||||
|
||||
// 2. 遍历关闭每个窗口
|
||||
allWindows.forEach(window => {
|
||||
if (!window.isDestroyed()) { // 避免操作已销毁的窗口(防止报错)
|
||||
window.close();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
console.log('=================================================')
|
||||
global.sharedObject = {
|
||||
hasService: false,
|
||||
|
||||
Reference in New Issue
Block a user