diff --git a/src/cascadia/Remoting/CommandlineArgs.cpp b/src/cascadia/Remoting/CommandlineArgs.cpp index e3c31cd2a31..bbe31961c6e 100644 --- a/src/cascadia/Remoting/CommandlineArgs.cpp +++ b/src/cascadia/Remoting/CommandlineArgs.cpp @@ -8,6 +8,10 @@ using namespace winrt::Windows::Foundation; namespace winrt::Microsoft::Terminal::Remoting::implementation { + // If you try to move this into the header, you will experience P A I N + // It must be defined after CommandlineArgs.g.cpp, otherwise the compiler + // will give you just the most impossible tmplate errors to try and + // decipher. void CommandlineArgs::Args(winrt::array_view const& value) { _args = { value.begin(), value.end() }; diff --git a/src/cascadia/Remoting/Monarch.cpp b/src/cascadia/Remoting/Monarch.cpp index 888dbade666..9c304b951b7 100644 --- a/src/cascadia/Remoting/Monarch.cpp +++ b/src/cascadia/Remoting/Monarch.cpp @@ -95,16 +95,16 @@ namespace winrt::Microsoft::Terminal::Remoting::implementation bool Monarch::ProposeCommandline(array_view args, winrt::hstring cwd) { - auto argsProcessed = 0; - std::wstring fullCmdline; - for (const auto& arg : args) - { - fullCmdline += argsProcessed++ == 0 ? L"sample.exe" : arg; - fullCmdline += L" "; - } - wprintf(L"\x1b[36mProposed Commandline\x1b[m: \""); - wprintf(fullCmdline.c_str()); - wprintf(L"\"\n"); + // auto argsProcessed = 0; + // std::wstring fullCmdline; + // for (const auto& arg : args) + // { + // fullCmdline += argsProcessed++ == 0 ? L"sample.exe" : arg; + // fullCmdline += L" "; + // } + // wprintf(L"\x1b[36mProposed Commandline\x1b[m: \""); + // wprintf(fullCmdline.c_str()); + // wprintf(L"\"\n"); bool createNewWindow = true; @@ -113,7 +113,7 @@ namespace winrt::Microsoft::Terminal::Remoting::implementation // We'll need three args at least - [WindowsTerminal.exe, -s, // id] to be able to have a session ID passed on the commandline. - if (args[1] == L"-s" || args[1] == L"--session") + if (args[1] == L"-w" || args[1] == L"--window") { auto sessionId = std::stoi({ args[2].data(), args[2].size() }); printf("Found a commandline intended for session %d\n", sessionId); diff --git a/src/cascadia/Remoting/Peasant.h b/src/cascadia/Remoting/Peasant.h index df4db13b529..e2181690e2b 100644 --- a/src/cascadia/Remoting/Peasant.h +++ b/src/cascadia/Remoting/Peasant.h @@ -23,7 +23,7 @@ namespace winrt::Microsoft::Terminal::Remoting::implementation private: uint64_t _id{ 0 }; - winrt::Microsoft::Terminal::Remoting::CommandlineArgs _initialArgs; //{ nullptr }; + winrt::Microsoft::Terminal::Remoting::CommandlineArgs _initialArgs{ nullptr }; // array_view _args; // winrt::hstring _cwd; diff --git a/src/cascadia/Remoting/WindowManager.cpp b/src/cascadia/Remoting/WindowManager.cpp index ddc0d85989a..b5e60723bd2 100644 --- a/src/cascadia/Remoting/WindowManager.cpp +++ b/src/cascadia/Remoting/WindowManager.cpp @@ -28,7 +28,8 @@ namespace winrt::Microsoft::Terminal::Remoting::implementation _registrationHostClass = 0; } - void WindowManager::ProposeCommandline(array_view args, const winrt::hstring cwd) + void WindowManager::ProposeCommandline(array_view args, + const winrt::hstring cwd) { const bool isKing = _areWeTheKing(); // If we're the king, we _definitely_ want to process the arguments, we were diff --git a/src/cascadia/WindowsTerminal/AppHost.cpp b/src/cascadia/WindowsTerminal/AppHost.cpp index 928931ada43..c37a74e8149 100644 --- a/src/cascadia/WindowsTerminal/AppHost.cpp +++ b/src/cascadia/WindowsTerminal/AppHost.cpp @@ -142,21 +142,11 @@ void AppHost::SetTaskbarProgress(const winrt::Windows::Foundation::IInspectable& // - void AppHost::_HandleCommandlineArgs() { - if (auto commandline{ GetCommandLineW() }) + if (auto peasant{ _windowManager.CurrentWindow() }) { - int argc = 0; - - // Get the argv, and turn them into a hstring array to pass to the app. - wil::unique_any argv{ CommandLineToArgvW(commandline, &argc) }; - if (argv) + if (auto args{ peasant.InitialArgs() }) { - std::vector args; - for (auto& elem : wil::make_range(argv.get(), argc)) - { - args.emplace_back(elem); - } - - const auto result = _logic.SetStartupCommandline({ args }); + const auto result = _logic.SetStartupCommandline(args.Args()); const auto message = _logic.ParseCommandlineMessage(); if (!message.empty()) { @@ -177,6 +167,41 @@ void AppHost::_HandleCommandlineArgs() } } } + // if (auto commandline{ GetCommandLineW() }) + // { + // int argc = 0; + + // // Get the argv, and turn them into a hstring array to pass to the app. + // wil::unique_any argv{ CommandLineToArgvW(commandline, &argc) }; + // if (argv) + // { + // std::vector args; + // for (auto& elem : wil::make_range(argv.get(), argc)) + // { + // args.emplace_back(elem); + // } + + // const auto result = _logic.SetStartupCommandline({ args }); + // const auto message = _logic.ParseCommandlineMessage(); + // if (!message.empty()) + // { + // const auto displayHelp = result == 0; + // const auto messageTitle = displayHelp ? IDS_HELP_DIALOG_TITLE : IDS_ERROR_DIALOG_TITLE; + // const auto messageIcon = displayHelp ? MB_ICONWARNING : MB_ICONERROR; + // // TODO:GH#4134: polish this dialog more, to make the text more + // // like msiexec /? + // MessageBoxW(nullptr, + // message.data(), + // GetStringResource(messageTitle).data(), + // MB_OK | messageIcon); + + // if (_logic.ShouldExitEarly()) + // { + // ExitProcess(result); + // } + // } + // } + // } } // Method Description: