-
Notifications
You must be signed in to change notification settings - Fork 321
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
New VSCode fallback behaviour for copyToClipboard #6598
Merged
Merged
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
e68fde7
change clipboard copy so that it fallsback to a postMessage to the pa…
CoderDake c565fc6
better Dart Doc
CoderDake a34fcef
release notes
CoderDake b59d134
lint
CoderDake 74771df
Make SemanticsNode.isMergedIntoParent Readonly
CaseyHillers 7344822
Simplify unnecessary cascade operator
CaseyHillers 84ce7d5
Merge remote-tracking branch 'upstream/master' into dake-clipboard
CoderDake 8bd5bf0
kenzie cleanup
CoderDake a360909
no unsafe plz
CoderDake ea26099
Kenzie Recomend
c06f41b
Merge remote-tracking branch 'upstream/b308325747' into dake-clipboard
CoderDake 7d1f090
Merge branch 'master' into dake-clipboard
CoderDake File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
7 changes: 7 additions & 0 deletions
7
...ools_app/lib/src/shared/config_specific/copy_to_clipboard/_copy_to_clipboard_desktop.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
// Copyright 2023 The Chromium Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style license that can be found | ||
// in the LICENSE file. | ||
|
||
void copyToClipboardVSCode(String _) { | ||
// Do nothing | ||
} |
19 changes: 19 additions & 0 deletions
19
...devtools_app/lib/src/shared/config_specific/copy_to_clipboard/_copy_to_clipboard_web.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
// Copyright 2023 The Chromium Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style license that can be found | ||
// in the LICENSE file. | ||
|
||
import 'dart:js_interop'; | ||
import 'package:web/web.dart'; | ||
|
||
void copyToClipboardVSCode(String data) { | ||
// This post message is only relevant in VSCode. If the parent frame is | ||
// listening for this command, then it will attempt to copy the contents | ||
// to the clipboard in the context of the parent frame. | ||
window.parent?.postMessage( | ||
{ | ||
'command': 'clipboard-write', | ||
'data': data, | ||
}.jsify(), | ||
'*'.toJS, | ||
); | ||
} |
52 changes: 52 additions & 0 deletions
52
...ages/devtools_app/lib/src/shared/config_specific/copy_to_clipboard/copy_to_clipboard.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
// Copyright 2023 The Chromium Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style license that can be found | ||
// in the LICENSE file. | ||
|
||
import 'package:devtools_app_shared/ui.dart'; | ||
import 'package:flutter/services.dart'; | ||
import 'package:logging/logging.dart'; | ||
|
||
import '../../globals.dart'; | ||
import '_copy_to_clipboard_desktop.dart' | ||
if (dart.library.js_interop) '_copy_to_clipboard_web.dart'; | ||
|
||
final _log = Logger('copy_to_clipboard'); | ||
|
||
/// Attempts to copy a String of `data` to the clipboard. | ||
/// | ||
/// Shows a `successMessage` [Notification] on the passed in `context`, if the | ||
/// copy is successfully done using the [Clipboard.setData] api. Otherwise it | ||
/// attempts to post the [data] to the parent frame where the parent frame will | ||
/// try to complete the copy (this fallback will only work in VSCode). | ||
Future<void> copyToClipboard( | ||
String data, | ||
String? successMessage, | ||
) async { | ||
try { | ||
await Clipboard.setData( | ||
ClipboardData( | ||
text: data, | ||
), | ||
); | ||
|
||
if (successMessage != null) notificationService.push(successMessage); | ||
} catch (e) { | ||
if (ideTheme.embed) { | ||
_log.warning( | ||
'DevTools copy failed. This may be as a result of a known bug in VSCode. ' | ||
'See https://github.com/Dart-Code/Dart-Code/issues/4540 for more ' | ||
'information. DevTools will now attempt to use a fallback method of ' | ||
'copying the contents.', | ||
); | ||
// Trying to use Clipboard.setData to copy in vscode will not work as a | ||
// result of a bug. So we should fallback to `copyToClipboardVSCode` which | ||
// delegates the copy to the frame above DevTools. | ||
// Sending this message in other environments will just have no effect. | ||
// See https://github.com/Dart-Code/Dart-Code/issues/4540 for more | ||
// information. | ||
copyToClipboardVSCode(data); | ||
} else { | ||
rethrow; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
You can probably use the existing
postMessage
in packages\devtools_app\lib\src\shared\config_specific\post_message\post_message_web.dart to avoid needing multiple stub files for this API? (eg. have a single copy function that just calls the shared postMessage)?Edit: Actually looks like the postMessage function there maybe isn't used... maybe it was only partly 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.
interesting, yeah it doesn't look like it exposed 🤔
Would you be alright with me just leaving the multi stub files for the copy behaviour?
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.
Seems reasonable to me (if that's what's tested and works). It seems to be what the "launch URL" functionality (that I just re-discovered) does. Maybe it's worth adding a TODO that we could possibly refactor these to reduce the number of stubs though (both copy + launch url)?
(I suspect I added some of that dead postMessage code, so I'm happy to look, and either consolidate or delete the unused bits)
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.
Issue created :)
#6613