diff --git a/src/Update/PowerToys.Update.cpp b/src/Update/PowerToys.Update.cpp index 1e16598c43..07a6a1a730 100644 --- a/src/Update/PowerToys.Update.cpp +++ b/src/Update/PowerToys.Update.cpp @@ -57,7 +57,7 @@ std::optional ObtainInstaller(bool& isUpToDate) auto state = UpdateState::read(); - const auto new_version_info = get_github_version_info_async().get(); + const auto new_version_info = get_github_version_info_async(); if (std::holds_alternative(*new_version_info)) { isUpToDate = true; @@ -76,7 +76,7 @@ std::optional ObtainInstaller(bool& isUpToDate) // Cleanup old updates before downloading the latest updating::cleanup_updates(); - auto downloaded_installer = download_new_version(std::get(*new_version_info)).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/installer.cpp b/src/common/updating/installer.cpp index 2be4a97c5f..0e491392d5 100644 --- a/src/common/updating/installer.cpp +++ b/src/common/updating/installer.cpp @@ -18,7 +18,7 @@ namespace // Strings in this namespace should not be localized namespace updating { - std::future uninstall_previous_msix_version_async() + winrt::Windows::Foundation::IAsyncOperation uninstall_previous_msix_version_async() { winrt::Windows::Management::Deployment::PackageManager package_manager; diff --git a/src/common/updating/installer.h b/src/common/updating/installer.h index 5f2ca4bbb9..1aac029665 100644 --- a/src/common/updating/installer.h +++ b/src/common/updating/installer.h @@ -2,11 +2,11 @@ #include #include -#include +#include #include namespace updating { - std::future uninstall_previous_msix_version_async(); + winrt::Windows::Foundation::IAsyncOperation uninstall_previous_msix_version_async(); } \ No newline at end of file diff --git a/src/common/updating/updating.cpp b/src/common/updating/updating.cpp index 9d80662d54..977daf46a6 100644 --- a/src/common/updating/updating.cpp +++ b/src/common/updating/updating.cpp @@ -83,18 +83,18 @@ namespace updating #pragma warning(push) #pragma warning(disable : 4702) #if USE_STD_EXPECTED - std::future> get_github_version_info_async(const bool prerelease) + std::expected get_github_version_info_async(const bool prerelease) #else - std::future> get_github_version_info_async(const bool prerelease) + 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 - co_return std::unexpected(LOCAL_BUILD_ERROR); + return std::unexpected(LOCAL_BUILD_ERROR); #else - co_return nonstd::make_unexpected(LOCAL_BUILD_ERROR); + return nonstd::make_unexpected(LOCAL_BUILD_ERROR); #endif } @@ -107,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(); @@ -125,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)) { @@ -135,11 +135,11 @@ namespace updating if (github_version <= current_version) { - co_return version_up_to_date{}; + return version_up_to_date{}; } auto [installer_download_url, installer_filename] = extract_installer_asset_download_info(release_object); - co_return 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) }; @@ -148,9 +148,9 @@ namespace updating { } #if USE_STD_EXPECTED - co_return std::unexpected(NETWORK_ERROR); + return std::unexpected(NETWORK_ERROR); #else - co_return nonstd::make_unexpected(NETWORK_ERROR); + return nonstd::make_unexpected(NETWORK_ERROR); #endif } #pragma warning(pop) @@ -170,12 +170,12 @@ namespace updating return !ec ? std::optional{ installer_download_path } : std::nullopt; } - std::future> download_new_version(const new_version_download_info& new_version) + std::optional download_new_version(const new_version_download_info& new_version) { auto installer_download_path = create_download_path(); if (!installer_download_path) { - co_return std::nullopt; + return std::nullopt; } *installer_download_path /= new_version.installer_filename; @@ -186,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; } @@ -195,7 +195,7 @@ namespace updating // reattempt to download or do nothing } } - co_return download_success ? installer_download_path : std::nullopt; + 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 148a5e5b25..9aaee7739b 100644 --- a/src/common/updating/updating.h +++ b/src/common/updating/updating.h @@ -2,7 +2,6 @@ #include #include -#include #include #include #include @@ -32,12 +31,12 @@ namespace updating }; using github_version_info = std::variant; - std::future> download_new_version(const new_version_download_info& new_version); + std::optional download_new_version(const new_version_download_info& new_version); std::filesystem::path get_pending_updates_path(); #if USE_STD_EXPECTED - std::future> get_github_version_info_async(const bool prerelease = false); + std::expected get_github_version_info_async(const bool prerelease = false); #else - std::future> get_github_version_info_async(const bool prerelease = false); + nonstd::expected get_github_version_info_async(const bool prerelease = false); #endif void cleanup_updates(); diff --git a/src/common/updating/updating.vcxproj b/src/common/updating/updating.vcxproj index ed642982cd..cf3fb9b175 100644 --- a/src/common/updating/updating.vcxproj +++ b/src/common/updating/updating.vcxproj @@ -28,8 +28,6 @@ ..\;..\..\;..\..\..\;%(AdditionalIncludeDirectories) _LIB;%(PreprocessorDefinitions) - - /await %(AdditionalOptions) Version.lib diff --git a/src/common/utils/HttpClient.h b/src/common/utils/HttpClient.h index 8726368fbb..29575ce1c7 100644 --- a/src/common/utils/HttpClient.h +++ b/src/common/utils/HttpClient.h @@ -1,6 +1,6 @@ #pragma once -#include +#include #include #include #include @@ -21,15 +21,15 @@ namespace http headers.UserAgent().TryParseAdd(USER_AGENT); } - std::future request(const winrt::Windows::Foundation::Uri& url) + winrt::Windows::Foundation::IAsyncOperation request(const winrt::Windows::Foundation::Uri& url) { auto response = co_await m_client.GetAsync(url); (void)response.EnsureSuccessStatusCode(); auto body = co_await response.Content().ReadAsStringAsync(); - co_return std::wstring(body); + co_return body; } - std::future download(const winrt::Windows::Foundation::Uri& url, const std::wstring& dstFilePath) + winrt::Windows::Foundation::IAsyncAction download(const winrt::Windows::Foundation::Uri& url, const std::wstring& dstFilePath) { auto response = co_await m_client.GetAsync(url); (void)response.EnsureSuccessStatusCode(); @@ -38,7 +38,7 @@ namespace http file_stream.Close(); } - std::future download(const winrt::Windows::Foundation::Uri& url, const std::wstring& dstFilePath, const std::function& progressUpdateCallback) + winrt::Windows::Foundation::IAsyncAction download(const winrt::Windows::Foundation::Uri& url, const std::wstring& dstFilePath, const std::function& progressUpdateCallback) { auto response = co_await m_client.GetAsync(url, HttpCompletionOption::ResponseHeadersRead); response.EnsureSuccessStatusCode(); diff --git a/src/modules/ZoomIt/ZoomIt/Zoomit.cpp b/src/modules/ZoomIt/ZoomIt/Zoomit.cpp index 68731f1a98..48a80b7206 100644 --- a/src/modules/ZoomIt/ZoomIt/Zoomit.cpp +++ b/src/modules/ZoomIt/ZoomIt/Zoomit.cpp @@ -5140,7 +5140,7 @@ bool IsPenInverted( WPARAM wParam ) // Captures the specified screen using the capture APIs // //---------------------------------------------------------------------------- -std::future> CaptureScreenshotAsync(winrt::IDirect3DDevice const& device, winrt::GraphicsCaptureItem const& item, winrt::DirectXPixelFormat const& pixelFormat) +winrt::Windows::Foundation::IAsyncAction CaptureScreenshotAsync(winrt::IDirect3DDevice const& device, winrt::GraphicsCaptureItem const& item, winrt::DirectXPixelFormat const& pixelFormat, winrt::com_ptr& result) { auto d3dDevice = GetDXGIInterfaceFromObject(device); winrt::com_ptr d3dContext; @@ -5176,9 +5176,7 @@ std::future> CaptureScreenshotAsync(winrt::IDire framePool.Close(); auto texture = GetDXGIInterfaceFromObject(frame.Surface()); - auto result = util::CopyD3DTexture(d3dDevice, texture, true); - - co_return result; + result = util::CopyD3DTexture(d3dDevice, texture, true); } //---------------------------------------------------------------------------- @@ -5205,10 +5203,9 @@ winrt::com_ptrCaptureScreenshot(winrt::DirectXPixelFormat const auto item = util::CreateCaptureItemForMonitor(hMon); - auto capture = CaptureScreenshotAsync(device, item, pixelFormat); - capture.wait(); - - return capture.get(); + winrt::com_ptr result; + CaptureScreenshotAsync(device, item, pixelFormat, result).get(); + return result; } diff --git a/src/runner/UpdateUtils.cpp b/src/runner/UpdateUtils.cpp index 820b926984..7e4c007a3f 100644 --- a/src/runner/UpdateUtils.cpp +++ b/src/runner/UpdateUtils.cpp @@ -173,7 +173,7 @@ void ProcessNewVersionInfo(const github_version_info& version_info, // Cleanup old updates before downloading the latest updating::cleanup_updates(); - if (download_new_version(new_version_info).get()) + if (download_new_version(new_version_info)) { state.state = UpdateState::readyToInstall; state.downloadedInstallerFilename = new_version_info.installer_filename; @@ -232,7 +232,7 @@ void PeriodicUpdateWorker() bool version_info_obtained = false; try { - const auto new_version_info = get_github_version_info_async().get(); + const auto new_version_info = get_github_version_info_async(); if (new_version_info.has_value()) { version_info_obtained = true; @@ -272,7 +272,7 @@ void CheckForUpdatesCallback() auto state = UpdateState::read(); try { - auto new_version_info = get_github_version_info_async().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