Skip to content

Commit

Permalink
Make sure we dont access an invalid optional on close (#11857)
Browse files Browse the repository at this point in the history
<!-- Enter a brief description/summary of your PR here. What does it fix/what does it change/how was it tested (even manually, if necessary)? -->
## Summary of the Pull Request
Clean up an invalid access that I introduced in #11440

<!-- Other than the issue solved, is this relevant to any other issues/existing PRs? -->
## References

<!-- Please review the items on the PR checklist before submitting-->
## PR Checklist
* [x] Closes #11684
* [x] CLA signed. If not, go over [here](https://cla.opensource.microsoft.com/microsoft/Terminal) and sign the CLA
* [ ] Tests added/passed
* [ ] Documentation updated. If checked, please file a pull request on [our docs repo](https://github.com/MicrosoftDocs/terminal) and link it here: #xxx
* [ ] Schema updated.
* [ ] I've discussed this with core contributors already. If not checked, I'm ready to accept this work might be rejected in favor of a different grand plan. Issue number where discussion took place: #xxx

<!-- Provide a more detailed description of the PR, other things fixed or any additional comments/features here -->
## Detailed Description of the Pull Request / Additional comments

<!-- Describe how you validated the behavior. Add automated tests wherever possible, but list manual validation steps taken as well -->
## Validation Steps Performed

(cherry picked from commit 29e6235)
  • Loading branch information
Rosefield authored and DHowett committed Dec 13, 2021
1 parent a303c63 commit 3a51afc
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 5 deletions.
21 changes: 16 additions & 5 deletions src/cascadia/WindowsTerminal/AppHost.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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());
});

Expand Down
2 changes: 2 additions & 0 deletions src/cascadia/WindowsTerminal/AppHost.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};

0 comments on commit 3a51afc

Please sign in to comment.