@@ -6,6 +6,8 @@ import 'dart:async';
6
6
import 'dart:convert' ;
7
7
import 'dart:io' ;
8
8
9
+ import 'package:collection/collection.dart' ;
10
+ import 'package:dds/dds_launcher.dart' ;
9
11
import 'package:dwds/data/build_result.dart' ;
10
12
import 'package:dwds/data/connect_request.dart' ;
11
13
import 'package:dwds/data/debug_event.dart' ;
@@ -70,8 +72,7 @@ class DevHandler {
70
72
final UrlEncoder ? _urlEncoder;
71
73
final bool _useSseForDebugProxy;
72
74
final bool _useSseForInjectedClient;
73
- final bool _spawnDds;
74
- final int ? _ddsPort;
75
+ final DartDevelopmentServiceConfiguration _ddsConfig;
75
76
final bool _launchDevToolsInNewWindow;
76
77
final ExpressionCompiler ? _expressionCompiler;
77
78
final DwdsInjector _injected;
@@ -97,8 +98,8 @@ class DevHandler {
97
98
this ._useSseForInjectedClient,
98
99
this ._expressionCompiler,
99
100
this ._injected,
100
- this ._spawnDds,
101
- this ._ddsPort ,
101
+
102
+ this ._ddsConfig ,
102
103
this ._launchDevToolsInNewWindow, {
103
104
this .useWebSocketConnection = false ,
104
105
}) {
@@ -251,8 +252,7 @@ class DevHandler {
251
252
// This will provide a websocket based service.
252
253
useSse: false ,
253
254
expressionCompiler: _expressionCompiler,
254
- spawnDds: _spawnDds,
255
- ddsPort: _ddsPort,
255
+ ddsConfig: _ddsConfig,
256
256
);
257
257
}
258
258
@@ -451,7 +451,7 @@ class DevHandler {
451
451
AppConnection appConnection,
452
452
SocketConnection sseConnection,
453
453
) async {
454
- if (_devTools == null ) {
454
+ if (_devTools == null && ! _ddsConfig.serveDevTools ) {
455
455
sseConnection.sink.add (
456
456
jsonEncode (
457
457
serializers.serialize (
@@ -548,6 +548,7 @@ class DevHandler {
548
548
await _launchDevTools (
549
549
chromeProxy.remoteDebugger,
550
550
_constructDevToolsUri (
551
+ appServices,
551
552
appServices.debugService.uri,
552
553
ideQueryParam: 'Dwds' ,
553
554
),
@@ -853,21 +854,21 @@ class DevHandler {
853
854
ChromeDebugService debugService,
854
855
) async {
855
856
final dwdsStats = DwdsStats ();
856
- Uri ? ddsUri;
857
- if (_spawnDds) {
858
- final dds = await debugService.startDartDevelopmentService ();
859
- ddsUri = dds.wsUri;
857
+ DartDevelopmentServiceLauncher ? dds;
858
+ if (_ddsConfig.enable) {
859
+ dds = await debugService.startDartDevelopmentService ();
860
860
}
861
861
final vmClient = await ChromeDwdsVmClient .create (
862
862
debugService,
863
863
dwdsStats,
864
- ddsUri ,
864
+ dds ? .wsUri ,
865
865
);
866
866
final appDebugService = ChromeAppDebugServices (
867
867
debugService,
868
868
vmClient,
869
869
dwdsStats,
870
- ddsUri,
870
+ dds? .wsUri,
871
+ dds? .devToolsUri,
871
872
);
872
873
final encodedUri = await debugService.encodedUri;
873
874
_logger.info ('Debug service listening on $encodedUri \n ' );
@@ -985,8 +986,7 @@ class DevHandler {
985
986
},
986
987
useSse: _useSseForDebugProxy,
987
988
expressionCompiler: _expressionCompiler,
988
- spawnDds: _spawnDds,
989
- ddsPort: _ddsPort,
989
+ ddsConfig: _ddsConfig,
990
990
);
991
991
appServices = await _createAppDebugServices (debugService);
992
992
extensionDebugger.sendEvent ('dwds.debugUri' , debugService.uri);
@@ -1026,27 +1026,17 @@ class DevHandler {
1026
1026
emitEvent (DwdsEvent .devtoolsLaunch ());
1027
1027
// Send the DevTools URI to the Dart Debug Extension so that it can open it:
1028
1028
final devToolsUri = _constructDevToolsUri (
1029
+ appServices,
1029
1030
encodedUri,
1030
1031
ideQueryParam: 'ChromeDevTools' ,
1031
1032
);
1032
1033
return extensionDebugger.sendEvent ('dwds.devtoolsUri' , devToolsUri);
1033
1034
}
1034
1035
1035
- DevTools _ensureDevTools () {
1036
- final devTools = _devTools;
1037
- if (devTools == null ) {
1038
- throw StateError ('DevHandler: DevTools is not available' );
1039
- }
1040
- return devTools;
1041
- }
1042
-
1043
1036
Future <void > _launchDevTools (
1044
1037
RemoteDebugger remoteDebugger,
1045
1038
String devToolsUri,
1046
1039
) async {
1047
- // TODO(annagrin): move checking whether devtools should be started
1048
- // and the creation of the uri logic here so it is easier to follow.
1049
- _ensureDevTools ();
1050
1040
// TODO(grouma) - We may want to log the debugServiceUri if we don't launch
1051
1041
// DevTools so that users can manually connect.
1052
1042
emitEvent (DwdsEvent .devtoolsLaunch ());
@@ -1057,20 +1047,28 @@ class DevHandler {
1057
1047
}
1058
1048
1059
1049
String _constructDevToolsUri (
1060
- String debugServiceUri, {
1050
+ AppDebugServices appDebugServices,
1051
+ String serviceUri, {
1061
1052
String ideQueryParam = '' ,
1062
1053
}) {
1063
- final devTools = _ensureDevTools ();
1064
- return Uri (
1065
- scheme: 'http' ,
1066
- host: devTools.hostname,
1067
- port: devTools.port,
1068
- path: 'debugger' ,
1069
- queryParameters: {
1070
- 'uri' : debugServiceUri,
1071
- if (ideQueryParam.isNotEmpty) 'ide' : ideQueryParam,
1072
- },
1073
- ).toString ();
1054
+ final devToolsUri = _devTools? .uri ?? appDebugServices.devToolsUri;
1055
+ if (devToolsUri == null ) {
1056
+ throw StateError ('DevHandler: DevTools is not available' );
1057
+ }
1058
+ return devToolsUri
1059
+ .replace (
1060
+ pathSegments: [
1061
+ // Strips any trailing slashes from the original path
1062
+ ...devToolsUri.pathSegments.whereNot ((e) => e.isEmpty),
1063
+ 'debugger' ,
1064
+ ],
1065
+ queryParameters: {
1066
+ ...devToolsUri.queryParameters,
1067
+ 'uri' : serviceUri,
1068
+ if (ideQueryParam.isNotEmpty) 'ide' : ideQueryParam,
1069
+ },
1070
+ )
1071
+ .toString ();
1074
1072
}
1075
1073
1076
1074
static void _maybeEmitDwdsAttachEvent (DevToolsRequest request) {
0 commit comments