Skip to content

Commit

Permalink
add comments throughout
Browse files Browse the repository at this point in the history
  • Loading branch information
PankajBhojwani committed Sep 18, 2020
1 parent cd6bdb3 commit f7bbc92
Showing 1 changed file with 27 additions and 2 deletions.
29 changes: 27 additions & 2 deletions src/cascadia/TerminalApp/CascadiaSettingsSerialization.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -391,6 +391,7 @@ void CascadiaSettings::_LoadDynamicProfiles()
// property, we'll ensure that the corresponding folders do not get searched
void CascadiaSettings::_LoadProtoExtensions()
{
// First, accumulate the namespaces the user wants to ignore
std::unordered_set<std::wstring> ignoredNamespaces;
const auto disabledProfileSources = CascadiaSettings::_GetDisabledProfileSourcesJsonObject(_userSettings);
if (disabledProfileSources.isArray())
Expand All @@ -401,20 +402,29 @@ void CascadiaSettings::_LoadProtoExtensions()
}
}

// Search through the local app data folder if its not in ignoredNamespaces
if ((ignoredNamespaces.find(L"local") == ignoredNamespaces.end()) && std::filesystem::exists(wil::ExpandEnvironmentStringsW<std::wstring>(L"%LOCALAPPDATA%\\Microsoft\\Windows\\Terminal")))
{
const auto jsonFiles = _AccumulateJsonFilesInDirectory(LocalAppDataFolder);
_AddOrModifyProfiles(jsonFiles, winrt::to_hstring(LocalSource));
}

// Search through the global app data folder if its not in ignoredNamespaces
if ((ignoredNamespaces.find(L"global") == ignoredNamespaces.end()) && std::filesystem::exists(wil::ExpandEnvironmentStringsW<std::wstring>(L"%ProgramData%\\Microsoft\\Windows\\Terminal")))
{
const auto jsonFiles = _AccumulateJsonFilesInDirectory(ProgramDataFolder);
_AddOrModifyProfiles(jsonFiles, winrt::to_hstring(GlobalSource));
}

// Search through app extensions if its not in ignoredNamespaces
if (ignoredNamespaces.find(L"app") == ignoredNamespaces.end())
{
// Gets the catalog of extensions with the name "Microsoft.com.Terminal"
const auto catalog = Windows::ApplicationModel::AppExtensions::AppExtensionCatalog::Open(winrt::to_hstring(AppExtensionHostName));

// Extracting the list of extensions from the catalog is an async operation, but since
// we are on a UI thread - and so cannot call a blocking operation like .get() - we use
// a mutex and condition variable
std::condition_variable cv;
std::mutex mtx;
Windows::Foundation::Collections::IVectorView<Windows::ApplicationModel::AppExtensions::AppExtension> extensions;
Expand All @@ -434,6 +444,8 @@ void CascadiaSettings::_LoadProtoExtensions()

for (auto ext : extensions)
{
// Likewise, getting the public folder from an extension is an async operation
// So we use another mutex and condition variable
std::condition_variable cv2;
std::mutex mtx2;
Windows::Storage::StorageFolder foundFolder{ nullptr };
Expand Down Expand Up @@ -470,7 +482,10 @@ void CascadiaSettings::_LoadProtoExtensions()
std::unordered_set<std::string> CascadiaSettings::_AccumulateJsonFilesInDirectory(const std::wstring_view directory)
{
std::unordered_set<std::string> jsonFiles;

// Expand out environment strings like %LOCALAPPDATA% and %ProgramData%
const std::filesystem::path root{ wil::ExpandEnvironmentStringsW<std::wstring>(directory.data()) };

for (auto& protoExt : std::filesystem::directory_iterator(root))
{
if (protoExt.path().extension() == jsonExtension)
Expand Down Expand Up @@ -503,12 +518,15 @@ void CascadiaSettings::_AddOrModifyProfiles(const std::unordered_set<std::string
{
for (const auto file : files)
{
// A file could have many new profiles/many profiles it wants to modify/many new colour schemes
// so we first parse the entire file into one json object
Json::Value fullFile;

_ParseJsonInto(file.data(), fullFile);

if (fullFile.isMember(JsonKey(ProfilesKey)))
{
// Now we separately get each stub that modifies/adds a profile
for (const auto profileStub : fullFile[JsonKey(ProfilesKey)])
{
auto matchingProfile = _FindMatchingProfile(profileStub);
Expand All @@ -519,14 +537,19 @@ void CascadiaSettings::_AddOrModifyProfiles(const std::unordered_set<std::string
}
else
{
// This is a new profile
// This is a new profile, check that it meets our minmum requirements first
// (it must have at least a name and a commandline)
if (profileStub.isMember(JsonKey(NameKey)) && profileStub.isMember(JsonKey(CommandLineKey)))
{
auto newProfile = winrt::make_self<Profile>();
if (_userDefaultProfileSettings)
{
newProfile->LayerJson(_userDefaultProfileSettings);
}

// Make sure to give the new profile a source, then we add it to our list of profiles
// We don't make modifications to the user profiles yet, that will happen when
// _AppendDynamicProfilesToUserSettings() is called later
newProfile->LayerJson(profileStub);
newProfile->Source(source);
_profiles.Append(*newProfile);
Expand All @@ -537,15 +560,17 @@ void CascadiaSettings::_AddOrModifyProfiles(const std::unordered_set<std::string

if (fullFile.isMember(JsonKey(SchemesKey)))
{
// Now we separately get each stub that adds a colour scheme
for (const auto schemeStub : fullFile[JsonKey(SchemesKey)])
{
auto matchingScheme = _FindMatchingColorScheme(schemeStub);
if (matchingScheme)
{
// we do not allow modifications to existing colour schemes
// We do not allow modifications to existing colour schemes
}
else
{
// This is a new colour scheme, make sure it meets our minimum requirements
if (schemeStub.isMember(JsonKey(NameKey)) && schemeStub.isMember(JsonKey(BackgroundKey)) && schemeStub.isMember(JsonKey(ForegroundKey)))
{
const auto newScheme = ColorScheme::FromJson(schemeStub);
Expand Down

1 comment on commit f7bbc92

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

New misspellings found, please review:

  • minmum
To accept these changes, run the following commands
perl -e '
my @expect_files=qw('".github/actions/spell-check/expect/alphabet.txt
.github/actions/spell-check/expect/expect.txt
.github/actions/spell-check/expect/web.txt"');
@ARGV=@expect_files;
my @stale=qw('"Autogenerated debugbreak DECLL DECSMBV Inplace notypeopt restrictederrorinfo Scs Switchto Wlk "');
my $re=join "|", @stale;
my $suffix=".".time();
my $previous="";
sub maybe_unlink { unlink($_[0]) if $_[0]; }
while (<>) {
  if ($ARGV ne $old_argv) { maybe_unlink($previous); $previous="$ARGV$suffix"; rename($ARGV, $previous); open(ARGV_OUT, ">$ARGV"); select(ARGV_OUT); $old_argv = $ARGV; }
  next if /^($re)(?:$| .*)/; print;
}; maybe_unlink($previous);'
perl -e '
my $new_expect_file=".github/actions/spell-check/expect/f7bbc92ed943b6b07db286342097b5e477e8c30d.txt";
open FILE, q{<}, $new_expect_file; chomp(my @words = <FILE>); close FILE;
my @add=qw('"autogenerated inplace minmum "');
my %items; @items{@words} = @words x (1); @items{@add} = @add x (1);
@words = sort {lc($a) cmp lc($b)} keys %items;
open FILE, q{>}, $new_expect_file; for my $word (@words) { print FILE "$word\n" if $word =~ /\w/; };
close FILE;'
git add .github/actions/spell-check/expect || echo '... you want to ensure .github/actions/spell-check/expect/f7bbc92ed943b6b07db286342097b5e477e8c30d.txt is added to your repository...'
✏️ Contributor please read this

By default the command suggestion will generate a file named based on your commit. That's generally ok as long as you add the file to your commit. Someone can reorganize it later.

⚠️ The command is written for posix shells. You can copy the contents of each perl command excluding the outer ' marks and dropping any '"/"' quotation mark pairs into a file and then run perl file.pl from the root of the repository to run the code. Alternatively, you can manually insert the items...

If the listed items are:

  • ... misspelled, then please correct them instead of using the command.
  • ... names, please add them to .github/actions/spell-check/dictionary/names.txt.
  • ... APIs, you can add them to a file in .github/actions/spell-check/dictionary/.
  • ... just things you're using, please add them to an appropriate file in .github/actions/spell-check/expect/.
  • ... tokens you only need in one place and shouldn't generally be used, you can add an item in an appropriate file in .github/actions/spell-check/patterns/.

See the README.md in each directory for more information.

🔬 You can test your commits without appending to a PR by creating a new branch with that extra change and pushing it to your fork. The :check-spelling action will run in response to your push -- it doesn't require an open pull request. By using such a branch, you can limit the number of typos your peers see you make. 😉

⚠️ Reviewers

At present, the action that triggered this message will not show its ❌ in this PR unless the branch is within this repository.
Thus, you should make sure that this comment has been addressed before encouraging the merge bot to merge this PR.

Please sign in to comment.