|
7 | 7 |
|
8 | 8 | #include <LibraryResources.h>
|
9 | 9 | #include <TerminalCore/ControlKeyStates.hpp>
|
10 |
| -#include <til/latch.h> |
11 | 10 | #include <Utils.h>
|
12 | 11 |
|
13 | 12 | #include "../../types/inc/utils.hpp"
|
@@ -293,12 +292,11 @@ namespace winrt::TerminalApp::implementation
|
293 | 292 | // - true if we're not elevated but all relevant pane-spawning actions are elevated
|
294 | 293 | bool TerminalPage::ShouldImmediatelyHandoffToElevated(const CascadiaSettings& settings) const
|
295 | 294 | {
|
296 |
| - // GH#12267: Don't forget about defterm handoff here. If we're being |
297 |
| - // created for embedding, then _yea_, we don't need to handoff to an |
298 |
| - // elevated window. |
299 |
| - if (_startupActions.empty() || IsRunningElevated() || _shouldStartInboundListener) |
| 295 | + if (_startupActions.empty() || _startupConnection || IsRunningElevated()) |
300 | 296 | {
|
301 |
| - // there aren't startup actions, or we're elevated. In that case, go for it. |
| 297 | + // No point in handing off if we got no startup actions, or we're already elevated. |
| 298 | + // Also, we shouldn't need to elevate handoff ConPTY connections. |
| 299 | + assert(!_startupConnection); |
302 | 300 | return false;
|
303 | 301 | }
|
304 | 302 |
|
@@ -488,45 +486,9 @@ namespace winrt::TerminalApp::implementation
|
488 | 486 | {
|
489 | 487 | _startupState = StartupState::InStartup;
|
490 | 488 |
|
491 |
| - ProcessStartupActions(std::move(_startupActions), true); |
492 |
| - |
493 |
| - // If we were told that the COM server needs to be started to listen for incoming |
494 |
| - // default application connections, start it now. |
495 |
| - // This MUST be done after we've registered the event listener for the new connections |
496 |
| - // or the COM server might start receiving requests on another thread and dispatch |
497 |
| - // them to nowhere. |
498 |
| - _StartInboundListener(); |
499 |
| - } |
500 |
| - } |
501 |
| - |
502 |
| - // Routine Description: |
503 |
| - // - Will start the listener for inbound console handoffs if we have already determined |
504 |
| - // that we should do so. |
505 |
| - // NOTE: Must be after TerminalPage::_OnNewConnection has been connected up. |
506 |
| - // Arguments: |
507 |
| - // - <unused> - Looks at _shouldStartInboundListener |
508 |
| - // Return Value: |
509 |
| - // - <none> - May fail fast if setup fails as that would leave us in a weird state. |
510 |
| - void TerminalPage::_StartInboundListener() |
511 |
| - { |
512 |
| - if (_shouldStartInboundListener) |
513 |
| - { |
514 |
| - _shouldStartInboundListener = false; |
515 |
| - |
516 |
| - // Hook up inbound connection event handler |
517 |
| - _newConnectionRevoker = ConptyConnection::NewConnection(winrt::auto_revoke, { this, &TerminalPage::_OnNewConnection }); |
518 |
| - |
519 |
| - try |
520 |
| - { |
521 |
| - winrt::Microsoft::Terminal::TerminalConnection::ConptyConnection::StartInboundListener(); |
522 |
| - } |
523 |
| - // If we failed to start the listener, it will throw. |
524 |
| - // We don't want to fail fast here because if a peasant has some trouble with |
525 |
| - // starting the listener, we don't want it to crash and take all its tabs down |
526 |
| - // with it. |
527 |
| - catch (...) |
| 489 | + if (!_startupActions.empty()) |
528 | 490 | {
|
529 |
| - LOG_CAUGHT_EXCEPTION(); |
| 491 | + ProcessStartupActions(std::move(_startupActions), true); |
530 | 492 | }
|
531 | 493 | }
|
532 | 494 | }
|
@@ -629,7 +591,7 @@ namespace winrt::TerminalApp::implementation
|
629 | 591 | // GH#12267: Make sure that we don't instantly close ourselves when
|
630 | 592 | // we're readying to accept a defterm connection. In that case, we don't
|
631 | 593 | // have a tab yet, but will once we're initialized.
|
632 |
| - if (_tabs.Size() == 0 && !_shouldStartInboundListener && !_isEmbeddingInboundListener) |
| 594 | + if (_tabs.Size() == 0) |
633 | 595 | {
|
634 | 596 | CloseWindowRequested.raise(*this, nullptr);
|
635 | 597 | co_return;
|
@@ -3653,25 +3615,9 @@ namespace winrt::TerminalApp::implementation
|
3653 | 3615 | _startupActions = std::move(actions);
|
3654 | 3616 | }
|
3655 | 3617 |
|
3656 |
| - // Routine Description: |
3657 |
| - // - Notifies this Terminal Page that it should start the incoming connection |
3658 |
| - // listener for command-line tools attempting to join this Terminal |
3659 |
| - // through the default application channel. |
3660 |
| - // Arguments: |
3661 |
| - // - isEmbedding - True if COM started us to be a server. False if we're doing it of our own accord. |
3662 |
| - // Return Value: |
3663 |
| - // - <none> |
3664 |
| - void TerminalPage::SetInboundListener(bool isEmbedding) |
| 3618 | + void TerminalPage::SetStartupConnection(ITerminalConnection connection) |
3665 | 3619 | {
|
3666 |
| - _shouldStartInboundListener = true; |
3667 |
| - _isEmbeddingInboundListener = isEmbedding; |
3668 |
| - |
3669 |
| - // If the page has already passed the NotInitialized state, |
3670 |
| - // then it is ready-enough for us to just start this immediately. |
3671 |
| - if (_startupState != StartupState::NotInitialized) |
3672 |
| - { |
3673 |
| - _StartInboundListener(); |
3674 |
| - } |
| 3620 | + _startupConnection = std::move(connection); |
3675 | 3621 | }
|
3676 | 3622 |
|
3677 | 3623 | winrt::TerminalApp::IDialogPresenter TerminalPage::DialogPresenter() const
|
@@ -4073,68 +4019,6 @@ namespace winrt::TerminalApp::implementation
|
4073 | 4019 | ChangeMaximizeRequested.raise(*this, nullptr);
|
4074 | 4020 | }
|
4075 | 4021 |
|
4076 |
| - HRESULT TerminalPage::_OnNewConnection(const ConptyConnection& connection) |
4077 |
| - { |
4078 |
| - _newConnectionRevoker.revoke(); |
4079 |
| - |
4080 |
| - // We need to be on the UI thread in order for _OpenNewTab to run successfully. |
4081 |
| - // HasThreadAccess will return true if we're currently on a UI thread and false otherwise. |
4082 |
| - // When we're on a COM thread, we'll need to dispatch the calls to the UI thread |
4083 |
| - // and wait on it hence the locking mechanism. |
4084 |
| - if (!Dispatcher().HasThreadAccess()) |
4085 |
| - { |
4086 |
| - til::latch latch{ 1 }; |
4087 |
| - auto finalVal = S_OK; |
4088 |
| - |
4089 |
| - Dispatcher().RunAsync(CoreDispatcherPriority::Normal, [&]() { |
4090 |
| - finalVal = _OnNewConnection(connection); |
4091 |
| - latch.count_down(); |
4092 |
| - }); |
4093 |
| - |
4094 |
| - latch.wait(); |
4095 |
| - return finalVal; |
4096 |
| - } |
4097 |
| - |
4098 |
| - try |
4099 |
| - { |
4100 |
| - NewTerminalArgs newTerminalArgs; |
4101 |
| - newTerminalArgs.Commandline(connection.Commandline()); |
4102 |
| - newTerminalArgs.TabTitle(connection.StartingTitle()); |
4103 |
| - // GH #12370: We absolutely cannot allow a defterm connection to |
4104 |
| - // auto-elevate. Defterm doesn't work for elevated scenarios in the |
4105 |
| - // first place. If we try accepting the connection, the spawning an |
4106 |
| - // elevated version of the Terminal with that profile... that's a |
4107 |
| - // recipe for disaster. We won't ever open up a tab in this window. |
4108 |
| - newTerminalArgs.Elevate(false); |
4109 |
| - const auto newPane = _MakePane(newTerminalArgs, nullptr, connection); |
4110 |
| - newPane->WalkTree([](const auto& pane) { |
4111 |
| - pane->FinalizeConfigurationGivenDefault(); |
4112 |
| - }); |
4113 |
| - _CreateNewTabFromPane(newPane); |
4114 |
| - |
4115 |
| - // Request a summon of this window to the foreground |
4116 |
| - SummonWindowRequested.raise(*this, nullptr); |
4117 |
| - |
4118 |
| - // TEMPORARY SOLUTION |
4119 |
| - // If the connection has requested for the window to be maximized, |
4120 |
| - // manually maximize it here. Ideally, we should be _initializing_ |
4121 |
| - // the session maximized, instead of manually maximizing it after initialization. |
4122 |
| - // However, because of the current way our defterm handoff works, |
4123 |
| - // we are unable to get the connection info before the terminal session |
4124 |
| - // has already started. |
4125 |
| - |
4126 |
| - // Make sure that there were no other tabs already existing (in |
4127 |
| - // the case that we are in glomming mode), because we don't want |
4128 |
| - // to be maximizing other existing sessions that did not ask for it. |
4129 |
| - if (_tabs.Size() == 1 && connection.ShowWindow() == SW_SHOWMAXIMIZED) |
4130 |
| - { |
4131 |
| - RequestSetMaximized(true); |
4132 |
| - } |
4133 |
| - return S_OK; |
4134 |
| - } |
4135 |
| - CATCH_RETURN() |
4136 |
| - } |
4137 |
| - |
4138 | 4022 | TerminalApp::IPaneContent TerminalPage::_makeSettingsContent()
|
4139 | 4023 | {
|
4140 | 4024 | if (auto app{ winrt::Windows::UI::Xaml::Application::Current().try_as<winrt::TerminalApp::App>() })
|
|
0 commit comments