From 45f3e1debbbd0c4e45ccf2a140b1ebbffdf9eafe Mon Sep 17 00:00:00 2001 From: "Gordon Lam (SH)" Date: Thu, 5 Feb 2026 15:13:53 -0800 Subject: [PATCH] Revert "refactor(updating): update async methods to use std::expected and co_await" This reverts commit 743feb7ce3d01f63db132193d414654151529c70. --- src/Update/PowerToys.Update.cpp | 10 ++------- src/common/updating/updating.cpp | 35 +++++++++++++------------------- src/common/updating/updating.h | 6 +++--- src/runner/UpdateUtils.cpp | 18 +++------------- 4 files changed, 22 insertions(+), 47 deletions(-) diff --git a/src/Update/PowerToys.Update.cpp b/src/Update/PowerToys.Update.cpp index 1715140e51..07a6a1a730 100644 --- a/src/Update/PowerToys.Update.cpp +++ b/src/Update/PowerToys.Update.cpp @@ -57,12 +57,7 @@ std::optional ObtainInstaller(bool& isUpToDate) auto state = UpdateState::read(); -#if USE_STD_EXPECTED - std::expected new_version_info; -#else - nonstd::expected new_version_info; -#endif - get_github_version_info_async(false, new_version_info).get(); + const auto new_version_info = get_github_version_info_async(); if (std::holds_alternative(*new_version_info)) { isUpToDate = true; @@ -81,8 +76,7 @@ std::optional ObtainInstaller(bool& isUpToDate) // Cleanup old updates before downloading the latest updating::cleanup_updates(); - std::optional downloaded_installer; - download_new_version(std::get(*new_version_info), downloaded_installer).get(); + auto downloaded_installer = download_new_version(std::get(*new_version_info)); if (!downloaded_installer) { Logger::error("Couldn't download new installer"); diff --git a/src/common/updating/updating.cpp b/src/common/updating/updating.cpp index 27c21d5e8e..977daf46a6 100644 --- a/src/common/updating/updating.cpp +++ b/src/common/updating/updating.cpp @@ -83,20 +83,18 @@ namespace updating #pragma warning(push) #pragma warning(disable : 4702) #if USE_STD_EXPECTED - winrt::Windows::Foundation::IAsyncAction get_github_version_info_async(const bool prerelease, std::expected& result) + std::expected get_github_version_info_async(const bool prerelease) #else - winrt::Windows::Foundation::IAsyncAction get_github_version_info_async(const bool prerelease, nonstd::expected& result) + nonstd::expected get_github_version_info_async(const bool prerelease) #endif { // If the current version starts with 0.0.*, it means we're on a local build from a farm and shouldn't check for updates. if constexpr (VERSION_MAJOR == 0 && VERSION_MINOR == 0) { #if USE_STD_EXPECTED - result = std::unexpected(LOCAL_BUILD_ERROR); - co_return; + return std::unexpected(LOCAL_BUILD_ERROR); #else - result = nonstd::make_unexpected(LOCAL_BUILD_ERROR); - co_return; + return nonstd::make_unexpected(LOCAL_BUILD_ERROR); #endif } @@ -109,7 +107,7 @@ namespace updating if (prerelease) { - const auto body = co_await client.request(Uri{ ALL_RELEASES_ENDPOINT }); + const auto body = client.request(Uri{ ALL_RELEASES_ENDPOINT }).get(); for (const auto& json : json::JsonValue::Parse(body).GetArray()) { auto potential_release_object = json.GetObjectW(); @@ -127,7 +125,7 @@ namespace updating } else { - const auto body = co_await client.request(Uri{ LATEST_RELEASE_ENDPOINT }); + const auto body = client.request(Uri{ LATEST_RELEASE_ENDPOINT }).get(); release_object = json::JsonValue::Parse(body).GetObjectW(); if (auto extracted_version = extract_version_from_release_object(release_object)) { @@ -137,26 +135,23 @@ namespace updating if (github_version <= current_version) { - result = version_up_to_date{}; - co_return; + return version_up_to_date{}; } auto [installer_download_url, installer_filename] = extract_installer_asset_download_info(release_object); - result = new_version_download_info{ extract_release_page_url(release_object), + return new_version_download_info{ extract_release_page_url(release_object), std::move(github_version), std::move(installer_download_url), std::move(installer_filename) }; - co_return; } catch (...) { } #if USE_STD_EXPECTED - result = std::unexpected(NETWORK_ERROR); + return std::unexpected(NETWORK_ERROR); #else - result = nonstd::make_unexpected(NETWORK_ERROR); + return nonstd::make_unexpected(NETWORK_ERROR); #endif - co_return; } #pragma warning(pop) @@ -175,13 +170,12 @@ namespace updating return !ec ? std::optional{ installer_download_path } : std::nullopt; } - winrt::Windows::Foundation::IAsyncAction download_new_version(const new_version_download_info& new_version, std::optional& result) + std::optional download_new_version(const new_version_download_info& new_version) { auto installer_download_path = create_download_path(); if (!installer_download_path) { - result = std::nullopt; - co_return; + return std::nullopt; } *installer_download_path /= new_version.installer_filename; @@ -192,7 +186,7 @@ namespace updating try { http::HttpClient client; - co_await client.download(new_version.installer_download_url, *installer_download_path); + client.download(new_version.installer_download_url, *installer_download_path).get(); download_success = true; break; } @@ -201,8 +195,7 @@ namespace updating // reattempt to download or do nothing } } - result = download_success ? installer_download_path : std::nullopt; - co_return; + return download_success ? installer_download_path : std::nullopt; } void cleanup_updates() diff --git a/src/common/updating/updating.h b/src/common/updating/updating.h index 2e7239eefc..9aaee7739b 100644 --- a/src/common/updating/updating.h +++ b/src/common/updating/updating.h @@ -31,12 +31,12 @@ namespace updating }; using github_version_info = std::variant; - winrt::Windows::Foundation::IAsyncAction download_new_version(const new_version_download_info& new_version, std::optional& result); + std::optional download_new_version(const new_version_download_info& new_version); std::filesystem::path get_pending_updates_path(); #if USE_STD_EXPECTED - winrt::Windows::Foundation::IAsyncAction get_github_version_info_async(const bool prerelease, std::expected& result); + std::expected get_github_version_info_async(const bool prerelease = false); #else - winrt::Windows::Foundation::IAsyncAction get_github_version_info_async(const bool prerelease, nonstd::expected& result); + nonstd::expected get_github_version_info_async(const bool prerelease = false); #endif void cleanup_updates(); diff --git a/src/runner/UpdateUtils.cpp b/src/runner/UpdateUtils.cpp index ca23db7271..7e4c007a3f 100644 --- a/src/runner/UpdateUtils.cpp +++ b/src/runner/UpdateUtils.cpp @@ -173,9 +173,7 @@ void ProcessNewVersionInfo(const github_version_info& version_info, // Cleanup old updates before downloading the latest updating::cleanup_updates(); - std::optional downloaded_installer; - download_new_version(new_version_info, downloaded_installer).get(); - if (downloaded_installer) + if (download_new_version(new_version_info)) { state.state = UpdateState::readyToInstall; state.downloadedInstallerFilename = new_version_info.installer_filename; @@ -234,12 +232,7 @@ void PeriodicUpdateWorker() bool version_info_obtained = false; try { -#if USE_STD_EXPECTED - std::expected new_version_info; -#else - nonstd::expected new_version_info; -#endif - get_github_version_info_async(false, new_version_info).get(); + const auto new_version_info = get_github_version_info_async(); if (new_version_info.has_value()) { version_info_obtained = true; @@ -279,12 +272,7 @@ void CheckForUpdatesCallback() auto state = UpdateState::read(); try { - #if USE_STD_EXPECTED - std::expected new_version_info; - #else - nonstd::expected new_version_info; - #endif - get_github_version_info_async(false, new_version_info).get(); + auto new_version_info = get_github_version_info_async(); if (!new_version_info) { // We couldn't get a new version from github for some reason, log error