-
Notifications
You must be signed in to change notification settings - Fork 6k
[UWP] Implement clipboard. #28064
[UWP] Implement clipboard. #28064
Conversation
68250c8 to
2423079
Compare
|
It looks like this pull request may not have tests. Please make sure to add tests before merging. If you need an exemption to this rule, contact Hixie on the #hackers channel in Chat. If you are not sure if you need tests, consider this rule of thumb: the purpose of a test is to make sure someone doesn't accidentally revert the fix. Ask yourself, is there anything in your PR that you feel it is important we not accidentally revert back to how it was before your fix? Reviewers: Read the Tree Hygiene page and make sure this patch meets those guidelines before LGTMing. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I attempted a review but I am not familiar with this component. Perhaps @cbracken @stuartmorgan
| // Waiting `DataPackageView::GetTextAsync()` using `TResult.get()` on the | ||
| // platform thread will causes the application stop, so we continue | ||
| // response on this callback. | ||
| content.GetTextAsync().Completed([result = std::move(result), key]( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not super familiar with these APIs, but, does this have an error handler as well that we may need to account for? Perhaps one that also gets invoked when the window is not in the foreground.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Before here I check window is in foreground, so I think this should throw no errors. I created an example and checked app doesn't crash from the engine. (I will post it on the comments.)
|
Reading clipboard every 1 sec to check no engine crash from background. import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
void main() {
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Clipboard Loop',
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: const MyHomePage(title: 'Clipboard Loop'),
);
}
}
class MyHomePage extends StatefulWidget {
const MyHomePage({Key? key, required this.title}) : super(key: key);
final String title;
@override
State<MyHomePage> createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
_MyHomePageState() {
startLoopingCheckClipboard().then((_) {});
}
Future<void> startLoopingCheckClipboard() async {
while (true) {
await Future.delayed(const Duration(seconds: 1));
try {
var text = (await Clipboard.getData("text/plain"))?.text;
if (text != null) {
_updateContentAndError(text, null);
} else {
_updateContentAndError(null, "clipboard is null");
}
} catch (e) {
_updateContentAndError(null, e.toString());
}
}
}
String? _content;
String? _error;
void _updateContentAndError(String? content, String? error) {
setState(() {
_content = content;
_error = error;
});
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text(widget.title),
),
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
const Text(
'Clipboard content',
),
Text(
_content ?? "",
style: Theme.of(context).textTheme.headline4,
),
Text(
_error ?? "",
style: Theme.of(context)
.textTheme
.headline4
?.copyWith(color: Theme.of(context).errorColor),
),
],
),
),
);
}
} |
| result->Success(rapidjson::Document()); | ||
| } | ||
| } else { | ||
| result->Success(rapidjson::Document()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
With the example, I found that Clipboard.getData() throws PlatformException when app is not focused, in web, but here Clipboard.getData() send success. I will fix it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
|
cc @clarkezone. I am not sure about these APIs but they the implementation looks good to me modulo the error callback. |
|
I'm blocked currently due to inability to build the UWP target on my machine. |
| } | ||
| } else { | ||
| result->Error(kClipboardError, | ||
| "Unable to read clipboard. The window is not focused."); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This conditional block is pretty huge; consider inverting the condition and writing this as a bailout-style check where if the window isn't in the foreground, you set the error and return. Similar comment for the inner case where the clipboard contains no text; that would also put the comment closer to the result->Success(empty document) handling of that case.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM other than the style nit above.
|
This pull request is not suitable for automatic merging in its current state.
|
dbce0be to
4ac26a2
Compare
|
The |
This PR implements clipboard in platform handler in UWP.
This PR will able to merge after:
hasStringimplementation for UWP.This PR implements clipboard in platform handler in UWP.
I tested it by these steps:
TextFieldin flutter uwp app.Pastebehavior in the context menu.PastebehaviorFixes one item in flutter/flutter#70214.
No changes in
flutter/tests.Pre-launch Checklist
writing and running engine tests.
///).