Skip to content

fix(macos): Close the windows through AppWindow.Closing when the app is asked to quit - #26063

Merged
ajpinedam merged 9 commits into
unoplatform:masterfrom
ajpinedam:dev/anpi/macos-quit-closes-windows
Nov 6, 2026
Merged

ajpinedam merged 9 commits into
unoplatform:masterfrom
ajpinedam:dev/anpi/macos-quit-closes-windows

Conversation

@ajpinedam

@ajpinedam ajpinedam commented Nov 4, 2026 •

Copy link
Copy Markdown
Contributor

GitHub Issue: closes #26075

PR Type:

🐞 Bugfix

What changed? 🚀

Today, on macOS:

  • Cmd+Q, the application menu's Quit and the Dock's Quit end the app at once. applicationShouldTerminate: answers NSTerminateNow from MacOSCoreApplicationExtension.CanExit, which is always true.
  • So AppWindow.Closing and Window.Closed are 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.
  • Closing the window with its close button does raise both, so the two ways of leaving the app behave differently.

With this change:

  • Cmd+Q, the application menu's Quit and the Dock's Quit close the windows the user can see as the user would, front to back: AppWindow.Closing first, which can cancel the quit, then Window.Closed. If one window cancels, the windows asked before it are closed; it and the windows behind it stay open.
  • Once they are closed, the app exits, whatever DispatcherShutdownMode is. OnExplicitShutdown still keeps the app running after the user closes its last window, and a later Quit still ends it.
  • Hidden windows are not asked, since the user has no close button for them; the app's exit ends them, as before.
  • The quit is refused while a modal panel (a file picker) or a sheet is up, as performClose: refuses a window with a sheet.
  • A logout, restart or shutdown is never refused: it ends the app without Closing or Closed, 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's kAEQuitReason.
  • Application.Exit() now matches WinUI's FrameworkApplication::ExitImpl: it closes every window as Window.Close() does, raising Window.Closed but not AppWindow.Closing, and then exits. As on WinUI, a Closed handler that sets Handled keeps its window open, and with OnLastWindowClose that keeps the app running; with OnExplicitShutdown the app exits anyway. Before, it ended the app without raising Closed.
  • A Closing handler that throws now logs an Error naming the window before the close (and the quit) is cancelled; a cancelled close and OnExplicitShutdown keeping the app running log at Debug.

The fix is in the native host (UNOApplication.m, and uno_windows_close_for_quit() in UNOWindow.m next to uno_window_close()), plus MacOSCoreApplicationExtension.Exit() and the logging in MacOSWindowHost and MacOSCoreApplicationExtension. doc/articles/features/app-close-handler.md gains a macOS section, and the manual sample Windowing/AppWindow_QuitClosesWindows covers the scenarios below.

Behaviour changes worth a review:

  • Application.Exit() now raises Window.Closed on each window, as on WinUI.
  • An app that cancels AppWindow.Closing to hide its window instead of closing it now also cancels Cmd+Q, since Closing does not say why the window is closing. Such an app needs its own way to exit that calls Application.Current.Exit(); the docs say so. This is kept on purpose: Closing is how an app vetoes a quit.

How to test (macOS, manual):

Open the Windowing/AppWindow_QuitClosesWindows sample, 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.

  1. Cmd+Q raises AppWindow.Closing and then Window.Closed, and the app exits. Repeat with the application menu's Quit and the Dock's Quit.
  2. Check "Cancel AppWindow.Closing on the main window": Cmd+Q leaves the app open.
  3. Set OnExplicitShutdown and close the main window: the app keeps running. Cmd+Q then ends it.
  4. Application.Current.Exit() raises Window.Closed on each window, but not AppWindow.Closing, and exits.
  5. Open a secondary window that cancels 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 same applicationShouldTerminate: as Cmd+Q and the menu's Quit; the logout as the same request carrying kAEQuitReason = kAEReallyLogOut. A Debug native build traced each AppKit callback.

Scenario Before (base commit) After
Quit exits, no events Closing → Closed → exits
Quit, main window cancels Closing — stays open
Quit with two windows — both Closing → Closed, front window first, exits
Quit, front window cancels (8 runs) — front window asked first every run; the other untouched
Quit, OnExplicitShutdown — Closing → Closed → exits
Quit, OnExplicitShutdown, after the last window was closed — exits
Quit with a hidden window that would cancel — hidden window not asked, one terminate pass, exits
Quit while a file picker is open — refused, no Closing
Quit, Closing handler throws — refused, Error logged with the window handle
Logout, main window would cancel / OnExplicitShutdown with a hide-on-close window — exits, no Closing
Application.Current.Exit() with two windows (one hidden, in another run) exits, no Closing, no Closed both Closed, no Closing, exits
Exit(), a Closed handler sets Handled — that window stays open and the app keeps running; with OnExplicitShutdown it exits
Exit() called from a Closed handler, during a close or a quit — exits
MainWindow.Close(); also with a hidden window that would cancel exits (OnLastWindowClose) unchanged: exits; stays alive with OnExplicitShutdown

Not 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.8 with a three-way merge (the files sit under Uno.UI.Runtime.Skia.MacOS there), and the sample would go in Microsoft_UI_Windowing/. On that branch a closed window stays in the windows set until it is deallocated; it is no longer visible, so a quit does not ask it.

PR Checklist ✅

@github-actions github-actions Bot added the platform/macos 🍏 Categorizes an issue or PR as relevant to the macOS platform label Nov 4, 2026
@unodevops

Copy link
Copy Markdown
Contributor

🤖 Your WebAssembly Sample App stage site is ready! Visit it here:

@github-actions github-actions Bot added the area/automation Categorizes an issue or PR as relevant to project automation label Nov 4, 2026
@unodevops

Copy link
Copy Markdown
Contributor

🤖 Your WebAssembly Sample App stage site is ready! Visit it here:

@unodevops

Copy link
Copy Markdown
Contributor

@unodevops

Copy link
Copy Markdown
Contributor

🤖 Your WebAssembly Sample App stage site is ready! Visit it here:

@unodevops

Copy link
Copy Markdown
Contributor

🤖 Your WebAssembly Sample App stage site is ready! Visit it here:

@nventive-devops

Copy link
Copy Markdown
Contributor

The build 243820 found UI Test snapshots differences: skia-linux-screenshots: 2458, skia-windows-screenshots: 2458

Details
  • skia-linux-screenshots: 2458 changed over 2494

    🚨🚨 Comparison Details (first 20) 🚨🚨
    • AnimatedIconPage.png
    • Accessibility_ScreenReader.png
    • AndroidWindowInsets.png-dark
    • Accessibility_ScreenReader.png-dark
    • AnimatedBackVisualSourceSamplePage.png-dark
    • AnimatedBackVisualSourceSamplePage.png
    • AnimatedIconPage.png-dark
    • AnimatedVisualsTestbedPage.png
    • AppBarButtonTest.png
    • AppBarButtonWithIconTest.png
    • AppBarButtonTest.png-dark
    • AppBarButtonWithIconTest.png-dark
    • AppBarToggleButtonTest.png-dark
    • AppBarToggleButtonTest.png
    • Application_DispatcherShutdownMode.png
    • ApplicationViewMode.png
    • ApplicationViewMode.png-dark
    • AppBar_KeyBoard.png-dark
    • AppBar_KeyBoard.png
    • ApplicationViewSizing.png-dark
  • skia-windows-screenshots: 2458 changed over 2494

    🚨🚨 Comparison Details (first 20) 🚨🚨
    • AnimatedIconPage.png-dark
    • AnimatedVisualsTestbedPage.png-dark
    • AppBarButtonTest.png-dark
    • AppBarToggleButtonTest.png-dark
    • ApplicationViewMode.png
    • Application_DispatcherShutdownMode.png
    • AppWindowPresenters.png
    • AppXamlDefinedResources.png
    • Arrange_Performance01.png
    • Attributed_text_FontSize_Changing.png-dark
    • AuthenticationBroker_Demo.png-dark
    • AuthenticationBroker_Demo.png
    • AutomationProperties_Landmark.png
    • AutomationProperties_Name.png-dark
    • AutoSizedPathCentered.png-dark
    • AutoSizedPathCentered.png
    • AutoSuggestBox_Icons.png-dark
    • AutoSuggestBox_Icons.png
    • BasicAcrylicBrushTest.png-dark
    • BasicAcrylicBrushTest.png

@ajpinedam
ajpinedam marked this pull request as ready for review November 5, 2026 02:39
@unodevops

Copy link
Copy Markdown
Contributor

@unodevops

Copy link
Copy Markdown
Contributor

🤖 Your WebAssembly Sample App stage site is ready! Visit it here:

@nventive-devops

Copy link
Copy Markdown
Contributor

The build 243839 found UI Test snapshots differences: skia-linux-screenshots: 2458, skia-windows-screenshots: 2458

Details
  • skia-linux-screenshots: 2458 changed over 2494

    🚨🚨 Comparison Details (first 20) 🚨🚨
    • AnimatedBackVisualSourceSamplePage.png
    • AppBarButtonWithIconTest.png
    • AppBarToggleButtonTest.png
    • ApplicationViewSpanningRectsPage.png
    • AppWindowPositionAndSize.png
    • Arrange_Performance01.png-dark
    • Attributed_text_Supserscript.png
    • AutoBorderStretchwithleftmargin.png
    • AutomationProperties_AutomationId.png
    • AutomationProperties_Landmark.png-dark
    • AutoSuggestBox_Description.png-dark
    • AutoSuggestBox_Description.png
    • BadgeNotificationTests.png-dark
    • BadgeNotificationTests.png
    • Basics_Automated.png-dark
    • Basics_Automated.png
    • BindableDrawerLayout_ChangePane.png-dark
    • BindableDrawerLayout_ChangePane.png
    • BorderBottomwithmargins.png-dark
    • BorderBottomwithmargins.png
  • skia-windows-screenshots: 2458 changed over 2494

    🚨🚨 Comparison Details (first 20) 🚨🚨
    • Accessibility_ScreenReader.png
    • AnimatedIconPage.png-dark
    • AnimatedIconPage.png
    • AppBarButtonTest.png
    • AppBarButtonWithIconTest.png
    • ApplicationViewSizing.png-dark
    • AppWindowPositionAndSize.png-dark
    • ArcSegment.png-dark
    • Attributed_text_Supserscript.png
    • AuthenticationBroker_Cancel.png-dark
    • AutomationProperties_Landmark.png-dark
    • AutomationProperties_Landmark.png
    • AutoSuggestBox_BitmapIcon.png-dark
    • AutoSuggestBox_BitmapIcon.png
    • BasicAutoSuggestBox.png-dark
    • BasicAutoSuggestBox.png
    • BasicThemeResources.png-dark
    • BasicThemeResources.png
    • BitmapIcon_Generic.png-dark
    • BitmapIcon_Generic.png

@ajpinedam
ajpinedam force-pushed the dev/anpi/macos-quit-closes-windows branch from f5a3cc4 to bb777ca Compare November 5, 2026 09:46
@unodevops

Copy link
Copy Markdown
Contributor

🤖 Your WebAssembly Sample App stage site is ready! Visit it here:

@unodevops

Copy link
Copy Markdown
Contributor

@nventive-devops

Copy link
Copy Markdown
Contributor

The build 243917 found UI Test snapshots differences: skia-linux-screenshots: 2458, skia-windows-screenshots: 2458

Details
  • skia-linux-screenshots: 2458 changed over 2494

    🚨🚨 Comparison Details (first 20) 🚨🚨
    • AndroidWindowInsets.png-dark
    • AnimatedVisualsTestbedPage.png-dark
    • ApplicationViewMode.png
    • AppWindowClosing.png
    • AppXamlDefinedResources.png-dark
    • Arrange_Performance01.png
    • AuthenticationBroker_Cancel.png
    • AutomationPropertiesExtensions_Role.png-dark
    • AutoSizedPathCentered.png-dark
    • AutoSizedPathCentered.png
    • AutoSuggestBox_Keyboard.png-dark
    • AutoSuggestBox_Keyboard.png
    • Basics Pivot Test.png-dark
    • Basics Pivot Test.png
    • Battery.png-dark
    • Battery.png
    • BezierSegment.png-dark
    • BezierSegment.png
    • BitmapIcon_Sizing.png-dark
    • BitmapIcon_Sizing.png
  • skia-windows-screenshots: 2458 changed over 2494

    🚨🚨 Comparison Details (first 20) 🚨🚨
    • Accessibility_ScreenReader.png-dark
    • AndroidWindowInsets.png
    • AnimatedIconPage.png
    • AppBarButtonTest.png
    • AppBarToggleButtonTest.png
    • ApplicationViewSpanningRectsPage.png
    • AppWindowFeatures.png-dark
    • AppWindowTitleBar Properties.png-dark
    • Attributed_text_FontSize_Changing.png-dark
    • Attributed_text_FontSize_Changing.png
    • AutoBorderStretchwithtopmargin.png
    • AutomationPropertiesExtensions_Role.png-dark
    • AutoSizedTopLeft.png
    • AutoSuggestBoxChosenSuggestion.png-dark
    • BackGesture.png-dark
    • BackGesture.png
    • Basics Pivot Test.png-dark
    • Basics Pivot Test.png
    • Battery.png-dark
    • Battery.png

@mergify

mergify Bot commented Nov 6, 2026 •

Copy link
Copy Markdown
Contributor

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.

@ajpinedam
ajpinedam merged commit 33e05b8 into unoplatform:master Nov 6, 2026
50 checks passed
agneszitte added a commit that referenced this pull request Nov 6, 2026
fix(macos): Close the windows through AppWindow.Closing when the app is asked to quit (backport #26063 to 6.7)
agneszitte added a commit that referenced this pull request Nov 9, 2026
fix(macos): Close the windows through AppWindow.Closing when the app is asked to quit (backport #26063)
@ajpinedam
ajpinedam deleted the dev/anpi/macos-quit-closes-windows branch November 9, 2026 15:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/automation Categorizes an issue or PR as relevant to project automation kind/documentation platform/macos 🍏 Categorizes an issue or PR as relevant to the macOS platform

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[macOS] Quitting the app does not raise AppWindow.Closing or Window.Closed

4 participants