const { app, BrowserWindow } = require('electron'); const path = require('path'); const url = require('url'); // 创建窗口 const createWindow = () => { const win = new BrowserWindow({ width: 1200, height: 800, autoHideMenuBar: true, // 隐藏菜单栏 webPreferences: { nodeIntegration: true, // 是否集成 Node.js enableRemoteModule: true, // 是否启用 remote 模块 webSecurity: false, // 是否禁用同源策略 }, }); win.loadURL( url.format({ pathname: path.join(__dirname, './dist', 'index.html'), protocol: 'file:', slashes: true, // true: file://, false: file: hash: '/login', }), ); }; // 当 Electron 完成初始化并准备创建浏览器窗口时调用此方法 app.whenReady().then(() => { createWindow(); app.on('activate', () => { if (BrowserWindow.getAllWindows().length === 0) { createWindow(); } }); }); // 当所有窗口都已关闭时退出 app.on('window-all-closed', () => { if (process.platform !== 'darwin') { app.quit(); } }); app.on('activate', () => { if (BrowserWindow.getAllWindows().length === 0) { createWindow(); } });