提交
This commit is contained in:
@ -7,7 +7,7 @@ import fs from 'fs'
|
||||
import { exec } from 'child_process'
|
||||
import dayjs from 'dayjs'
|
||||
import { GetHomeDir } from './config'
|
||||
import { start } from "./app";
|
||||
import { start, getServer } from "./app";
|
||||
|
||||
|
||||
// 开发环境路径处理 - 确保添加正确的file协议
|
||||
@ -57,9 +57,9 @@ if (prodSplashPath) {
|
||||
|
||||
// 最终的启动页URL
|
||||
const splashURL = process.env.NODE_ENV === 'development' ? devSplashURL : prodSplashURL
|
||||
let startBatPath = path.join(process.resourcesPath, 'app.asar.unpacked', 'resources', 'java', 'start.bat')
|
||||
let startBatPath = process.env.NODE_ENV === 'development' ? path.resolve(app.getAppPath(), 'resources', 'java', 'start.bat') : path.join(process.resourcesPath, 'app.asar.unpacked', 'resources', 'java', 'start.bat')
|
||||
startBatPath = process.platform === 'win32' ? startBatPath.replace(/^(\w:)/, '/$1') : startBatPath
|
||||
let stopBatPath = path.join(process.resourcesPath, 'app.asar.unpacked', 'resources', 'java', 'stop.bat')
|
||||
let stopBatPath = process.env.NODE_ENV === 'development' ? path.resolve(app.getAppPath(), 'resources', 'java', 'stop.bat') : path.join(process.resourcesPath, 'app.asar.unpacked', 'resources', 'java', 'stop.bat')
|
||||
stopBatPath = process.platform === 'win32' ? stopBatPath.replace(/^(\w:)/, '/$1') : stopBatPath
|
||||
|
||||
// const splashURL =
|
||||
@ -126,7 +126,7 @@ function createWindow(): void {
|
||||
}, 1000)
|
||||
})
|
||||
ipcMain.on('quit-app', () => {
|
||||
app.quit()
|
||||
windowAllClosed()
|
||||
})
|
||||
ipcMain.on('renderNode', () => {
|
||||
// 获取所有窗口并转发消息
|
||||
@ -254,7 +254,7 @@ function createWindow(): void {
|
||||
ipcMain.handle('show-window-by-id', async (event, id) => {
|
||||
BrowserWindow.fromId(id)?.show()
|
||||
})
|
||||
ipcMain.handle('get-_winMap',()=>{
|
||||
ipcMain.handle('get-_winMap', () => {
|
||||
return _winMap
|
||||
})
|
||||
// 设置窗口标题和图标
|
||||
@ -332,36 +332,89 @@ app.whenReady().then(() => {
|
||||
// Quit when all windows are closed, except on macOS. There, it's common
|
||||
// for applications and their menu bar to stay active until the user quits
|
||||
// explicitly with Cmd + Q.
|
||||
app.on('window-all-closed', () => {
|
||||
console.log('=================================================111111111', process.platform)
|
||||
if (process.platform !== 'darwin') {
|
||||
app.quit()
|
||||
}
|
||||
})
|
||||
// app.on('window-all-closed', () => {
|
||||
// if (process.platform !== 'darwin') {
|
||||
// getServer().close(() => {
|
||||
// // 关闭后台服务
|
||||
// exec(stopBatPath.substring(1, 200), () => {
|
||||
// app.quit()
|
||||
// });
|
||||
// })
|
||||
// }
|
||||
// })
|
||||
// 退出时注销所有快捷键
|
||||
app.on('will-quit', () => {
|
||||
console.log('222222222222222222222')
|
||||
// 关闭后台服务
|
||||
exec(stopBatPath.substring(1, 200), (error, stdout, stderr) => {
|
||||
dialog.showMessageBox({
|
||||
type: 'info',
|
||||
title: '信息1',
|
||||
message: 'process.platform',
|
||||
buttons: ['确定']
|
||||
})
|
||||
if (error) {
|
||||
console.error(`执行错误: ${error.message}`);
|
||||
return;
|
||||
}
|
||||
if (stderr) {
|
||||
console.error(`错误输出: ${stderr}`);
|
||||
return;
|
||||
}
|
||||
console.log(`批处理输出: ${stdout}`);
|
||||
});
|
||||
globalShortcut.unregisterAll()
|
||||
})
|
||||
|
||||
// 用于跟踪是否正在执行退出流程
|
||||
let isQuitting = false;
|
||||
|
||||
app.on('window-all-closed', () => {
|
||||
windowAllClosed()
|
||||
});
|
||||
|
||||
function windowAllClosed() {
|
||||
// 防止重复触发退出流程
|
||||
if (isQuitting) return;
|
||||
isQuitting = true;
|
||||
|
||||
// macOS特殊处理(保持应用活跃)
|
||||
if (process.platform === 'darwin') {
|
||||
return;
|
||||
}
|
||||
|
||||
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}`);
|
||||
}
|
||||
|
||||
// 脚本执行完成后强制退出
|
||||
forceQuit();
|
||||
});
|
||||
|
||||
// 监听子进程退出事件(确保即使脚本出错也能退出)
|
||||
cleanupProcess.on('exit', (code) => {
|
||||
console.log(`清理脚本退出,代码: ${code}`);
|
||||
if (isQuitting) {
|
||||
forceQuit();
|
||||
}
|
||||
});
|
||||
|
||||
// 超时保护:防止脚本卡住导致应用无法退出
|
||||
setTimeout(() => {
|
||||
if (isQuitting) {
|
||||
console.log('清理脚本执行超时,强制退出');
|
||||
cleanupProcess.kill(); // 终止卡住的脚本
|
||||
forceQuit();
|
||||
}
|
||||
}, 2000); // 2秒超时
|
||||
})
|
||||
}
|
||||
|
||||
// 强制退出应用的辅助函数
|
||||
function forceQuit() {
|
||||
// 终止所有剩余的子进程
|
||||
if (process.platform === 'win32') {
|
||||
// Windows系统特殊处理
|
||||
exec('taskkill /F /T /PID ' + process.pid, (error) => {
|
||||
if (error) console.error('强制终止失败:', error);
|
||||
});
|
||||
} else {
|
||||
// 其他系统
|
||||
process.exit(0);
|
||||
}
|
||||
}
|
||||
|
||||
console.log('=================================================')
|
||||
global.sharedObject = {
|
||||
hasService: false,
|
||||
|
||||
Reference in New Issue
Block a user