From 3cda662a0297f89651c6373e9047bd06081c6d7e Mon Sep 17 00:00:00 2001 From: Danny Tuppeny Date: Mon, 20 Nov 2023 18:10:52 +0000 Subject: [PATCH] Always call launchUrlVSCode, error or not 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. --- .../launch_url/launch_url.dart | 24 ++++++++++++------- 1 file changed, 15 insertions(+), 9 deletions(-) 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 5e871d0050d..8bf41953ddd 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 @@ -11,14 +11,20 @@ import '_launch_url_desktop.dart' Future 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); }