Always call launchUrlVSCode, error or not (#6780)
This should prevent a repeat of https://github.com/flutter/devtools/issues/6105 if an exception occurs while trying to open the page when embedded inside VS Code.
diff --git a/packages/devtools_app/lib/src/shared/config_specific/launch_url/launch_url.dart b/packages/devtools_app/lib/src/shared/config_specific/launch_url/launch_url.dart
index abe8121..cf3b5de 100644
--- a/packages/devtools_app/lib/src/shared/config_specific/launch_url/launch_url.dart
+++ b/packages/devtools_app/lib/src/shared/config_specific/launch_url/launch_url.dart
@@ -12,14 +12,20 @@
Future<void> launchUrl(String url) async {
final parsedUrl = Uri.tryParse(url);
- if (parsedUrl != null && await url_launcher.canLaunchUrl(parsedUrl)) {
- await url_launcher.launchUrl(parsedUrl);
- } else {
- notificationService.push('Unable to open $url.');
+ try {
+ if (parsedUrl != null && await url_launcher.canLaunchUrl(parsedUrl)) {
+ await url_launcher.launchUrl(parsedUrl);
+ } else {
+ notificationService.push('Unable to open $url.');
+ }
+ } finally {
+ // Always pass the request up to VS Code because we could fail both silently
+ // (the usual behaviour) or with another error like
+ // "Attempted to call Window.open with a null window"
+ // https://github.com/flutter/devtools/issues/6105.
+ //
+ // In the case where we are not in VS Code, there will be nobody listening
+ // to the postMessage this sends.
+ launchUrlVSCode(url);
}
-
- // When embedded in VSCode, url_launcher will silently fail, so we send a
- // command to DartCode to launch the URL. This will do nothing when not
- // embedded in VSCode.
- launchUrlVSCode(url);
}