Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit 4ac26a2

Browse files
moko256cbracken
authored andcommitted
use fast-return if condition and make conditions closer to comments
1 parent 26ca58d commit 4ac26a2

File tree

1 file changed

+22
-20
lines changed

1 file changed

+22
-20
lines changed

shell/platform/windows/platform_handler_winuwp.cc

Lines changed: 22 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -41,19 +41,28 @@ void PlatformHandlerWinUwp::GetPlainText(
4141
std::string_view key) {
4242
// We call `Clipboard::GetContent()` when the application window is in
4343
// focus, otherwise calling this will throw an error.
44-
if (isWindowInForeground()) {
45-
auto content =
46-
winrt::Windows::ApplicationModel::DataTransfer::Clipboard::GetContent();
47-
// Calling `DataPackageView::GetTextAsync()` when the clipboard has no text
48-
// content will throw an error.
49-
if (content.Contains(winrt::Windows::ApplicationModel::DataTransfer::
50-
StandardDataFormats::Text())) {
51-
// Waiting `DataPackageView::GetTextAsync()` using `TResult.get()` on the
52-
// platform thread will causes the application stop, so we continue
53-
// response on this callback.
54-
content.GetTextAsync().Completed([result = std::move(result), key](
55-
auto async_info,
56-
auto _async_status) {
44+
if (!isWindowInForeground()) {
45+
result->Error(kClipboardError,
46+
"Unable to read clipboard. The window is not focused.");
47+
return;
48+
}
49+
50+
auto content =
51+
winrt::Windows::ApplicationModel::DataTransfer::Clipboard::GetContent();
52+
53+
// Calling `DataPackageView::GetTextAsync()` when the clipboard has no text
54+
// content will throw an error.
55+
if (!content.Contains(winrt::Windows::ApplicationModel::DataTransfer::
56+
StandardDataFormats::Text())) {
57+
result->Success(rapidjson::Document());
58+
return;
59+
}
60+
61+
// Waiting `DataPackageView::GetTextAsync()` using `TResult.get()` on the
62+
// platform thread will causes the application stop, so we continue
63+
// response on this callback.
64+
content.GetTextAsync().Completed(
65+
[result = std::move(result), key](auto async_info, auto _async_status) {
5766
auto clipboard_string = async_info.GetResults();
5867

5968
rapidjson::Document document;
@@ -65,13 +74,6 @@ void PlatformHandlerWinUwp::GetPlainText(
6574
allocator);
6675
result->Success(document);
6776
});
68-
} else {
69-
result->Success(rapidjson::Document());
70-
}
71-
} else {
72-
result->Error(kClipboardError,
73-
"Unable to read clipboard. The window is not focused.");
74-
}
7577
}
7678

7779
void PlatformHandlerWinUwp::GetHasStrings(

0 commit comments

Comments
 (0)