Repository: microsoft/terminal
File: src/cascadia/WindowsTerminal/AppHost.cpp (C++)

Code before:

    // Switch to the BG thread - anything x-proc must happen on a BG thread
    co_await winrt::resume_background();

    if (auto peasant{ _windowManager.CurrentWindow() })
    {
        Remoting::RenameRequestArgs requestArgs{ args.ProposedName() };

        peasant.RequestRename(requestArgs);

        // Switch back to the UI thread. Setting the WindowName needs to happen
        // on the UI thread, because it'll raise a PropertyChanged event
        co_await ui_thread;

        if (requestArgs.Succeeded())
        {
            _logic.WindowName(args.ProposedName());
        }
        else
        {
            _logic.RenameFailed();
        }
    }
}

double _opacityFromBrush(const winrt::Windows::UI::Xaml::Media::Brush& brush)
{
    if (auto acrylic = brush.try_as<winrt::Windows::UI::Xaml::Media::AcrylicBrush>())
    {
        return acrylic.TintOpacity();
    }
    else if (auto solidColor = brush.try_as<winrt::Windows::UI::Xaml::Media::SolidColorBrush>())
    {
        return solidColor.Opacity();
    }
    return 1.0;
}

void AppHost::_updateTheme()
{
    auto theme = _logic.Theme();

    _window->OnApplicationThemeChanged(theme.RequestedTheme());

    const auto b = _logic.TitlebarBrush();
    const auto color = ThemeColor::ColorFromBrush(b);
    const auto colorOpacity = b ? color.A / 255.0 : 0.0;
    const auto brushOpacity = _opacityFromBrush(b);
    const auto opacity = std::min(colorOpacity, brushOpacity);
    _window->UseMica(theme.Window() ? theme.Window().UseMica() : false, opacity);
}

Review comment (suggestion):
```suggestion
static double _opacityFromBrush(const winrt::Windows::UI::Xaml::Media::Brush& brush)
```

Code after:

    // Switch to the BG thread - anything x-proc must happen on a BG thread
    co_await winrt::resume_background();

    if (auto peasant{ _windowManager.CurrentWindow() })
    {
        Remoting::RenameRequestArgs requestArgs{ args.ProposedName() };

        peasant.RequestRename(requestArgs);

        // Switch back to the UI thread. Setting the WindowName needs to happen
        // on the UI thread, because it'll raise a PropertyChanged event
        co_await ui_thread;

        if (requestArgs.Succeeded())
        {
            _logic.WindowName(args.ProposedName());
        }
        else
        {
            _logic.RenameFailed();
        }
    }
}

static double _opacityFromBrush(const winrt::Windows::UI::Xaml::Media::Brush& brush)
{
    if (auto acrylic = brush.try_as<winrt::Windows::UI::Xaml::Media::AcrylicBrush>())
    {
        return acrylic.TintOpacity();
    }
    else if (auto solidColor = brush.try_as<winrt::Windows::UI::Xaml::Media::SolidColorBrush>())
    {
        return solidColor.Opacity();
    }
    return 1.0;
}

static bool _isActuallyDarkTheme(const auto requestedTheme)
{
    switch (requestedTheme)
    {
    case winrt::Windows::UI::Xaml::ElementTheme::Light:
        return false;
    case winrt::Windows::UI::Xaml::ElementTheme::Dark:
        return true;
    case winrt::Windows::UI::Xaml::ElementTheme::Default:
    default:
        return Theme::IsSystemInDarkTheme();
    }
}