diff --git a/toolkit/components/startup/nsAppStartup.cpp b/toolkit/components/startup/nsAppStartup.cpp index 316a86d5fcad..d8f0c072c8a5 100644 --- a/toolkit/components/startup/nsAppStartup.cpp +++ b/toolkit/components/startup/nsAppStartup.cpp @@ -621,6 +621,12 @@ nsAppStartup::GetShuttingDown(bool* aResult) { return NS_OK; } +NS_IMETHODIMP +nsAppStartup::GetAttemptingQuit(bool* aResult) { + *aResult = mAttemptingQuit; + return NS_OK; +} + NS_IMETHODIMP nsAppStartup::GetStartingUp(bool* aResult) { *aResult = mStartingUp; diff --git a/toolkit/components/startup/public/nsIAppStartup.idl b/toolkit/components/startup/public/nsIAppStartup.idl index b8eca35f78b3..5cc9497562e0 100644 --- a/toolkit/components/startup/public/nsIAppStartup.idl +++ b/toolkit/components/startup/public/nsIAppStartup.idl @@ -202,6 +202,13 @@ interface nsIAppStartup : nsISupports */ [infallible] readonly attribute boolean shuttingDown; + /** + * True if the application is attempting to quit (Quit has been called). This + * is an early signal that we are headed to shutdown. It becomes true just + * before we start closing windows. + */ + [infallible] readonly attribute boolean attemptingQuit; + /** * True if the application is in the process of starting up. * diff --git a/widget/cocoa/nsCocoaWindow.mm b/widget/cocoa/nsCocoaWindow.mm index 7a6ee5299a66..b965ee108d74 100644 --- a/widget/cocoa/nsCocoaWindow.mm +++ b/widget/cocoa/nsCocoaWindow.mm @@ -8,12 +8,14 @@ #include "nsArrayUtils.h" #include "nsCursorManager.h" +#include "nsIAppStartup.h" #include "nsIDOMWindowUtils.h" #include "nsILocalFileMac.h" #include "GLContextCGL.h" #include "MacThemeGeometryType.h" #include "NativeMenuSupport.h" #include "WindowRenderer.h" +#include "mozilla/Components.h" #include "mozilla/MiscEvents.h" #include "mozilla/SwipeTracker.h" #include "mozilla/layers/APZInputBridge.h" @@ -7109,9 +7111,17 @@ void nsCocoaWindow::CocoaWindowDidResize() { RefPtr hiddenWindowMenuBar = nsMenuUtilsX::GetHiddenWindowMenuBar(); if (hiddenWindowMenuBar) { - // We do an async paint in order to prevent crashes when macOS is actively - // enumerating the menu items in `NSApp.mainMenu`. - hiddenWindowMenuBar->PaintAsyncIfNeeded(); + bool isTerminating = false; + nsCOMPtr appStartup(components::AppStartup::Service()); + if (appStartup) { + appStartup->GetAttemptingQuit(&isTerminating); + } + + if (!isTerminating) { + // We do an async paint in order to prevent crashes when macOS is actively + // enumerating the menu items in `NSApp.mainMenu`. + hiddenWindowMenuBar->PaintAsyncIfNeeded(); + } } NSWindow* window = [aNotification object];