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

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

https://img1.sycdn.imooc.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回答

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

  • unbreakable_全栈 提问者 #1

    我查看没有呢

    2022-08-30 21:43:14
  • unbreakable_全栈 提问者 #2

    老师 我找到原因啦 是因为这里多了个 

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

     删除掉app.quit()即可

    2022-08-30 22:06:37
问题已解决,确定采纳
还有疑问,暂不采纳

恭喜解决一个难题,获得1积分~

来为老师/同学的回答评分吧

0 星
请稍等 ...
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号

在线咨询

领取优惠

免费试听

领取大纲

扫描二维码,添加
你的专属老师