diff --git a/src/cascadia/WindowsTerminal/AppHost.cpp b/src/cascadia/WindowsTerminal/AppHost.cpp index 005b27ab6e8..ca81f1b511d 100644 --- a/src/cascadia/WindowsTerminal/AppHost.cpp +++ b/src/cascadia/WindowsTerminal/AppHost.cpp @@ -402,9 +402,14 @@ void AppHost::LastTabClosed(const winrt::Windows::Foundation::IInspectable& /*se _HideNotificationIconRequested(); } - // We don't want to try to save layouts if we are about to close + // We don't want to try to save layouts if we are about to close. _getWindowLayoutThrottler.reset(); _windowManager.GetWindowLayoutRequested(_GetWindowLayoutRequestedToken); + // We also don't need to update any of our bookkeeping on how many + // windows are open. + _windowManager.WindowCreated(_WindowCreatedToken); + _windowManager.WindowClosed(_WindowClosedToken); + // Remove ourself from the list of peasants so that we aren't included in // any future requests. This will also mean we block until any existing // event handler finishes. @@ -812,11 +817,17 @@ void AppHost::_BecomeMonarch(const winrt::Windows::Foundation::IInspectable& /*s // and subscribe for updates if there are any changes to that number. _logic.SetNumberOfOpenWindows(_windowManager.GetNumberOfPeasants()); - _windowManager.WindowCreated([this](auto&&, auto&&) { - _getWindowLayoutThrottler.value()(); + _WindowCreatedToken = _windowManager.WindowCreated([this](auto&&, auto&&) { + if (_getWindowLayoutThrottler) { + _getWindowLayoutThrottler.value()(); + } _logic.SetNumberOfOpenWindows(_windowManager.GetNumberOfPeasants()); }); - _windowManager.WindowClosed([this](auto&&, auto&&) { - _getWindowLayoutThrottler.value()(); + + _WindowClosedToken = _windowManager.WindowClosed([this](auto&&, auto&&) { + if (_getWindowLayoutThrottler) + { + _getWindowLayoutThrottler.value()(); + } _logic.SetNumberOfOpenWindows(_windowManager.GetNumberOfPeasants()); }); diff --git a/src/cascadia/WindowsTerminal/AppHost.h b/src/cascadia/WindowsTerminal/AppHost.h index 149c657054f..08bb35db822 100644 --- a/src/cascadia/WindowsTerminal/AppHost.h +++ b/src/cascadia/WindowsTerminal/AppHost.h @@ -115,4 +115,6 @@ class AppHost winrt::event_token _ShowNotificationIconContextMenuToken; winrt::event_token _NotificationIconMenuItemSelectedToken; winrt::event_token _GetWindowLayoutRequestedToken; + winrt::event_token _WindowCreatedToken; + winrt::event_token _WindowClosedToken; };