From 7142ae88c9a3558a04e765b4ec71a6dc1ebcbccb Mon Sep 17 00:00:00 2001 From: Mike Griese Date: Thu, 16 Mar 2023 09:59:56 -0500 Subject: [PATCH] [ainulindale] fix defterm Each page was registering as a handoff target, so basically we'd start the server then yeet the connection back to the first window and presto, you'd have a dead window and a connection on the wrong thread and everything was awful. Instead, only register as the handoff listener when we've actually said we want to be a handoff listener. --- src/cascadia/TerminalApp/TerminalPage.cpp | 8 +++++--- src/cascadia/TerminalApp/TerminalPage.h | 2 ++ 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/src/cascadia/TerminalApp/TerminalPage.cpp b/src/cascadia/TerminalApp/TerminalPage.cpp index 5661f8f4a5..1b4083844b 100644 --- a/src/cascadia/TerminalApp/TerminalPage.cpp +++ b/src/cascadia/TerminalApp/TerminalPage.cpp @@ -228,9 +228,6 @@ namespace winrt::TerminalApp::implementation // Hookup our event handlers to the ShortcutActionDispatch _RegisterActionCallbacks(); - // Hook up inbound connection event handler - ConptyConnection::NewConnection({ this, &TerminalPage::_OnNewConnection }); - //Event Bindings (Early) _newTabButton.Click([weakThis{ get_weak() }](auto&&, auto&&) { if (auto page{ weakThis.get() }) @@ -519,6 +516,9 @@ namespace winrt::TerminalApp::implementation { _shouldStartInboundListener = false; + // Hook up inbound connection event handler + _newConnectionRevoker = ConptyConnection::NewConnection(winrt::auto_revoke, { this, &TerminalPage::_OnNewConnection }); + try { winrt::Microsoft::Terminal::TerminalConnection::ConptyConnection::StartInboundListener(); @@ -3326,6 +3326,8 @@ namespace winrt::TerminalApp::implementation HRESULT TerminalPage::_OnNewConnection(const ConptyConnection& connection) { + _newConnectionRevoker.revoke(); + // We need to be on the UI thread in order for _OpenNewTab to run successfully. // HasThreadAccess will return true if we're currently on a UI thread and false otherwise. // When we're on a COM thread, we'll need to dispatch the calls to the UI thread diff --git a/src/cascadia/TerminalApp/TerminalPage.h b/src/cascadia/TerminalApp/TerminalPage.h index f19a1df1a5..0b9c1f6515 100644 --- a/src/cascadia/TerminalApp/TerminalPage.h +++ b/src/cascadia/TerminalApp/TerminalPage.h @@ -226,6 +226,8 @@ namespace winrt::TerminalApp::implementation PaneResources _paneResources; + winrt::Microsoft::Terminal::TerminalConnection::ConptyConnection::NewConnection_revoker _newConnectionRevoker; + winrt::Windows::Foundation::IAsyncOperation _ShowDialogHelper(const std::wstring_view& name);