Repository: microsoft/terminal
File: src/cascadia/TerminalApp/AboutDialog.cpp (C++)

Code before:

        co_await wil::resume_foreground(strongThis->Dispatcher());
        UpdatesAvailable(false);
        CheckingForUpdates(true);

        try
        {
#ifdef WT_BRANDING_DEV
            // **DEV BRANDING**: Always sleep for three seconds and then report that
            // there is an update available. This lets us test the system.
            co_await winrt::resume_after(std::chrono::seconds{ 3 });
            co_await wil::resume_foreground(strongThis->Dispatcher());
            UpdatesAvailable(true);
#else // release build, likely has a store context
            if (auto storeContext{ winrt::Windows::Services::Store::StoreContext::GetDefault() })
            {
                const auto updates = co_await storeContext.GetAppAndOptionalStorePackageUpdatesAsync();
                co_await wil::resume_foreground(strongThis->Dispatcher());
                if (updates)
                {
                    const auto numUpdates = updates.Size();
                    if (numUpdates > 0)
                    {
                        UpdatesAvailable(true);
                    }
                }
            }
#endif
        }
        catch (...)
        {
            // do nothing on failure
        }

        co_await wil::resume_foreground(strongThis->Dispatcher());
        CheckingForUpdates(false);
    }
}


Review comment (suggestion):
may want `if (auto availabilityResult = co_await lookedUpPackage.CheckUpdateAvailabilityAsync()) {...}`

cause you know, sometimes these APIs just decide to return null

Code after:

        co_await wil::resume_foreground(strongThis->Dispatcher());
        UpdatesAvailable(false);
        CheckingForUpdates(true);

        try
        {
#ifdef WT_BRANDING_DEV
            // **DEV BRANDING**: Always sleep for three seconds and then report that
            // there is an update available. This lets us test the system.
            co_await winrt::resume_after(std::chrono::seconds{ 3 });
            co_await wil::resume_foreground(strongThis->Dispatcher());
            UpdatesAvailable(true);
#else // release build, likely has a store context
            bool packageManagerAnswered{ false };

            try
            {
                if (auto currentPackage{ winrt::Windows::ApplicationModel::Package::Current() })
                {
                    // We need to look up our package in the Package Manager; we cannot use Current
                    winrt::Windows::Management::Deployment::PackageManager pm;
                    if (auto lookedUpPackage{ pm.FindPackageForUser(winrt::hstring{}, currentPackage.Id().FullName()) })
                    {
                        using winrt::Windows::ApplicationModel::PackageUpdateAvailability;
                        auto availabilityResult = co_await lookedUpPackage.CheckUpdateAvailabilityAsync();
                        co_await wil::resume_foreground(strongThis->Dispatcher());
                        auto availability = availabilityResult.Availability();
                        switch (availability)
                        {
                        case PackageUpdateAvailability::Available:
                        case PackageUpdateAvailability::Required:
                        case PackageUpdateAvailability::NoUpdates:
                            UpdatesAvailable(availability != PackageUpdateAvailability::NoUpdates);
                            packageManagerAnswered = true;
                            break;
                        case PackageUpdateAvailability::Error:
                        case PackageUpdateAvailability::Unknown:
                        default:
                            // Do not set packageManagerAnswered, which will trigger the store check.
                            break;
                        }
                    }
                }
            }
            catch (...)
            {
            } // Do nothing on failure

            if (!packageManagerAnswered)
            {