Repository navigation
fix(macos): Close the windows through AppWindow.Closing when the app is asked to quit - #26063
Conversation
|
🤖 Your WebAssembly Sample App stage site is ready! Visit it here: |
|
🤖 Your WebAssembly Sample App stage site is ready! Visit it here: |
|
🤖 Your Docs stage site is ready! Visit it here: https://unodocsprstaging.z13.web.core.windows.net/pr-26063/docs/index.html |
|
🤖 Your WebAssembly Sample App stage site is ready! Visit it here: |
|
🤖 Your WebAssembly Sample App stage site is ready! Visit it here: |
|
The build 243820 found UI Test snapshots differences: Details
|
|
🤖 Your Docs stage site is ready! Visit it here: https://unodocsprstaging.z13.web.core.windows.net/pr-26063/docs/index.html |
|
🤖 Your WebAssembly Sample App stage site is ready! Visit it here: |
|
The build 243839 found UI Test snapshots differences: Details
|
f5a3cc4 to
bb777ca
Compare
|
🤖 Your WebAssembly Sample App stage site is ready! Visit it here: |
|
🤖 Your Docs stage site is ready! Visit it here: https://unodocsprstaging.z13.web.core.windows.net/pr-26063/docs/index.html |
|
The build 243917 found UI Test snapshots differences: Details
|
|
This pull request does not currently match the merge queue conditions, so it cannot be queued from here. The box comes back if it matches again. |
fix(macos): Close the windows through AppWindow.Closing when the app is asked to quit (backport #26063 to 6.7)
fix(macos): Close the windows through AppWindow.Closing when the app is asked to quit (backport #26063)
GitHub Issue: closes #26075
PR Type:
🐞 Bugfix
What changed? 🚀
Today, on macOS:
applicationShouldTerminate:answersNSTerminateNowfromMacOSCoreApplicationExtension.CanExit, which is alwaystrue.AppWindow.ClosingandWindow.Closedare never raised. An app cannot cancel the quit (for example to ask about unsaved work), and it cannot finish work it starts when its window closes.With this change:
AppWindow.Closingfirst, which can cancel the quit, thenWindow.Closed. If one window cancels, the windows asked before it are closed; it and the windows behind it stay open.DispatcherShutdownModeis.OnExplicitShutdownstill keeps the app running after the user closes its last window, and a later Quit still ends it.performClose:refuses a window with a sheet.ClosingorClosed, as before and as on Windows (Uno's Win32 host does not handle session end either). The quit reason comes from the quit Apple Event'skAEQuitReason.Application.Exit()now matches WinUI'sFrameworkApplication::ExitImpl: it closes every window asWindow.Close()does, raisingWindow.Closedbut notAppWindow.Closing, and then exits. As on WinUI, aClosedhandler that setsHandledkeeps its window open, and withOnLastWindowClosethat keeps the app running; withOnExplicitShutdownthe app exits anyway. Before, it ended the app without raisingClosed.Closinghandler that throws now logs an Error naming the window before the close (and the quit) is cancelled; a cancelled close andOnExplicitShutdownkeeping the app running log at Debug.The fix is in the native host (
UNOApplication.m, anduno_windows_close_for_quit()inUNOWindow.mnext touno_window_close()), plusMacOSCoreApplicationExtension.Exit()and the logging inMacOSWindowHostandMacOSCoreApplicationExtension.doc/articles/features/app-close-handler.mdgains a macOS section, and the manual sampleWindowing/AppWindow_QuitClosesWindowscovers the scenarios below.Behaviour changes worth a review:
Application.Exit()now raisesWindow.Closedon each window, as on WinUI.AppWindow.Closingto hide its window instead of closing it now also cancels Cmd+Q, sinceClosingdoes not say why the window is closing. Such an app needs its own way to exit that callsApplication.Current.Exit(); the docs say so. This is kept on purpose:Closingis how an app vetoes a quit.How to test (macOS, manual):
Open the
Windowing/AppWindow_QuitClosesWindowssample, ideally from a terminal (dotnet SamplesApp.dll sample=Windowing/AppWindow_QuitClosesWindows): it logs each event on screen and to the console, which still shows them after the app has exited.AppWindow.Closingand thenWindow.Closed, and the app exits. Repeat with the application menu's Quit and the Dock's Quit.OnExplicitShutdownand close the main window: the app keeps running. Cmd+Q then ends it.Application.Current.Exit()raisesWindow.Closedon each window, but notAppWindow.Closing, and exits.Closing, bring either window to the front, and quit: the window in front is asked first.Tested locally on macOS 27 (Apple silicon) with SamplesApp
net10.0-desktop(Release) and a scratch harness page (not committed). The quit was sent as the Dock's quit request (NSRunningApplication.terminate), which reaches the sameapplicationShouldTerminate:as Cmd+Q and the menu's Quit; the logout as the same request carryingkAEQuitReason=kAEReallyLogOut. A Debug native build traced each AppKit callback.Closing→Closed→ exitsClosingClosing→Closed, front window first, exitsOnExplicitShutdownClosing→Closed→ exitsOnExplicitShutdown, after the last window was closedClosingClosinghandler throwsOnExplicitShutdownwith a hide-on-close windowClosingApplication.Current.Exit()with two windows (one hidden, in another run)Closing, noClosedClosed, noClosing, exitsExit(), aClosedhandler setsHandledOnExplicitShutdownit exitsExit()called from aClosedhandler, during a close or a quitMainWindow.Close(); also with a hidden window that would cancelOnLastWindowClose)OnExplicitShutdownNot run: a real keypress or menu click, a real logout, a WebView sheet during quit, and a build of
servicing/6.8.No automated test: the terminate path runs inside AppKit, and driving it from the runtime tests would risk closing the test host's own window.
Backport: the runtime commits apply to
servicing/6.8with a three-way merge (the files sit underUno.UI.Runtime.Skia.MacOSthere), and the sample would go inMicrosoft_UI_Windowing/. On that branch a closed window stays in thewindowsset until it is deallocated; it is no longer visible, so a quit does not ask it.PR Checklist ✅
Screenshots Compare Test Runresults.