[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.
This commit is contained in:
Mike Griese
2023-03-16 09:59:56 -05:00
parent 59b07f1b41
commit 7142ae88c9
2 changed files with 7 additions and 3 deletions

View File

@@ -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

View File

@@ -226,6 +226,8 @@ namespace winrt::TerminalApp::implementation
PaneResources _paneResources;
winrt::Microsoft::Terminal::TerminalConnection::ConptyConnection::NewConnection_revoker _newConnectionRevoker;
winrt::Windows::Foundation::IAsyncOperation<winrt::Windows::UI::Xaml::Controls::ContentDialogResult>
_ShowDialogHelper(const std::wstring_view& name);