Skip to content

Commit a321863

Browse files
authored
modifying DWDS Injector to always inject client and introduce useDwdsWebSocketConnection flag (#2629)
* modifying injector to always inject client and introduce runMainAtStart flag * mark fields as deprecated * added method to mark application as completed to avoid calling main() twice * added a flag to determine the communication protocol; temporirily use it to trigger main * addressed comment in client.dart
1 parent 2eb2754 commit a321863

File tree

7 files changed

+436
-334
lines changed

7 files changed

+436
-334
lines changed

dwds/CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
## 24.3.11-wip
1+
## 24.3.11
22

3+
- Changed DWDS to always inject the client and added `useDwdsWebSocketConnection` flag to control communication protocol: when true uses socket-based implementation, when false uses Chrome-based communication protocol.
34
- Added WebSocket-based hot reload support: `reloadSources` in `ChromeProxyService` and `DevHandler` now handle hot reload requests and responses over WebSockets.
45
- Refactored the injected client to use a reusable function for handling hot reload requests and responses over WebSockets.
56
- Added support for breakpoint registering on a hot restart with the DDC library bundle format using PausePostRequests.

dwds/lib/dart_web_debug_service.dart

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,12 @@ class Dwds {
6666
required Stream<BuildResult> buildResults,
6767
required ConnectionProvider chromeConnection,
6868
required ToolConfiguration toolConfiguration,
69+
// ignore: avoid-unused-parameters
70+
@Deprecated(
71+
'This parameter is ignored and will be removed in a future version.',
72+
)
6973
bool injectDebuggingSupportCode = true,
74+
bool useDwdsWebSocketConnection = false,
7075
}) async {
7176
globalToolConfiguration = toolConfiguration;
7277
final debugSettings = toolConfiguration.debugSettings;
@@ -120,7 +125,7 @@ class Dwds {
120125

121126
final injected = DwdsInjector(
122127
extensionUri: extensionUri,
123-
injectDebuggingSupportCode: injectDebuggingSupportCode,
128+
useDwdsWebSocketConnection: useDwdsWebSocketConnection,
124129
);
125130

126131
final devHandler = DevHandler(

dwds/lib/src/handlers/injector.dart

Lines changed: 20 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -30,25 +30,21 @@ const _clientScript = 'dwds/src/injected/client';
3030
/// to include the injected DWDS client, enabling debugging capabilities
3131
/// and source mapping when running in a browser environment.
3232
///
33-
/// The `_injectDebuggingSupportCode` flag determines whether debugging-related
34-
/// functionality should be included:
35-
/// - When `true`, the DWDS client is injected, enabling debugging features.
36-
/// - When `false`, debugging support is disabled, meaning the application will
37-
/// run without debugging.
38-
///
39-
/// This separation allows for scenarios where debugging is not needed or
40-
/// should be explicitly avoided.
33+
/// TODO(yjessy): Remove this when the DWDS WebSocket connection is implemented.
34+
/// The `_useDwdsWebSocketConnection` flag determines the communication protocol:
35+
/// - When `true`, uses a socket-based implementation.
36+
/// - When `false`, uses Chrome-based communication protocol.
4137
class DwdsInjector {
4238
final Future<String>? _extensionUri;
4339
final _devHandlerPaths = StreamController<String>();
4440
final _logger = Logger('DwdsInjector');
45-
final bool _injectDebuggingSupportCode;
41+
final bool _useDwdsWebSocketConnection;
4642

4743
DwdsInjector({
4844
Future<String>? extensionUri,
49-
bool injectDebuggingSupportCode = true,
45+
bool useDwdsWebSocketConnection = false,
5046
}) : _extensionUri = extensionUri,
51-
_injectDebuggingSupportCode = injectDebuggingSupportCode;
47+
_useDwdsWebSocketConnection = useDwdsWebSocketConnection;
5248

5349
/// Returns the embedded dev handler paths.
5450
///
@@ -108,17 +104,15 @@ class DwdsInjector {
108104
await globalToolConfiguration.loadStrategy.trackEntrypoint(
109105
entrypoint,
110106
);
111-
// If true, inject the debugging client and hoist the main function
112-
// to enable debugging support.
113-
if (_injectDebuggingSupportCode) {
114-
body = await _injectClientAndHoistMain(
115-
body,
116-
appId,
117-
devHandlerPath,
118-
entrypoint,
119-
await _extensionUri,
120-
);
121-
}
107+
// Always inject the debugging client and hoist the main function.
108+
body = await _injectClientAndHoistMain(
109+
body,
110+
appId,
111+
devHandlerPath,
112+
entrypoint,
113+
await _extensionUri,
114+
_useDwdsWebSocketConnection,
115+
);
122116
body += await globalToolConfiguration.loadStrategy.bootstrapFor(
123117
entrypoint,
124118
);
@@ -154,6 +148,7 @@ Future<String> _injectClientAndHoistMain(
154148
String devHandlerPath,
155149
String entrypointPath,
156150
String? extensionUri,
151+
bool useDwdsWebSocketConnection,
157152
) async {
158153
final bodyLines = body.split('\n');
159154
final extensionIndex = bodyLines.indexWhere(
@@ -172,6 +167,7 @@ Future<String> _injectClientAndHoistMain(
172167
devHandlerPath,
173168
entrypointPath,
174169
extensionUri,
170+
useDwdsWebSocketConnection,
175171
);
176172
result += '''
177173
// Injected by dwds for debugging support.
@@ -203,6 +199,7 @@ Future<String> _injectedClientSnippet(
203199
String devHandlerPath,
204200
String entrypointPath,
205201
String? extensionUri,
202+
bool useDwdsWebSocketConnection,
206203
) async {
207204
final loadStrategy = globalToolConfiguration.loadStrategy;
208205
final buildSettings = loadStrategy.buildSettings;
@@ -221,6 +218,7 @@ Future<String> _injectedClientSnippet(
221218
'window.\$dartEmitDebugEvents = ${debugSettings.emitDebugEvents};\n'
222219
'window.\$isInternalBuild = ${appMetadata.isInternalBuild};\n'
223220
'window.\$isFlutterApp = ${buildSettings.isFlutterApp};\n'
221+
'window.\$useDwdsWebSocketConnection = $useDwdsWebSocketConnection;\n'
224222
'${loadStrategy is DdcLibraryBundleStrategy ? 'window.\$hotReloadSourcesPath = "${loadStrategy.hotReloadSourcesUri.toString()}";\n' : ''}'
225223
'${loadStrategy.loadClientSnippet(_clientScript)}';
226224

0 commit comments

Comments
 (0)