Check key existance before getting it from JSON (#1632)

This commit is contained in:
vldmr11080 2020-03-19 09:21:10 +01:00 committed by GitHub
parent 81710ff3b0
commit 57f763b0b6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -207,22 +207,22 @@ void start_initial_powertoys()
try
{
general_settings = load_general_settings();
json::JsonObject enabled = general_settings.GetNamedObject(L"enabled");
for (const auto& enabled_element : enabled)
if (general_settings.HasKey(L"enabled"))
{
if (enabled_element.Value().GetBoolean())
json::JsonObject enabled = general_settings.GetNamedObject(L"enabled");
for (const auto& enabled_element : enabled)
{
// Enable this powertoy.
powertoys_to_enable.emplace(enabled_element.Key());
if (enabled_element.Value().GetBoolean())
{
// Enable this powertoy.
powertoys_to_enable.emplace(enabled_element.Key());
}
}
only_enable_some_powertoys = true;
}
only_enable_some_powertoys = true;
}
catch (...)
{
// Couldn't read the general settings correctly.
// Load all powertoys.
// TODO: notify user about invalid json config
only_enable_some_powertoys = false;
}