Skip to content

Commit

Permalink
Okay this works. -Embedding if found skips other arg parsing. No new …
Browse files Browse the repository at this point in the history
…tabs are made for embedding... and it totally works. Except Terminal can't read from the pipes it was given. So gotta figure that one out.
  • Loading branch information
miniksa committed Sep 2, 2020
1 parent b1c56b2 commit 4286f61
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 22 deletions.
19 changes: 12 additions & 7 deletions src/cascadia/TerminalApp/AppCommandlineArgs.cpp
Expand Up @@ -183,13 +183,7 @@ void AppCommandlineArgs::_buildParser()
embeddingAction->Action(ShortcutAction::ToggleInboundPty);
_startupActions.push_back(*embeddingAction);
}
else
{
throw CLI::ParseError(fmt::format("Invalid call to COM server with {}", param), E_INVALIDARG);
}
};

_app.add_option_function<std::string>("-E", comEmbeddingCallback, RS_A(L"CmdEmbeddingDesc"));

// Maximized and Fullscreen flags
// -M,--maximized: Maximizes the window on launch
Expand Down Expand Up @@ -666,7 +660,7 @@ void AppCommandlineArgs::ValidateStartupCommands()
// If we parsed no commands, or the first command we've parsed is not a new
// tab action, prepend a new-tab command to the front of the list.
if (_startupActions.empty() ||
_startupActions.front().Action() != ShortcutAction::NewTab)
(_startupActions.front().Action() != ShortcutAction::NewTab && _startupActions.front().Action() != ShortcutAction::ToggleInboundPty))
{
// Build the NewTab action from the values we've parsed on the commandline.
auto newTabAction = winrt::make_self<implementation::ActionAndArgs>();
Expand Down Expand Up @@ -700,6 +694,17 @@ std::optional<winrt::TerminalApp::LaunchMode> AppCommandlineArgs::GetLaunchMode(
// - 0 if the commandline was successfully parsed
int AppCommandlineArgs::ParseArgs(winrt::array_view<const winrt::hstring>& args)
{
for (auto& arg : args)
{
if (arg == L"-Embedding")
{
auto embeddingAction = winrt::make_self<implementation::ActionAndArgs>();
embeddingAction->Action(ShortcutAction::ToggleInboundPty);
_startupActions.push_back(*embeddingAction);
return 0;
}
}

auto commands = ::TerminalApp::AppCommandlineArgs::BuildCommands(args);

for (auto& cmdBlob : commands)
Expand Down
10 changes: 6 additions & 4 deletions src/cascadia/TerminalApp/TerminalPage.cpp
Expand Up @@ -197,7 +197,7 @@ namespace winrt::TerminalApp::implementation

// Hook up inbound PTY event handlers
InboundPtyChanged({ this, &TerminalPage::_OnInboundPtyChanged });
//Microsoft::Terminal::TerminalConnection::ConptyConnection::NewConnection(&TerminalPage::_OnNewConnection);
TerminalConnection::ConptyConnection::NewConnection({ this, &TerminalPage::_OnNewConnection });

//Event Bindings (Early)
_newTabButton.Click([weakThis{ get_weak() }](auto&&, auto&&) {
Expand Down Expand Up @@ -2517,9 +2517,11 @@ namespace winrt::TerminalApp::implementation
}
}

//void TerminalPage::_OnNewConnection(winrt::Microsoft::Terminal::TerminalConnection::ITerminalConnection /*connection*/)
//{
//}
void TerminalPage::_OnNewConnection(winrt::Microsoft::Terminal::TerminalConnection::ITerminalConnection connection)
{
// TODO: this should probably use a more reasonable profile than nullptr.
_OpenNewTab(nullptr, connection);
}

// -------------------------------- WinRT Events ---------------------------------
// Winrt events need a method for adding a callback to the event and removing the callback.
Expand Down
2 changes: 1 addition & 1 deletion src/cascadia/TerminalApp/TerminalPage.h
Expand Up @@ -205,7 +205,7 @@ namespace winrt::TerminalApp::implementation
void _UnZoomIfNeeded();

void _OnInboundPtyChanged(const IInspectable& sender, const IInspectable& eventArgs);
//void _OnNewConnection(winrt::Microsoft::Terminal::TerminalConnection::ITerminalConnection connection);
void _OnNewConnection(winrt::Microsoft::Terminal::TerminalConnection::ITerminalConnection connection);

#pragma region ActionHandlers
// These are all defined in AppActionHandlers.cpp
Expand Down
15 changes: 5 additions & 10 deletions src/host/srvinit.cpp
Expand Up @@ -331,11 +331,11 @@ try
wil::unique_handle outPipeTheirSide;
wil::unique_handle outPipeOurSide;

//SECURITY_ATTRIBUTES sa;
//sa.nLength = sizeof(sa);
//// Mark inheritable for signal handle when creating. It'll have the same value on the other side.
//sa.bInheritHandle = TRUE;
//sa.lpSecurityDescriptor = nullptr;
SECURITY_ATTRIBUTES sa;
sa.nLength = sizeof(sa);
// Mark inheritable for signal handle when creating. It'll have the same value on the other side.
sa.bInheritHandle = TRUE;
sa.lpSecurityDescriptor = nullptr;

RETURN_IF_WIN32_BOOL_FALSE(CreatePipe(signalPipeOurSide.addressof(), signalPipeTheirSide.addressof(), nullptr, 0));
RETURN_IF_WIN32_BOOL_FALSE(SetHandleInformation(signalPipeTheirSide.get(), HANDLE_FLAG_INHERIT, HANDLE_FLAG_INHERIT));
Expand All @@ -351,11 +351,6 @@ try

RETURN_IF_FAILED(CoCreateInstance(g.handoffTerminalClsid.value(), nullptr, CLSCTX_LOCAL_SERVER, IID_PPV_ARGS(&handoff)));

handoff->AddRef();
handoff->DoNothing();

/*handoff->EstablishHandoff((HANDLE)4, (HANDLE)8, (HANDLE)12);*/

RETURN_IF_FAILED(handoff->EstablishHandoff(inPipeTheirSide.get(),
outPipeTheirSide.get(),
signalPipeTheirSide.get()));
Expand Down

1 comment on commit 4286f61

@github-actions

This comment was marked as outdated.

Please sign in to comment.