@@ -31,9 +31,10 @@ import 'package:dwds/src/servers/devtools.dart';
31
31
import 'package:dwds/src/servers/extension_backend.dart' ;
32
32
import 'package:dwds/src/servers/extension_debugger.dart' ;
33
33
import 'package:dwds/src/services/app_debug_services.dart' ;
34
+ import 'package:dwds/src/services/chrome_proxy_service.dart' ;
34
35
import 'package:dwds/src/services/debug_service.dart' ;
35
36
import 'package:dwds/src/services/expression_compiler.dart' ;
36
- import 'package:dwds/src/services/web_socket_app_debug_services .dart' ;
37
+ import 'package:dwds/src/services/web_socket_proxy_service .dart' ;
37
38
import 'package:dwds/src/utilities/shared.dart' ;
38
39
import 'package:dwds/src/web_socket_dwds_vm_client.dart' ;
39
40
import 'package:logging/logging.dart' ;
@@ -315,18 +316,19 @@ class DevHandler {
315
316
IAppDebugServices appServices,
316
317
AppConnection appConnection,
317
318
) {
318
- safeUnawaited (
319
- appServices.chromeProxyService.remoteDebugger.onClose.first.whenComplete (
320
- () async {
319
+ final chromeProxy = appServices.proxyService;
320
+ if (chromeProxy is ChromeProxyService ) {
321
+ safeUnawaited (
322
+ chromeProxy.remoteDebugger.onClose.first.whenComplete (() async {
321
323
await appServices.close ();
322
324
_servicesByAppId.remove (appConnection.request.appId);
323
325
_logger.info (
324
326
'Stopped debug service on '
325
327
'ws://${appServices .debugService .hostname }:${appServices .debugService .port }\n ' ,
326
328
);
327
- },
328
- ),
329
- );
329
+ }) ,
330
+ );
331
+ }
330
332
}
331
333
332
334
void _handleConnection (SocketConnection injectedConnection) {
@@ -420,7 +422,9 @@ class DevHandler {
420
422
if (message == null ) return ;
421
423
422
424
final appId = connection.request.appId;
423
- final wsService = _servicesByAppId[appId]? .webSocketProxyService;
425
+ final proxyService = _servicesByAppId[appId]? .proxyService;
426
+ final wsService =
427
+ proxyService is WebSocketProxyService ? proxyService : null ;
424
428
425
429
if (wsService == null ) {
426
430
_logger.warning (
@@ -452,22 +456,21 @@ class DevHandler {
452
456
) async {
453
457
if (message == null ) return ;
454
458
455
- if (message is HotReloadResponse ) {
456
- _servicesByAppId[connection.request.appId]? .chromeProxyService
457
- .completeHotReload (message);
458
- } else if (message is IsolateExit ) {
459
+ final appId = connection.request.appId;
460
+ final proxyService = _servicesByAppId[appId]? .proxyService;
461
+ final chromeService =
462
+ proxyService is ChromeProxyService ? proxyService : null ;
463
+
464
+ if (message is IsolateExit ) {
459
465
_handleIsolateExit (connection);
460
466
} else if (message is IsolateStart ) {
461
467
await _handleIsolateStart (connection);
462
468
} else if (message is BatchedDebugEvents ) {
463
- _servicesByAppId[connection.request.appId]? .chromeProxyService
464
- .parseBatchedDebugEvents (message);
469
+ chromeService? .parseBatchedDebugEvents (message);
465
470
} else if (message is DebugEvent ) {
466
- _servicesByAppId[connection.request.appId]? .chromeProxyService
467
- .parseDebugEvent (message);
471
+ chromeService? .parseDebugEvent (message);
468
472
} else if (message is RegisterEvent ) {
469
- _servicesByAppId[connection.request.appId]? .chromeProxyService
470
- .parseRegisterEvent (message);
473
+ chromeService? .parseRegisterEvent (message);
471
474
} else {
472
475
throw UnsupportedError (
473
476
'Message type ${message .runtimeType } is not supported in Chrome mode' ,
@@ -571,13 +574,16 @@ class DevHandler {
571
574
debuggerStart: debuggerStart,
572
575
devToolsStart: DateTime .now (),
573
576
);
574
- await _launchDevTools (
575
- appServices.chromeProxyService.remoteDebugger,
576
- _constructDevToolsUri (
577
- appServices.debugService.uri,
578
- ideQueryParam: 'Dwds' ,
579
- ),
580
- );
577
+ final chromeProxy = appServices.proxyService;
578
+ if (chromeProxy is ChromeProxyService ) {
579
+ await _launchDevTools (
580
+ chromeProxy.remoteDebugger,
581
+ _constructDevToolsUri (
582
+ appServices.debugService.uri,
583
+ ideQueryParam: 'Dwds' ,
584
+ ),
585
+ );
586
+ }
581
587
}
582
588
583
589
/// Creates a debug connection for WebSocket mode.
@@ -587,9 +593,9 @@ class DevHandler {
587
593
final appDebugServices = await loadAppServices (appConnection);
588
594
589
595
// Initialize WebSocket proxy service
590
- final webSocketProxyService = appDebugServices.webSocketProxyService ;
591
- if (webSocketProxyService != null ) {
592
- await webSocketProxyService .isInitialized;
596
+ final proxyService = appDebugServices.proxyService ;
597
+ if (proxyService is WebSocketProxyService ) {
598
+ await proxyService .isInitialized;
593
599
_logger.fine ('WebSocket proxy service initialized successfully' );
594
600
} else {
595
601
_logger.warning ('WebSocket proxy service is null' );
@@ -606,9 +612,9 @@ class DevHandler {
606
612
607
613
// Initialize Chrome proxy service
608
614
try {
609
- final chromeProxyService = appDebugServices.chromeProxyService ;
610
- if (chromeProxyService != null ) {
611
- await chromeProxyService .isInitialized;
615
+ final proxyService = appDebugServices.proxyService ;
616
+ if (proxyService is ChromeProxyService ) {
617
+ await proxyService .isInitialized;
612
618
_logger.fine ('Chrome proxy service initialized successfully' );
613
619
} else {
614
620
_logger.warning ('Chrome proxy service is null' );
@@ -653,24 +659,30 @@ class DevHandler {
653
659
// Disconnect any old connection (eg. those in the keep-alive waiting
654
660
// state when reloading the page).
655
661
existingConnection? .shutDown ();
656
- services.chromeProxyService.destroyIsolate ();
662
+ final chromeProxy = services.proxyService;
663
+ if (chromeProxy is ChromeProxyService ) {
664
+ chromeProxy.destroyIsolate ();
665
+ }
657
666
658
667
// Reconnect to existing service.
659
668
services.connectedInstanceId = message.instanceId;
660
669
661
- if (services.chromeProxyService.pauseIsolatesOnStart) {
662
- // If the pause-isolates-on-start flag is set, we need to wait for
663
- // the resume event to run the app's main() method.
664
- _waitForResumeEventToRunMain (
665
- services.chromeProxyService.resumeAfterRestartEventsStream,
666
- readyToRunMainCompleter,
667
- );
668
- } else {
669
- // Otherwise, we can run the app's main() method immediately.
670
- readyToRunMainCompleter.complete ();
671
- }
670
+ final chromeService = services.proxyService;
671
+ if (chromeService is ChromeProxyService ) {
672
+ if (chromeService.pauseIsolatesOnStart) {
673
+ // If the pause-isolates-on-start flag is set, we need to wait for
674
+ // the resume event to run the app's main() method.
675
+ _waitForResumeEventToRunMain (
676
+ chromeService.resumeAfterRestartEventsStream,
677
+ readyToRunMainCompleter,
678
+ );
679
+ } else {
680
+ // Otherwise, we can run the app's main() method immediately.
681
+ readyToRunMainCompleter.complete ();
682
+ }
672
683
673
- await services.chromeProxyService.createIsolate (connection);
684
+ await chromeService.createIsolate (connection);
685
+ }
674
686
} else {
675
687
// If this is the initial app connection, we can run the app's main()
676
688
// method immediately.
@@ -762,11 +774,16 @@ class DevHandler {
762
774
763
775
_logger.finest ('WebSocket service reconnected for app: ${message .appId }' );
764
776
765
- _setupMainExecution (
766
- services.webSocketProxyService? .pauseIsolatesOnStart == true ,
767
- services.webSocketProxyService? .resumeAfterRestartEventsStream,
768
- readyToRunMainCompleter,
769
- );
777
+ final wsService = services.proxyService;
778
+ if (wsService is WebSocketProxyService ) {
779
+ _setupMainExecution (
780
+ wsService.pauseIsolatesOnStart,
781
+ wsService.resumeAfterRestartEventsStream,
782
+ readyToRunMainCompleter,
783
+ );
784
+ } else {
785
+ readyToRunMainCompleter.complete ();
786
+ }
770
787
771
788
await _handleIsolateStart (newConnection);
772
789
}
@@ -809,7 +826,10 @@ class DevHandler {
809
826
'Isolate exit handled by WebSocket proxy service for app: $appId ' ,
810
827
);
811
828
} else {
812
- _servicesByAppId[appId]? .chromeProxyService.destroyIsolate ();
829
+ final proxyService = _servicesByAppId[appId]? .proxyService;
830
+ if (proxyService is ChromeProxyService ) {
831
+ proxyService.destroyIsolate ();
832
+ }
813
833
}
814
834
}
815
835
@@ -818,13 +838,15 @@ class DevHandler {
818
838
final appId = appConnection.request.appId;
819
839
820
840
if (useWebSocketConnection) {
821
- await _servicesByAppId[appId]? .webSocketProxyService? .createIsolate (
822
- appConnection,
823
- );
841
+ final proxyService = _servicesByAppId[appId]? .proxyService;
842
+ if (proxyService is WebSocketProxyService ) {
843
+ await proxyService.createIsolate (appConnection);
844
+ }
824
845
} else {
825
- await _servicesByAppId[appId]? .chromeProxyService.createIsolate (
826
- appConnection,
827
- );
846
+ final proxyService = _servicesByAppId[appId]? .proxyService;
847
+ if (proxyService is ChromeProxyService ) {
848
+ await proxyService.createIsolate (appConnection);
849
+ }
828
850
}
829
851
}
830
852
@@ -871,15 +893,18 @@ class DevHandler {
871
893
);
872
894
final encodedUri = await debugService.encodedUri;
873
895
_logger.info ('Debug service listening on $encodedUri \n ' );
874
- await appDebugService.chromeProxyService.remoteDebugger.sendCommand (
875
- 'Runtime.evaluate' ,
876
- params: {
877
- 'expression' :
878
- 'console.log('
879
- '"This app is linked to the debug service: $encodedUri "'
880
- ');' ,
881
- },
882
- );
896
+ final chromeProxy = appDebugService.proxyService;
897
+ if (chromeProxy is ChromeProxyService ) {
898
+ await chromeProxy.remoteDebugger.sendCommand (
899
+ 'Runtime.evaluate' ,
900
+ params: {
901
+ 'expression' :
902
+ 'console.log('
903
+ '"This app is linked to the debug service: $encodedUri "'
904
+ ');' ,
905
+ },
906
+ );
907
+ }
883
908
884
909
// Notify that DWDS has been launched and a debug connection has been made:
885
910
_maybeEmitDwdsLaunchEvent ();
@@ -989,18 +1014,20 @@ class DevHandler {
989
1014
extensionDebugger.sendEvent ('dwds.debugUri' , debugService.uri);
990
1015
final encodedUri = await debugService.encodedUri;
991
1016
extensionDebugger.sendEvent ('dwds.encodedUri' , encodedUri);
992
- safeUnawaited (
993
- appServices.chromeProxyService.remoteDebugger.onClose.first
994
- .whenComplete (() async {
995
- appServices? .chromeProxyService.destroyIsolate ();
996
- await appServices? .close ();
997
- _servicesByAppId.remove (devToolsRequest.appId);
998
- _logger.info (
999
- 'Stopped debug service on '
1000
- '${await appServices ?.debugService .encodedUri }\n ' ,
1001
- );
1002
- }),
1003
- );
1017
+ final chromeProxy = appServices.proxyService;
1018
+ if (chromeProxy is ChromeProxyService ) {
1019
+ safeUnawaited (
1020
+ chromeProxy.remoteDebugger.onClose.first.whenComplete (() async {
1021
+ chromeProxy.destroyIsolate ();
1022
+ await appServices? .close ();
1023
+ _servicesByAppId.remove (devToolsRequest.appId);
1024
+ _logger.info (
1025
+ 'Stopped debug service on '
1026
+ '${await appServices ?.debugService .encodedUri }\n ' ,
1027
+ );
1028
+ }),
1029
+ );
1030
+ }
1004
1031
extensionDebugConnections.add (DebugConnection (appServices));
1005
1032
_servicesByAppId[appId] = appServices;
1006
1033
}
0 commit comments