Skip to content

Commit

Permalink
Reload environment variables by default; add setting to disable (#14999)
Browse files Browse the repository at this point in the history
Adds a global setting `compatibility.reloadEnvironmentVariables` with a
default value of `true`. When set, during connection creation a new
environment block will be generated to ensure it has the latest
environment variables.

Closes #1125

Co-authored-by: Leonard Hecker <lhecker@microsoft.com>
  • Loading branch information
ianjoneill and lhecker authored Mar 17, 2023
1 parent 65640f6 commit 5166148
Show file tree
Hide file tree
Showing 8 changed files with 161 additions and 132 deletions.
2 changes: 1 addition & 1 deletion .github/actions/spelling/allow/apis.txt
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ DNE
DONTADDTORECENT
DWMSBT
DWMWA
DWMWA
DWORDLONG
endfor
ENDSESSION
Expand Down Expand Up @@ -251,3 +250,4 @@ xtree
xutility
YIcon
YMax
zwstring
5 changes: 5 additions & 0 deletions doc/cascadia/profiles.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -2164,6 +2164,11 @@
"description": "When set to true, the background image for the currently focused profile is expanded to encompass the entire window, beneath other panes.",
"type": "boolean"
},
"compatibility.reloadEnvironmentVariables": {
"default": true,
"description": "When set to true, when opening a new tab or pane it will get reloaded environment variables.",
"type": "boolean"
},
"initialCols": {
"default": 120,
"description": "The number of columns displayed in the window upon first load. If \"launchMode\" is set to \"maximized\" (or \"maximizedFocus\"), this property is ignored.",
Expand Down
2 changes: 2 additions & 0 deletions src/cascadia/TerminalApp/TerminalPage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1274,6 +1274,8 @@ namespace winrt::TerminalApp::implementation
winrt::guid());

valueSet.Insert(L"passthroughMode", Windows::Foundation::PropertyValue::CreateBoolean(settings.VtPassthrough()));
valueSet.Insert(L"reloadEnvironmentVariables",
Windows::Foundation::PropertyValue::CreateBoolean(_settings.GlobalSettings().ReloadEnvironmentVariables()));

conhostConn.Initialize(valueSet);

Expand Down
18 changes: 17 additions & 1 deletion src/cascadia/TerminalConnection/ConptyConnection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include "ConptyConnection.h"

#include <conpty-static.h>
#include <til/env.h>
#include <winternl.h>

#include "CTerminalHandoff.h"
Expand Down Expand Up @@ -95,7 +96,20 @@ namespace winrt::Microsoft::Terminal::TerminalConnection::implementation
});

// Populate the environment map with the current environment.
RETURN_IF_FAILED(Utils::UpdateEnvironmentMapW(environment));
if (_reloadEnvironmentVariables)
{
til::env refreshedEnvironment;
refreshedEnvironment.regenerate();

for (auto& [key, value] : refreshedEnvironment.as_map())
{
environment.try_emplace(key, std::move(value));
}
}
else
{
RETURN_IF_FAILED(Utils::UpdateEnvironmentMapW(environment));
}

{
// Convert connection Guid to string and ignore the enclosing '{}'.
Expand Down Expand Up @@ -272,6 +286,8 @@ namespace winrt::Microsoft::Terminal::TerminalConnection::implementation
{
_passthroughMode = winrt::unbox_value_or<bool>(settings.TryLookup(L"passthroughMode").try_as<Windows::Foundation::IPropertyValue>(), _passthroughMode);
}
_reloadEnvironmentVariables = winrt::unbox_value_or<bool>(settings.TryLookup(L"reloadEnvironmentVariables").try_as<Windows::Foundation::IPropertyValue>(),
_reloadEnvironmentVariables);
}

if (_guid == guid{})
Expand Down
1 change: 1 addition & 0 deletions src/cascadia/TerminalConnection/ConptyConnection.h
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ namespace winrt::Microsoft::Terminal::TerminalConnection::implementation
std::wstring _u16Str{};
std::array<char, 4096> _buffer{};
bool _passthroughMode{};
bool _reloadEnvironmentVariables{};

struct StartupInfoFromDefTerm
{
Expand Down
1 change: 1 addition & 0 deletions src/cascadia/TerminalSettingsModel/GlobalAppSettings.idl
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ namespace Microsoft.Terminal.Settings.Model
INHERITABLE_SETTING(Boolean, ForceFullRepaintRendering);
INHERITABLE_SETTING(Boolean, SoftwareRendering);
INHERITABLE_SETTING(Boolean, UseBackgroundImageForWindow);
INHERITABLE_SETTING(Boolean, ReloadEnvironmentVariables);
INHERITABLE_SETTING(Boolean, ForceVTInput);
INHERITABLE_SETTING(Boolean, DebugFeaturesEnabled);
INHERITABLE_SETTING(Boolean, StartOnUserLogin);
Expand Down
1 change: 1 addition & 0 deletions src/cascadia/TerminalSettingsModel/MTSMSettings.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ Author(s):
X(bool, ForceFullRepaintRendering, "experimental.rendering.forceFullRepaint", false) \
X(bool, SoftwareRendering, "experimental.rendering.software", false) \
X(bool, UseBackgroundImageForWindow, "experimental.useBackgroundImageForWindow", false) \
X(bool, ReloadEnvironmentVariables, "compatibility.reloadEnvironmentVariables", true) \
X(bool, ForceVTInput, "experimental.input.forceVT", false) \
X(bool, TrimBlockSelection, "trimBlockSelection", true) \
X(bool, DetectURLs, "experimental.detectURLs", true) \
Expand Down
Loading

0 comments on commit 5166148

Please sign in to comment.