Repository: microsoft/PowerToys
File: src/runner/general_settings.cpp (C++)

Code before:
            {
                Logger::info(L"apply_general_settings: Enabling powertoy {}", name);
                powertoy->enable();
            }
            else
            {
                Logger::info(L"apply_general_settings: Disabling powertoy {}", name);
                powertoy->disable();
            }
            // Sync the hotkey state with the module state, so it can be removed for disabled modules.
            powertoy.UpdateHotkeyEx();
        }
    }

    if (json::has(general_configs, L"theme", json::JsonValueType::String))
    {
        settings_theme = general_configs.GetNamedString(L"theme");
    }

    if (json::has(general_configs, L"hide_tray_icon", json::JsonValueType::Boolean))
    {
        hide_tray_icon = general_configs.GetNamedBoolean(L"hide_tray_icon");
        // Update tray icon visibility when setting is toggled
        set_tray_icon_visible(!hide_tray_icon);
    }

    if (save)
    {
        GeneralSettings save_settings = get_general_settings();
        PTSettingsHelper::save_general_settings(save_settings.to_json());
        Trace::SettingsChanged(save_settings);
    }
}

void start_enabled_powertoys()
{
    std::unordered_set<std::wstring> powertoys_to_disable;
    std::unordered_map<std::wstring, powertoys_gpo::gpo_rule_configured_t> powertoys_gpo_configuration;
    // Take into account default values supplied by modules themselves and gpo configurations
    for (auto& [name, powertoy] : modules())
    {
        auto gpo_rule = powertoy->gpo_policy_enabled_configuration();
        powertoys_gpo_configuration[name] = gpo_rule;
        if (gpo_rule == powertoys_gpo::gpo_rule_configured_unavailable)
        {
            Logger::warn(L"start_enabled_powertoys: couldn't read the gpo rule for Powertoy {}", name);
        }
        if (gpo_rule == powertoys_gpo::gpo_rule_configured_wrong_value)
        {
            Logger::warn(L"start_enabled_powertoys: gpo rule for Powertoy {} is set to an unknown value", name);
        }

Review comment (suggestion):
The addition of hide_tray_icon in apply_general_settings is well-implemented, and toggling the tray icon visibility based on this setting improves user control. Consider adding a brief comment to explain the specific use case or behavior, as it may help maintainers understand its purpose during future updates.


Code after:
            bool target_enabled = value.GetBoolean();

            auto gpo_rule = powertoy->gpo_policy_enabled_configuration();
            if (gpo_rule == powertoys_gpo::gpo_rule_configured_enabled || gpo_rule == powertoys_gpo::gpo_rule_configured_disabled)
            {
                // Apply the GPO Rule.
                target_enabled = gpo_rule == powertoys_gpo::gpo_rule_configured_enabled;
            }

            if (module_inst_enabled == target_enabled)
            {
                continue;
            }
            if (target_enabled)
            {
                Logger::info(L"apply_general_settings: Enabling powertoy {}", name);
                powertoy->enable();
            }
            else
            {
                Logger::info(L"apply_general_settings: Disabling powertoy {}", name);
                powertoy->disable();
            }
            // Sync the hotkey state with the module state, so it can be removed for disabled modules.
            powertoy.UpdateHotkeyEx();
        }
    }

    if (json::has(general_configs, L"theme", json::JsonValueType::String))
    {
        settings_theme = general_configs.GetNamedString(L"theme");
    }

    if (json::has(general_configs, L"show_tray_icon", json::JsonValueType::Boolean))
    {
        show_tray_icon = general_configs.GetNamedBoolean(L"show_tray_icon");
        // Update tray icon visibility when setting is toggled
        set_tray_icon_visible(show_tray_icon);
    }

    if (save)
    {
        GeneralSettings save_settings = get_general_settings();
        PTSettingsHelper::save_general_settings(save_settings.to_json());
        Trace::SettingsChanged(save_settings);
    }
}

void start_enabled_powertoys()
{
    std::unordered_set<std::wstring> powertoys_to_disable;