@@ -104,11 +104,11 @@ void main() {
104
104
105
105
// When a Dart application tab is closed, detach the corresponding debug
106
106
// session:
107
- tabsOnRemovedAddListener (allowInterop (_maybeDetachDebugSessionForTab ));
107
+ tabsOnRemovedAddListener (allowInterop (_removeAndDetachDebugSessionForTab ));
108
108
109
109
// When a debug session is detached, remove the reference to it:
110
110
onDetachAddListener (allowInterop ((Debuggee source, DetachReason reason) {
111
- _maybeRemoveDebugSessionForTab (source.tabId);
111
+ _removeDebugSessionForTab (source.tabId);
112
112
}));
113
113
114
114
// Save the tab ID for the opened DevTools.
@@ -277,14 +277,38 @@ void _maybeAttachDebugSession(
277
277
}
278
278
}
279
279
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);
282
284
283
285
if (removedTabId != - 1 ) {
284
286
detach (Debuggee (tabId: removedTabId), allowInterop (() {}));
285
287
}
286
288
}
287
289
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
+
288
312
void _maybeSaveDevToolsTabId (Tab tab) async {
289
313
// Remembers the ID of the DevTools tab.
290
314
//
@@ -338,28 +362,6 @@ void _forwardMessageToExternalExtensions(
338
362
}
339
363
}
340
364
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
-
363
365
void _notifyPanelScriptOfChanges (List <DevToolsPanel > panels) {
364
366
for (final panel in panels) {
365
367
sendSimpleMessage (panel.panelId,
@@ -500,12 +502,12 @@ Future<void> _startSseClient(
500
502
}
501
503
}, onDone: () {
502
504
_tabIdToEncodedUri.remove (currentTab.id);
503
- client. close ( );
505
+ _removeAndDetachDebugSessionForTab (currentTab.id, null );
504
506
return ;
505
507
}, onError: (_) {
506
508
_tabIdToEncodedUri.remove (currentTab.id);
507
509
alert ('Lost app connection.' );
508
- client. close ( );
510
+ _removeAndDetachDebugSessionForTab (currentTab.id, null );
509
511
}, cancelOnError: true );
510
512
511
513
client.sink.add (jsonEncode (serializers.serialize (DevToolsRequest ((b) => b
0 commit comments