From 13ca871b88e441d107fc238f231b06bbbf3c91e5 Mon Sep 17 00:00:00 2001 From: Leonard Hecker Date: Wed, 14 Jun 2023 15:18:29 +0200 Subject: [PATCH 1/2] Fix a crash when duplicating tabs with elevate:true --- src/cascadia/TerminalApp/TerminalPage.cpp | 39 ++++++++++++----------- 1 file changed, 21 insertions(+), 18 deletions(-) diff --git a/src/cascadia/TerminalApp/TerminalPage.cpp b/src/cascadia/TerminalApp/TerminalPage.cpp index 2f6691162ce..21b20363b0a 100644 --- a/src/cascadia/TerminalApp/TerminalPage.cpp +++ b/src/cascadia/TerminalApp/TerminalPage.cpp @@ -4242,26 +4242,29 @@ namespace winrt::TerminalApp::implementation const TerminalSettingsCreateResult& controlSettings, const Profile& profile) { - // Try to handle auto-elevation - const auto requestedElevation = controlSettings.DefaultSettings().Elevate(); - const auto currentlyElevated = IsRunningElevated(); - - // We aren't elevated, but we want to be. - if (requestedElevation && !currentlyElevated) + // When duplicating a tab there aren't any newTerminalArgs. + if (!newTerminalArgs) { - // Manually set the Profile of the NewTerminalArgs to the guid we've - // resolved to. If there was a profile in the NewTerminalArgs, this - // will be that profile's GUID. If there wasn't, then we'll use - // whatever the default profile's GUID is. - - newTerminalArgs.Profile(::Microsoft::Console::Utils::GuidToString(profile.Guid())); - - newTerminalArgs.StartingDirectory(_evaluatePathForCwd(controlSettings.DefaultSettings().StartingDirectory())); - - _OpenElevatedWT(newTerminalArgs); - return true; + return false; } - return false; + + const auto defaultSettings = controlSettings.DefaultSettings(); + + // If we don't even want to elevate we can return early. + // If we're already elevated we can also return, because it doesn't get any more elevated than that. + if (!defaultSettings.Elevate() || IsRunningElevated()) + { + return false; + } + + // Manually set the Profile of the NewTerminalArgs to the guid we've + // resolved to. If there was a profile in the NewTerminalArgs, this + // will be that profile's GUID. If there wasn't, then we'll use + // whatever the default profile's GUID is. + newTerminalArgs.Profile(::Microsoft::Console::Utils::GuidToString(profile.Guid())); + newTerminalArgs.StartingDirectory(_evaluatePathForCwd(defaultSettings.StartingDirectory())); + _OpenElevatedWT(newTerminalArgs); + return true; } // Method Description: From 1c6f3dd952a74b26e0659a499ceb73c09d24fa0c Mon Sep 17 00:00:00 2001 From: Leonard Hecker Date: Thu, 15 Jun 2023 16:10:28 +0200 Subject: [PATCH 2/2] Fix formatting --- src/cascadia/TerminalApp/TerminalPage.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/cascadia/TerminalApp/TerminalPage.cpp b/src/cascadia/TerminalApp/TerminalPage.cpp index 21b20363b0a..858b6f6af97 100644 --- a/src/cascadia/TerminalApp/TerminalPage.cpp +++ b/src/cascadia/TerminalApp/TerminalPage.cpp @@ -4247,16 +4247,16 @@ namespace winrt::TerminalApp::implementation { return false; } - + const auto defaultSettings = controlSettings.DefaultSettings(); - + // If we don't even want to elevate we can return early. // If we're already elevated we can also return, because it doesn't get any more elevated than that. if (!defaultSettings.Elevate() || IsRunningElevated()) { return false; } - + // Manually set the Profile of the NewTerminalArgs to the guid we've // resolved to. If there was a profile in the NewTerminalArgs, this // will be that profile's GUID. If there wasn't, then we'll use