diff options
author | Andy Shaw <andy.shaw@qt.io> | 2020-03-10 10:27:50 +0100 |
---|---|---|
committer | Andy Shaw <andy.shaw@qt.io> | 2020-03-14 11:41:02 +0100 |
commit | f45d2dc54397fabca25de51fd0c9ec37014e46c8 (patch) | |
tree | 5f257d153010d6c8d09fe4c743d7f1151ad7646f /src/plugins/platforms/winrt | |
parent | 1d403ef81a2b9b19383f45b27d53149e122d65d8 (diff) |
WinRT: Open the URLs via the XAML thread to enable them to be opened
UWP expects these functions to be opened via the XAML thread, so we
ensure this is done by running those functions on that thread.
Change-Id: I57ae3a7d9b45d0b1a00ac23b103386bd34b65c6d
Reviewed-by: Oliver Wolff <oliver.wolff@qt.io>
Diffstat (limited to 'src/plugins/platforms/winrt')
-rw-r--r-- | src/plugins/platforms/winrt/qwinrtservices.cpp | 33 |
1 files changed, 21 insertions, 12 deletions
diff --git a/src/plugins/platforms/winrt/qwinrtservices.cpp b/src/plugins/platforms/winrt/qwinrtservices.cpp index b27c408f40..04d7417801 100644 --- a/src/plugins/platforms/winrt/qwinrtservices.cpp +++ b/src/plugins/platforms/winrt/qwinrtservices.cpp @@ -43,6 +43,7 @@ #include <QtCore/QDir> #include <QtCore/QCoreApplication> #include <QtCore/qfunctions_winrt.h> +#include <private/qeventdispatcher_winrt_p.h> #include <wrl.h> #include <windows.foundation.h> @@ -94,13 +95,17 @@ bool QWinRTServices::openUrl(const QUrl &url) HRESULT hr = d->uriFactory->CreateUri(uriString.Get(), &uri); RETURN_FALSE_IF_FAILED("Failed to create URI from QUrl."); - ComPtr<IAsyncOperation<bool>> op; - hr = d->launcher->LaunchUriAsync(uri.Get(), &op); - RETURN_FALSE_IF_FAILED("Failed to start URI launch."); - boolean result; - hr = QWinRTFunctions::await(op, &result); - RETURN_FALSE_IF_FAILED("Failed to launch URI."); + hr = QEventDispatcherWinRT::runOnXamlThread([this, d, uri, &result]() { + ComPtr<IAsyncOperation<bool>> op; + HRESULT hr = d->launcher->LaunchUriAsync(uri.Get(), &op); + RETURN_HR_IF_FAILED("Failed to start URI launch."); + + hr = QWinRTFunctions::await(op, &result); + RETURN_HR_IF_FAILED("Failed to launch URI."); + return hr; + }); + RETURN_FALSE_IF_FAILED("Failed to launch URI from Xaml thread."); return result; } @@ -131,12 +136,16 @@ bool QWinRTServices::openDocument(const QUrl &url) boolean result; { - ComPtr<IAsyncOperation<bool>> op; - hr = d->launcher->LaunchFileAsync(file.Get(), &op); - RETURN_FALSE_IF_FAILED("Failed to start file launch."); - - hr = QWinRTFunctions::await(op, &result); - RETURN_FALSE_IF_FAILED("Failed to launch file."); + hr = QEventDispatcherWinRT::runOnXamlThread([this, d, file, &result]() { + ComPtr<IAsyncOperation<bool>> op; + HRESULT hr = d->launcher->LaunchFileAsync(file.Get(), &op); + RETURN_HR_IF_FAILED("Failed to start file launch."); + + hr = QWinRTFunctions::await(op, &result); + RETURN_HR_IF_FAILED("Failed to launch file."); + return hr; + }); + RETURN_FALSE_IF_FAILED("Failed to launch file from Xaml thread."); } return result; |