| 123456789101112131415161718192021222324252627282930313233343536373839404142 |
- const { app, BrowserWindow } = require('electron')
- const path = require('path')
- const config = require('../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) {
- mainWindow.loadURL('http://localhost:5173')
- // 根据配置文件决定是否打开调试侧边栏
- 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()
- }
- })
|