Repository: microsoft/terminal
File: src/cascadia/TerminalControl/TermControl.cpp (C++)

Code before:
    const size_t TermControl::TaskbarState() const noexcept
    {
        return _core->TaskbarState();
    }

    // Method Description:
    // - Gets the internal taskbar progress value
    // Return Value:
    // - The taskbar progress of this control
    const size_t TermControl::TaskbarProgress() const noexcept
    {
        return _core->TaskbarProgress();
    }

    void TermControl::BellLightOn()
    {
        if (!_bellLightTimer)
        {
            // Start the timer, when the timer ticks we switch off the light
            DispatcherTimer invertTimer;
            invertTimer.Interval(std::chrono::milliseconds(TerminalWarningBellInterval));
            invertTimer.Tick({ get_weak(), &TermControl::_BellLightOff });
            invertTimer.Start();
            _bellLightTimer.emplace(std::move(invertTimer));

            // Switch on the light and animate the intensity to fade out
            VisualBellLight::SetIsTarget(RootGrid(), true);
            BellLight().CompositionLight().StartAnimation(L"Intensity", _bellLightAnimation);
        }
    }

    void TermControl::_BellLightOff(Windows::Foundation::IInspectable const& /* sender */,
                                    Windows::Foundation::IInspectable const& /* e */)
    {
        if (_bellLightTimer && !_closing)
        {
            // Stop the timer and switch off the light
            _bellLightTimer.value().Stop();
            _bellLightTimer = std::nullopt;
            VisualBellLight::SetIsTarget(RootGrid(), false);
        }
    }

    // Method Description:
    // - Checks whether the control is in a read-only mode (in this mode node input is sent to connection).
    // Return Value:
    // - True if the mode is read-only
    bool TermControl::ReadOnly() const noexcept
    {
        return _core->IsInReadOnlyMode();
    }

Review comment (suggestion):
BTW If you want to you can replace the entire `DispatchTimer` logic with a potentially simpler coroutine solution... Something like this (untested):

```cpp
winrt::fire_and_forget TermControl::BellLightOn()
{
    auto weakSelf = get_weak();
    
    VisualBellLight::SetIsTarget(RootGrid(), true);
    BellLight().CompositionLight().StartAnimation(L"Intensity", _bellLightAnimation);
    
    winrt::apartment_context ui_thread;
    co_await winrt::resume_after(TerminalWarningBellInterval);
    co_await ui_thread;
    
    if (auto self{ weakThis.get() })
    {
        VisualBellLight::SetIsTarget(self.RootGrid(), false);
    }
}
```

Code after:
    {
        return _core->TaskbarState();
    }

    // Method Description:
    // - Gets the internal taskbar progress value
    // Return Value:
    // - The taskbar progress of this control
    const size_t TermControl::TaskbarProgress() const noexcept
    {
        return _core->TaskbarProgress();
    }

    void TermControl::BellLightOn()
    {
        Windows::Foundation::Numerics::float2 zeroSize{ 0, 0 };
        // If the grid has 0 size or if the bell timer is
        // already active, do nothing
        if (RootGrid().ActualSize() != zeroSize && !_bellLightTimer)
        {
            // Start the timer, when the timer ticks we switch off the light
            DispatcherTimer invertTimer;
            invertTimer.Interval(std::chrono::milliseconds(TerminalWarningBellInterval));
            invertTimer.Tick({ get_weak(), &TermControl::_BellLightOff });
            invertTimer.Start();
            _bellLightTimer.emplace(std::move(invertTimer));

            // Switch on the light and animate the intensity to fade out
            VisualBellLight::SetIsTarget(RootGrid(), true);
            BellLight().CompositionLight().StartAnimation(L"Intensity", _bellLightAnimation);
        }
    }

    void TermControl::_BellLightOff(Windows::Foundation::IInspectable const& /* sender */,
                                    Windows::Foundation::IInspectable const& /* e */)
    {
        if (_bellLightTimer)
        {
            // Stop the timer and switch off the light
            _bellLightTimer->Stop();
            _bellLightTimer.reset();

            if (!_closing)
            {
                VisualBellLight::SetIsTarget(RootGrid(), false);
            }
        }
    }

    // Method Description:
    // - Checks whether the control is in a read-only mode (in this mode node input is sent to connection).