Un-template executeGenerator

This commit is contained in:
Leonard Hecker 2021-09-17 21:19:54 +02:00
parent 76b78dcaa1
commit 239d2ef2b4
2 changed files with 38 additions and 34 deletions

View file

@ -67,6 +67,7 @@ namespace winrt::Microsoft::Terminal::Settings::Model::implementation
static bool _isValidProfileObject(const Json::Value& profileJson);
void _parse(const OriginTag origin, const winrt::hstring& source, const std::string_view& content, ParsedSettings& settings);
void _appendProfile(winrt::com_ptr<implementation::Profile>&& profile, ParsedSettings& settings);
void _executeGenerator(const IDynamicProfileGenerator& generator);
std::unordered_set<std::wstring_view> _ignoredNamespaces;
// We treat userSettings.profiles as an append-only array and will

View file

@ -127,40 +127,11 @@ SettingsLoader::SettingsLoader(const std::string_view& userJSON, const std::stri
// (meaning profiles specified by the application rather by the user).
void SettingsLoader::GenerateProfiles()
{
const auto executeGenerator = [&](const auto& generator) {
const auto generatorNamespace = generator.GetNamespace();
if (_ignoredNamespaces.count(generatorNamespace))
{
return;
}
const auto previousSize = inboxSettings.profiles.size();
try
{
generator.GenerateProfiles(inboxSettings.profiles);
}
CATCH_LOG_MSG("Dynamic Profile Namespace: \"%.*s\"", gsl::narrow<int>(generatorNamespace.size()), generatorNamespace.data())
// If the generator produced some profiles we're going to give them default attributes.
// By settings the Origin/Source/etc. here, we deduplicate some code and ensure they aren't missing accidentally.
if (inboxSettings.profiles.size() > previousSize)
{
const winrt::hstring source{ generatorNamespace };
for (const auto& profile : gsl::span(inboxSettings.profiles).subspan(previousSize))
{
profile->Origin(OriginTag::Generated);
profile->Source(source);
}
}
};
executeGenerator(PowershellCoreProfileGenerator{});
executeGenerator(WslDistroGenerator{});
executeGenerator(AzureCloudShellGenerator{});
executeGenerator(VsDevCmdGenerator{});
executeGenerator(VsDevShellGenerator{});
_executeGenerator(PowershellCoreProfileGenerator{});
_executeGenerator(WslDistroGenerator{});
_executeGenerator(AzureCloudShellGenerator{});
_executeGenerator(VsDevCmdGenerator{});
_executeGenerator(VsDevShellGenerator{});
}
// A new settings.json gets a special treatment:
@ -562,6 +533,38 @@ void SettingsLoader::_appendProfile(winrt::com_ptr<Profile>&& profile, ParsedSet
}
}
// As the name implies it executes a generator.
// Generated profiles are added to .inboxSettings. Used by GenerateProfiles().
void SettingsLoader::_executeGenerator(const IDynamicProfileGenerator& generator)
{
const auto generatorNamespace = generator.GetNamespace();
if (_ignoredNamespaces.count(generatorNamespace))
{
return;
}
const auto previousSize = inboxSettings.profiles.size();
try
{
generator.GenerateProfiles(inboxSettings.profiles);
}
CATCH_LOG_MSG("Dynamic Profile Namespace: \"%.*s\"", gsl::narrow<int>(generatorNamespace.size()), generatorNamespace.data())
// If the generator produced some profiles we're going to give them default attributes.
// By settings the Origin/Source/etc. here, we deduplicate some code and ensure they aren't missing accidentally.
if (inboxSettings.profiles.size() > previousSize)
{
const winrt::hstring source{ generatorNamespace };
for (const auto& profile : gsl::span(inboxSettings.profiles).subspan(previousSize))
{
profile->Origin(OriginTag::Generated);
profile->Source(source);
}
}
}
// Method Description:
// - Creates a CascadiaSettings from whatever's saved on disk, or instantiates
// a new one with the default values. If we're running as a packaged app,