This commit is contained in:
zh
2025-11-05 18:24:35 +08:00
parent 318b0fc8ce
commit d6fb3b57e2
30 changed files with 580 additions and 340 deletions

View File

@ -72,6 +72,7 @@ stopBatPath = process.platform === 'win32' ? stopBatPath.replace(/^(\w:)/, '/$1'
// ? `${join(app.getAppPath(), 'src/renderer/public/startUp/startUp.html')}`
// : `file://${join(app.getAppPath(), 'resources/app.asar/out/renderer/startUp/startUp.html')}`
let isRestart = false
let mainWindow;
function createWindow(): void {
// Create the browser window.
@ -98,10 +99,10 @@ function createWindow(): void {
splashWindow.loadURL(splashURL)
splashWindow.show()
// 创建主窗口(保持原有配置,但先不显示)
const mainWindow = new BrowserWindow({
// minWidth: 1780, // 添加最小宽度限制
// minHeight: 920, // 添加最小高度限制
// fullscreen: true,
mainWindow = new BrowserWindow({
minWidth: 1280, // 添加最小宽度限制
minHeight: 768, // 添加最小高度限制
fullscreen: true,
show: false,
frame: true,
autoHideMenuBar: true,
@ -429,77 +430,9 @@ function createWindow(): void {
}
}
// This method will be called when Electron has finished
// initialization and is ready to create browser windows.
// Some APIs can only be used after this event occurs.
app.whenReady().then(() => {
// alert(devSplashURL)
// alert(prodSplashURL)
// dialog.showMessageBox({
// type: 'info',
// title: '信息1',
// message: devSplashURL,
// buttons: ['确定']
// })
// 执行批处理文件
exec(startBatPath.substring(1, 200), (error, stdout, stderr) => {
if (error) {
console.error(`执行错误: ${error.message}`);
return;
}
if (stderr) {
console.error(`错误输出: ${stderr}`);
return;
}
console.log(`批处理输出: ${stdout}`);
});
// Set app user model id for windows
electronApp.setAppUserModelId('com.electron')
// Default open or close DevTools by F12 in development
// and ignore CommandOrControl + R in production.
// see https://github.com/alex8088/electron-toolkit/tree/master/packages/utils
app.on('browser-window-created', (_, window) => {
optimizer.watchWindowShortcuts(window)
})
// IPC test
ipcMain.on('ping', () => console.log('pong'))
createWindow()
app.on('activate', function () {
// On macOS it's common to re-create a window in the app when the
// dock icon is clicked and there are no other windows open.
if (BrowserWindow.getAllWindows().length === 0) createWindow()
})
})
// 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', () => {
// if (process.platform !== 'darwin') {
// getServer().close(() => {
// // 关闭后台服务
// exec(stopBatPath.substring(1, 200), () => {
// app.quit()
// });
// })
// }
// })
// 退出时注销所有快捷键
app.on('will-quit', () => {
globalShortcut.unregisterAll()
})
// 用于跟踪是否正在执行退出流程
let isQuitting = false;
app.on('window-all-closed', () => {
windowAllClosed()
});
function windowAllClosed() {
// 防止重复触发退出流程
if (isQuitting) return;
@ -581,10 +514,80 @@ function closeAllWindows() {
});
}
console.log('=================================================')
global.sharedObject = {
hasService: false,
};
const gotTheLock = app.requestSingleInstanceLock();
if (!gotTheLock) {
app.quit();
} else {
if (app.isReady()) {
}
app.whenReady().then(() => {
// alert(devSplashURL)
// alert(prodSplashURL)
// dialog.showMessageBox({
// type: 'info',
// title: '信息1',
// message: devSplashURL,
// buttons: ['确定']
// })
// 执行批处理文件
exec(startBatPath.substring(1, 200), (error, stdout, stderr) => {
if (error) {
console.error(`执行错误: ${error.message}`);
return;
}
if (stderr) {
console.error(`错误输出: ${stderr}`);
return;
}
console.log(`批处理输出: ${stdout}`);
});
// Set app user model id for windows
electronApp.setAppUserModelId('com.electron')
// Default open or close DevTools by F12 in development
// and ignore CommandOrControl + R in production.
// see https://github.com/alex8088/electron-toolkit/tree/master/packages/utils
app.on('browser-window-created', (_, window) => {
optimizer.watchWindowShortcuts(window)
})
// IPC test
ipcMain.on('ping', () => console.log('pong'))
createWindow()
app.on('activate', function () {
// On macOS it's common to re-create a window in the app when the
// dock icon is clicked and there are no other windows open.
if (BrowserWindow.getAllWindows().length === 0) createWindow()
})
})
// 退出时注销所有快捷键
app.on('will-quit', () => {
globalShortcut.unregisterAll()
})
app.on('window-all-closed', () => {
windowAllClosed()
});
app.on("second-instance", () => {
// 当运行第二个实例时,将会聚焦到myWindow这个窗口
if (mainWindow) {
if (mainWindow.isMinimized()) mainWindow.restore();
mainWindow.focus();
}
});
// testNapi()
global.sharedObject = {
hasService: false,
};
}
// In this file you can include the rest of your app's specific main process
// code. You can also put them in separate files and require them here.