Repository: microsoft/terminal
File: src/host/srvinit.cpp (C++)

Code before:

    FontInfoBase::s_SetFontDefaultList(Globals.pFontDefaultList);

    // Check if this conhost is allowed to delegate its activities to another.
    // If so, look up the registered default console handler.
    bool isEnabled = false;
    if (SUCCEEDED(Microsoft::Console::Internal::DefaultApp::CheckDefaultAppPolicy(isEnabled)) && isEnabled)
    {
        IID delegationClsid;
        if (SUCCEEDED(DelegationConfig::s_GetDefaultConsoleId(delegationClsid)))
        {
            Globals.handoffConsoleClsid = delegationClsid;
        }
        if (SUCCEEDED(DelegationConfig::s_GetDefaultTerminalId(delegationClsid)))
        {
            Globals.handoffTerminalClsid = delegationClsid;
        }
    }

    // Create the accessibility notifier early in the startup process.
    // We pass along the PTY mode as it won't need to make a notifier then.
    // The notifiers use expensive legacy MSAA events and the PTY isn't even responsible
    // for the terminal user interface, so we should set ourselves up to skip all
    // those notifications and the mathematical calculations required to send those events
    // for performance reasons.
    RETURN_IF_FAILED(ServiceLocator::CreateAccessibilityNotifier(args->InConptyMode()));

    // Removed allocation of scroll buffer here.
    return S_OK;
}
CATCH_RETURN()

static bool s_IsOnDesktop()
{
    // Persist this across calls so we don't dig it out a whole bunch of times. Once is good enough for the system.
    static bool fAlreadyQueried = false;
    static bool fIsDesktop = false;

    if (!fAlreadyQueried)
    {
        Microsoft::Console::Interactivity::ApiLevel level;
        const NTSTATUS status = Microsoft::Console::Interactivity::ApiDetector::DetectNtUserWindow(&level);
        LOG_IF_NTSTATUS_FAILED(status);

        if (NT_SUCCESS(status))
        {
            switch (level)
            {
            case Microsoft::Console::Interactivity::ApiLevel::OneCore:
                fIsDesktop = false;
                break;

Review comment (suggestion):
I dunno about this. It's less clear (comment aside) that "if this is `true`, `CreateBlah...` does nothing". Why is the decision made in ServiceLocator, rather than ServiceLocator's user?

If ServiceLocator then stored the value and remembered, "I was asked to not create one because i am in a PTY, I will make later decisions based on this" it would make sense... but after all... ServiceLocator's job is to _locate services_ and we would make it easier by simply not giving it services if it isn't supposed to have them.

Code after:

    FontInfoBase::s_SetFontDefaultList(Globals.pFontDefaultList);

    // Check if this conhost is allowed to delegate its activities to another.
    // If so, look up the registered default console handler.
    bool isEnabled = false;
    if (SUCCEEDED(Microsoft::Console::Internal::DefaultApp::CheckDefaultAppPolicy(isEnabled)) && isEnabled)
    {
        IID delegationClsid;
        if (SUCCEEDED(DelegationConfig::s_GetDefaultConsoleId(delegationClsid)))
        {
            Globals.handoffConsoleClsid = delegationClsid;
        }
        if (SUCCEEDED(DelegationConfig::s_GetDefaultTerminalId(delegationClsid)))
        {
            Globals.handoffTerminalClsid = delegationClsid;
        }
    }

    // Create the accessibility notifier early in the startup process.
    // Only create if we're not in PTY mode.
    // The notifiers use expensive legacy MSAA events and the PTY isn't even responsible
    // for the terminal user interface, so we should set ourselves up to skip all
    // those notifications and the mathematical calculations required to send those events
    // for performance reasons.
    if (!args->InConptyMode())
    {
        RETURN_IF_FAILED(ServiceLocator::CreateAccessibilityNotifier());
    }

    // Removed allocation of scroll buffer here.
    return S_OK;
}
CATCH_RETURN()

static bool s_IsOnDesktop()
{
    // Persist this across calls so we don't dig it out a whole bunch of times. Once is good enough for the system.
    static bool fAlreadyQueried = false;
    static bool fIsDesktop = false;

    if (!fAlreadyQueried)
    {
        Microsoft::Console::Interactivity::ApiLevel level;
        const NTSTATUS status = Microsoft::Console::Interactivity::ApiDetector::DetectNtUserWindow(&level);
        LOG_IF_NTSTATUS_FAILED(status);

        if (NT_SUCCESS(status))
        {
            switch (level)
            {