12-10
This commit is contained in:
@ -83,7 +83,7 @@ let mainWindow;
|
||||
|
||||
let isSeverInit = false
|
||||
let isAppInit = false
|
||||
let severError:any = undefined
|
||||
let severError: any = undefined
|
||||
function createWindow(): void {
|
||||
// Create the browser window.
|
||||
|
||||
@ -581,35 +581,61 @@ function windowAllClosed() {
|
||||
|
||||
console.log('所有窗口已关闭,执行清理脚本...');
|
||||
getServer().close(() => {
|
||||
// 执行批处理文件
|
||||
const cleanupProcess = exec(stopBatPath.substring(1, 200), (error, stdout, stderr) => {
|
||||
if (error) {
|
||||
console.error(`清理脚本执行失败: ${error.message}`);
|
||||
}
|
||||
if (stderr) {
|
||||
console.error(`清理脚本错误输出: ${stderr}`);
|
||||
}
|
||||
if (stdout) {
|
||||
console.log(`清理脚本输出: ${stdout}`);
|
||||
}
|
||||
if (isQuitting) {
|
||||
forceQuit();
|
||||
}
|
||||
|
||||
|
||||
const vbsScript = `
|
||||
Set WshShell = CreateObject("WScript.Shell")
|
||||
WshShell.Run "${stopBatPath.substring(1, 200)}", 0, False
|
||||
Set WshShell = Nothing
|
||||
`;
|
||||
const vbsPath = path.join(os.tmpdir(), 'run_bat_hidden.vbs');
|
||||
require('fs').writeFileSync(vbsPath, vbsScript, 'utf8');
|
||||
|
||||
// 2. 执行 VBS 脚本(零窗口)
|
||||
const batProcess = spawn('wscript.exe', [vbsPath], {
|
||||
detached: true,
|
||||
stdio: 'ignore',
|
||||
windowsHide: true,
|
||||
});
|
||||
|
||||
// 监听子进程退出事件(确保即使脚本出错也能退出)
|
||||
cleanupProcess.on('exit', (code) => {
|
||||
console.log(`清理脚本退出,代码: ${code}`);
|
||||
});
|
||||
batProcess.unref();
|
||||
|
||||
// 超时保护:防止脚本卡住导致应用无法退出
|
||||
setTimeout(() => {
|
||||
if (isQuitting) {
|
||||
console.log('清理脚本执行超时,强制退出');
|
||||
// cleanupProcess.kill(); // 终止卡住的脚本
|
||||
forceQuit();
|
||||
}
|
||||
}, 3000); // 3秒超时
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// // 执行批处理文件
|
||||
// const cleanupProcess = exec(stopBatPath.substring(1, 200), (error, stdout, stderr) => {
|
||||
// if (error) {
|
||||
// console.error(`清理脚本执行失败: ${error.message}`);
|
||||
// }
|
||||
// if (stderr) {
|
||||
// console.error(`清理脚本错误输出: ${stderr}`);
|
||||
// }
|
||||
// if (stdout) {
|
||||
// console.log(`清理脚本输出: ${stdout}`);
|
||||
// }
|
||||
// if (isQuitting) {
|
||||
// forceQuit();
|
||||
// }
|
||||
// });
|
||||
|
||||
// // 监听子进程退出事件(确保即使脚本出错也能退出)
|
||||
// cleanupProcess.on('exit', (code) => {
|
||||
// console.log(`清理脚本退出,代码: ${code}`);
|
||||
// });
|
||||
|
||||
forceQuit();
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user