const { app, BrowserWindow } = require('electron') const path = require('path') const config = require('../configs/config.js') const isDev = process.env.NODE_ENV === 'development' || !app.isPackaged function createWindow() { const mainWindow = new BrowserWindow({ width: config.window.width, height: config.window.height, autoHideMenuBar: config.window.autoHideMenuBar, // 从配置文件读取 webPreferences: { nodeIntegration: false, contextIsolation: true } }) if (isDev) { // 从配置文件读取 Vite 开发服务器端口 const vitePort = config.vite?.port || 5173 mainWindow.loadURL(`http://${config.vite?.host || 'localhost'}:${vitePort}`) // 根据配置文件决定是否打开调试侧边栏 if (config.devTools.enabled) { mainWindow.webContents.openDevTools() } } else { mainWindow.loadFile(path.join(__dirname, '../dist/index.html')) } } app.whenReady().then(() => { createWindow() app.on('activate', () => { if (BrowserWindow.getAllWindows().length === 0) { createWindow() } }) }) app.on('window-all-closed', () => { if (process.platform !== 'darwin') { app.quit() } })