老师 我关闭的时候,执行window-all-closed一次;before-quit好多次;will-quit,quit没有执行

来源:3-3 主进程事件生命周期&创建窗口、获取窗口数量API

unbreakable_全栈

2022-08-29 08:36:24

https://img.mukewang.com/climg/630c09ba09dec97633281904.jpg

老师 我关闭的时候,执行window-all-closed一次;before-quit好多次;will-quit,quit没有执行

相关代码:

// Common.js规范
const { app, BrowserWindow } = require('electron')

// 主进程
const createWindow = () => {
const win = new BrowserWindow({
width:810,
height: 600
});

win.loadFile('index.html')

// win.webContents.openDevTools() // 写上这句代码之后,可以在npm run start启动项目之后,就打开控制台。
}

app.on('window-all-closed', () => {
console.log('window-all-closed')
app.quit()
})

app.on('will-finish-launching', () => {
console.log('will-finish-launching')
})
app.on('ready', () => {
console.log('ready')
})
app.on('will-quit', () => {
console.log('will-quit')
})
app.on('before-quit', () => {
console.log('before-quit')
app.quit()
})
app.on('quit', () => {
console.log('quit')
})

app.whenReady().then(createWindow)


写回答

1回答

Brian

2022-08-29

你看看你是不是在vscode中启动了多个进程,所以可能是开了多个窗口~

0
hnbreakable_全栈
hp>老师 我找到原因啦 是因为这里多了个 

app.on('before-quit', () => { console.log('before-quit') app.quit() })

 删除掉app.quit()即可

h022-08-30
共2条回复

大前端2022版

1个业务场景打通全端、全栈、全流程,实现全局思维与综合技术能力全面突破;对标阿里P6,8个月成为前端高级人才

2840 学习 · 691 问题

查看课程