const { app, BrowserWindow } = require('electron'); const path = require('path'); const url = require('url'); let win = null; // 创建窗口 const createWindow = () => { win = new BrowserWindow({ // width: 1200, // height: 800, show: false, // 是否显示窗口 autoHideMenuBar: true, // 隐藏菜单栏 webPreferences: { nodeIntegration: true, // 是否集成 Node.js // enableRemoteModule: true, // 是否启用 remote 模块 webSecurity: false, // 是否禁用同源策略 preload: path.join(__dirname, 'preload.js'), // 预加载脚本 }, }); win.loadURL( url.format({ pathname: path.join(__dirname, './dist', 'index.html'), protocol: 'file:', slashes: true, // true: file://, false: file: hash: '/login', }), ); win.once('ready-to-show', () => { win.maximize(); win.show(); }); }; // 当 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(); } });