From a73c4dfc31d5fbd9b7fe9836f677bebd8a8f7354 Mon Sep 17 00:00:00 2001 From: Kenzie Schmoll Date: Thu, 9 Nov 2023 11:15:00 -0800 Subject: [PATCH] Fix a bug where we were unnecessarily calling `manualDisconnect` --- packages/devtools_app/lib/src/app.dart | 2 +- packages/devtools_app/lib/src/framework/framework_core.dart | 6 +++--- packages/devtools_app/lib/src/shared/routing.dart | 4 +++- 3 files changed, 7 insertions(+), 5 deletions(-) diff --git a/packages/devtools_app/lib/src/app.dart b/packages/devtools_app/lib/src/app.dart index 7d4f1d5867f..5885725cb51 100644 --- a/packages/devtools_app/lib/src/app.dart +++ b/packages/devtools_app/lib/src/app.dart @@ -204,7 +204,7 @@ class DevToolsAppState extends State with AutoDisposeMixin { Map args, DevToolsNavigationState? state, ) { - if (FrameworkCore.initializationInProgress) { + if (FrameworkCore.vmServiceConnectionInProgress) { return const MaterialPage(child: CenteredCircularProgressIndicator()); } diff --git a/packages/devtools_app/lib/src/framework/framework_core.dart b/packages/devtools_app/lib/src/framework/framework_core.dart index 6a2644806bc..c855d07ce48 100644 --- a/packages/devtools_app/lib/src/framework/framework_core.dart +++ b/packages/devtools_app/lib/src/framework/framework_core.dart @@ -52,7 +52,7 @@ class FrameworkCore { _log.info('DevTools version ${devtools.version}.'); } - static bool initializationInProgress = false; + static bool vmServiceConnectionInProgress = false; /// Returns true if we're able to connect to a device and false otherwise. static Future initVmService( @@ -70,7 +70,7 @@ class FrameworkCore { final normalizedUri = normalizeVmServiceUri(serviceUriAsString); final Uri? uri = normalizedUri ?? getServiceUriFromQueryString(url); if (uri != null) { - initializationInProgress = true; + vmServiceConnectionInProgress = true; final finishedCompleter = Completer(); try { @@ -111,7 +111,7 @@ class FrameworkCore { errorReporter!('Unable to connect to VM service at $uri: $e', e); return false; } finally { - initializationInProgress = false; + vmServiceConnectionInProgress = false; } } else { // Don't report an error here because we do not have a URI to connect to. diff --git a/packages/devtools_app/lib/src/shared/routing.dart b/packages/devtools_app/lib/src/shared/routing.dart index 25c494f4d36..3306ba48c68 100644 --- a/packages/devtools_app/lib/src/shared/routing.dart +++ b/packages/devtools_app/lib/src/shared/routing.dart @@ -60,7 +60,9 @@ class DevToolsRouteInformationParser // If the uri has been modified and we do not have a vm service uri as a // query parameter, ensure we manually disconnect from any previously // connected applications. - await serviceConnection.serviceManager.manuallyDisconnect(); + if (serviceConnection.serviceManager.hasConnection) { + await serviceConnection.serviceManager.manuallyDisconnect(); + } } else if (_forceVmServiceUri == null) { // Otherwise, connect to the vm service from the query parameter before // loading the route (but do not do this in a testing environment).