Repository navigation
Conversation
退出流程在 before-quit 里拦一次、异步清理、再调一次 app.quit()。第二次退出 会关闭所有窗口,而 Electron 在关窗阶段会复位内部退出标记,最后一个窗口关闭后 只触发 window-all-closed(macOS 上该分支什么都不做),不再进入 will-quit, 进程要等 10 秒后的看门狗兜底,期间用户看到的是窗口消失、图标仍在。 清理此时已经完成,在 window-all-closed 里补一次退出调用即可正常收尾。
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
问题
#450:macOS 上用 ⌘Q 退出后,窗口消失了、Dock 图标还在,进程一直没有结束,要等十几秒才被收掉。
原因
退出流程是「
before-quit里preventDefault()→ 异步清理 → 再调一次app.quit()」。第二次
app.quit()会去关闭所有窗口,而 Electron 在关窗阶段会把内部的退出标记(is_quitting_)复位。于是最后一个窗口关闭后,Browser::OnWindowAllClosed()走的是window-all-closed分支(macOS 下该分支不做任何事),不会再进入will-quit,进程就停在这里,只能靠 10 秒看门狗app.exit(1)兜底。临时埋点抓到的日志(dev 分支,打包后运行):
窗口正是在第二步被销毁的,所以此时点 Dock 图标会走
activate重新建窗(#445 里那个cache协议报错就出现在这一步,该问题已由 a8716df 修复)。修复
清理已经完成,在
window-all-closed里补一次app.quit(),退出流程就能继续走到will-quit,正常结束。关联 Issue
Closes #450
验证
electron/main/core/lifecycle.spec.ts:清理顺序、清理期间重复触发不重复清理、关掉最后一个窗口后补一次退出vitest run全量 585 个用例通过