const { app, BrowserWindow } = require('electron') function createWindow() { let mainWin = new BrowserWindow({ width: 600, height: 400 }) mainWin.loadFile('index.html') mainWin.webContents.on('did-finish-load', () => { console.log('3 - did finish load') }) mainWin.webContents.on('dom-ready', () => { console.log('2 - dom ready') }) mainWin.on('close', () => { console.log('8 - win closed') // 多窗口时最后触发 mainWin = null // 删除引用,释放空间 }) } app.on('ready', () => { console.log('1 - ready') createWindow() }) app.on('window-all-closed', () => { console.log('4 - window all closed') app.quit() }) app.on('before-quit', () => { console.log('5 - before quit') }) app.on('will-quit', () => { console.log('6 - will-quit') }) app.on('quit', () => { console.log('7 - quit') })