const { app, BrowserWindow } = require('electron'); const path = require('path'); let win; function createWindow() { win = new BrowserWindow({ width: 500, height: 400, webPreferences: { nodeIntegration: false, contextIsolation: true, preload: path.join(__dirname, 'preload.js') } }); win.loadFile('index.html'); // 打开开发者工具方便调试 // win.webContents.openDevTools(); } app.whenReady().then(createWindow); app.on('window-all-closed', () => { if (process.platform !== 'darwin') { app.quit(); } }); app.on('activate', () => { if (BrowserWindow.getAllWindows().length === 0) { createWindow(); } });