@@ -104,11 +104,11 @@ void main() {
104104
105105 // When a Dart application tab is closed, detach the corresponding debug
106106 // session:
107- tabsOnRemovedAddListener (allowInterop (_maybeDetachDebugSessionForTab ));
107+ tabsOnRemovedAddListener (allowInterop (_removeAndDetachDebugSessionForTab ));
108108
109109 // When a debug session is detached, remove the reference to it:
110110 onDetachAddListener (allowInterop ((Debuggee source, DetachReason reason) {
111- _maybeRemoveDebugSessionForTab (source.tabId);
111+ _removeDebugSessionForTab (source.tabId);
112112 }));
113113
114114 // Save the tab ID for the opened DevTools.
@@ -277,14 +277,38 @@ void _maybeAttachDebugSession(
277277 }
278278}
279279
280- void _maybeDetachDebugSessionForTab (int tabId, _) {
281- final removedTabId = _maybeRemoveDebugSessionForTab (tabId);
280+ // Tries to remove the debug session for the specified tab, and detach the
281+ // debugger associated with that debug session.
282+ void _removeAndDetachDebugSessionForTab (int tabId, _) {
283+ final removedTabId = _removeDebugSessionForTab (tabId);
282284
283285 if (removedTabId != - 1 ) {
284286 detach (Debuggee (tabId: removedTabId), allowInterop (() {}));
285287 }
286288}
287289
290+ // Tries to remove the debug session for the specified tab. If no session is
291+ // found, returns -1. Otherwise returns the tab ID.
292+ int _removeDebugSessionForTab (int tabId) {
293+ var session = _debugSessions.firstWhere (
294+ (session) => session.appTabId == tabId || session.devtoolsTabId == tabId,
295+ orElse: () => null );
296+ if (session != null ) {
297+ session.socketClient.close ();
298+ _debugSessions.remove (session);
299+
300+ // Notify the Dart DevTools panel that the session has been detached by
301+ // setting the URI to an empty string:
302+ _updateOrCreateDevToolsPanel (session.appId, (panel) {
303+ panel.devToolsUri = '' ;
304+ });
305+
306+ return session.appTabId;
307+ } else {
308+ return - 1 ;
309+ }
310+ }
311+
288312void _maybeSaveDevToolsTabId (Tab tab) async {
289313 // Remembers the ID of the DevTools tab.
290314 //
@@ -338,28 +362,6 @@ void _forwardMessageToExternalExtensions(
338362 }
339363}
340364
341- // Tries to remove the debug session for the specified tab. If no session is
342- // found, returns -1. Otherwise returns the tab ID.
343- int _maybeRemoveDebugSessionForTab (int tabId) {
344- var session = _debugSessions.firstWhere (
345- (session) => session.appTabId == tabId || session.devtoolsTabId == tabId,
346- orElse: () => null );
347- if (session != null ) {
348- session.socketClient.close ();
349- _debugSessions.remove (session);
350-
351- // Notify the Dart DevTools panel that the session has been detached by
352- // setting the URI to an empty string:
353- _updateOrCreateDevToolsPanel (session.appId, (panel) {
354- panel.devToolsUri = '' ;
355- });
356-
357- return session.appTabId;
358- } else {
359- return - 1 ;
360- }
361- }
362-
363365void _notifyPanelScriptOfChanges (List <DevToolsPanel > panels) {
364366 for (final panel in panels) {
365367 sendSimpleMessage (panel.panelId,
@@ -500,12 +502,12 @@ Future<void> _startSseClient(
500502 }
501503 }, onDone: () {
502504 _tabIdToEncodedUri.remove (currentTab.id);
503- client. close ( );
505+ _removeAndDetachDebugSessionForTab (currentTab.id, null );
504506 return ;
505507 }, onError: (_) {
506508 _tabIdToEncodedUri.remove (currentTab.id);
507509 alert ('Lost app connection.' );
508- client. close ( );
510+ _removeAndDetachDebugSessionForTab (currentTab.id, null );
509511 }, cancelOnError: true );
510512
511513 client.sink.add (jsonEncode (serializers.serialize (DevToolsRequest ((b) => b
0 commit comments