@@ -146,20 +146,11 @@ class WebSocketProxyService implements VmServiceInterface {
146
146
vm_service.IsolateRef ? _isolateRef;
147
147
bool _isolateRunning = false ;
148
148
vm_service.Event ? _currentPauseEvent;
149
- bool _hasResumed = false ;
150
149
151
150
/// Creates a new isolate for WebSocket debugging.
152
151
Future <void > createIsolate ([AppConnection ? appConnectionOverride]) async {
153
- final appConn = appConnectionOverride ?? appConnection;
154
-
155
- // Update the app connection reference if a new one is provided
156
- if (appConnectionOverride != null ) {
157
- _logger.fine (
158
- 'Updating appConnection reference from '
159
- 'instanceId: ${appConnection .request .instanceId } to instanceId: ${appConnectionOverride .request .instanceId }' ,
160
- );
161
- appConnection = appConnectionOverride;
162
- }
152
+ // Update app connection if override provided
153
+ appConnection = appConnectionOverride ?? appConnection;
163
154
164
155
// Clean up existing isolate
165
156
if (_isIsolateRunning) {
@@ -169,7 +160,9 @@ class WebSocketProxyService implements VmServiceInterface {
169
160
170
161
// Auto-cleanup on connection close
171
162
await _appConnectionDoneSubscription? .cancel ();
172
- _appConnectionDoneSubscription = appConn.onDone.asStream ().listen ((_) {
163
+ _appConnectionDoneSubscription = appConnection.onDone.asStream ().listen ((
164
+ _,
165
+ ) {
173
166
destroyIsolate ();
174
167
});
175
168
@@ -184,7 +177,6 @@ class WebSocketProxyService implements VmServiceInterface {
184
177
185
178
_isolateRef = isolateRef;
186
179
_isolateRunning = true ;
187
- _hasResumed = false ;
188
180
_vm.isolates? .add (isolateRef);
189
181
final timestamp = DateTime .now ().millisecondsSinceEpoch;
190
182
@@ -206,23 +198,6 @@ class WebSocketProxyService implements VmServiceInterface {
206
198
),
207
199
);
208
200
209
- if (! _initializedCompleter.isCompleted) _initializedCompleter.complete ();
210
-
211
- // Set up app connection listener for resume handling
212
- safeUnawaited (
213
- appConn.onStart.then ((_) {
214
- if (pauseIsolatesOnStart && ! _hasResumed) {
215
- final resumeEvent = vm_service.Event (
216
- kind: vm_service.EventKind .kResume,
217
- timestamp: DateTime .now ().millisecondsSinceEpoch,
218
- isolate: isolateRef,
219
- );
220
- _hasResumed = true ;
221
- _streamNotify (vm_service.EventStreams .kDebug, resumeEvent);
222
- }
223
- }),
224
- );
225
-
226
201
// Send pause event if enabled
227
202
if (pauseIsolatesOnStart) {
228
203
final pauseEvent = vm_service.Event (
@@ -231,18 +206,11 @@ class WebSocketProxyService implements VmServiceInterface {
231
206
isolate: isolateRef,
232
207
);
233
208
_currentPauseEvent = pauseEvent;
234
- _hasResumed = false ;
235
209
_streamNotify (vm_service.EventStreams .kDebug, pauseEvent);
236
- } else {
237
- // Send immediate resume event
238
- final resumeEvent = vm_service.Event (
239
- kind: vm_service.EventKind .kResume,
240
- timestamp: timestamp,
241
- isolate: isolateRef,
242
- );
243
- _hasResumed = true ;
244
- _streamNotify (vm_service.EventStreams .kDebug, resumeEvent);
245
210
}
211
+
212
+ // Complete initialization after isolate is set up
213
+ if (! _initializedCompleter.isCompleted) _initializedCompleter.complete ();
246
214
}
247
215
248
216
/// Destroys the isolate and cleans up state.
@@ -273,7 +241,6 @@ class WebSocketProxyService implements VmServiceInterface {
273
241
_isolateRef = null ;
274
242
_isolateRunning = false ;
275
243
_currentPauseEvent = null ;
276
- _hasResumed = false ;
277
244
278
245
if (_initializedCompleter.isCompleted) {
279
246
_initializedCompleter = Completer <void >();
@@ -765,7 +732,6 @@ class WebSocketProxyService implements VmServiceInterface {
765
732
isolate: _isolateRef! ,
766
733
);
767
734
_currentPauseEvent = pauseEvent;
768
- _hasResumed = false ;
769
735
_streamNotify (vm_service.EventStreams .kDebug, pauseEvent);
770
736
}
771
737
}
@@ -809,6 +775,18 @@ class WebSocketProxyService implements VmServiceInterface {
809
775
} else {
810
776
appConnection.runMain ();
811
777
}
778
+
779
+ // Clear pause state and send resume event to notify debugging tools
780
+ if (_currentPauseEvent != null && _isolateRef != null ) {
781
+ _currentPauseEvent = null ;
782
+ final resumeEvent = vm_service.Event (
783
+ kind: vm_service.EventKind .kResume,
784
+ timestamp: DateTime .now ().millisecondsSinceEpoch,
785
+ isolate: _isolateRef! ,
786
+ );
787
+ _streamNotify (vm_service.EventStreams .kDebug, resumeEvent);
788
+ }
789
+
812
790
return Success ();
813
791
}
814
792
0 commit comments