Skip to content

Commit 0f57f00

Browse files
committed
added a flag to determine the communication protocol; temporirily use it to trigger main
1 parent ba9d21a commit 0f57f00

File tree

7 files changed

+124
-96
lines changed

7 files changed

+124
-96
lines changed

dwds/CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
## 24.3.11
22

3-
- Changed DWDS to always inject the client and use `runMainAtStart` flag to control whether main() execution is deferred or runs immediately.
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.
44
- Added WebSocket-based hot reload support: `reloadSources` in `ChromeProxyService` and `DevHandler` now handle hot reload requests and responses over WebSockets.
55
- Refactored the injected client to use a reusable function for handling hot reload requests and responses over WebSockets.
66

dwds/lib/dart_web_debug_service.dart

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,10 +68,10 @@ class Dwds {
6868
required ToolConfiguration toolConfiguration,
6969
// ignore: avoid-unused-parameters
7070
@Deprecated(
71-
'Use runMainAtStart instead. This parameter is ignored and will be removed in a future version.',
71+
'This parameter is ignored and will be removed in a future version.',
7272
)
7373
bool injectDebuggingSupportCode = true,
74-
bool runMainAtStart = false,
74+
bool useDwdsWebSocketConnection = false,
7575
}) async {
7676
globalToolConfiguration = toolConfiguration;
7777
final debugSettings = toolConfiguration.debugSettings;
@@ -125,7 +125,7 @@ class Dwds {
125125

126126
final injected = DwdsInjector(
127127
extensionUri: extensionUri,
128-
runMainAtStart: runMainAtStart,
128+
useDwdsWebSocketConnection: useDwdsWebSocketConnection,
129129
);
130130

131131
final devHandler = DevHandler(

dwds/lib/src/connections/app_connection.dart

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -44,14 +44,4 @@ class AppConnection {
4444
_connection.sink.add(jsonEncode(serializers.serialize(RunRequest())));
4545
_startedCompleter.complete();
4646
}
47-
48-
/// Marks the application as started by completing the _startedCompleter.
49-
/// This can be used when the application starts through alternative means
50-
/// (e.g., immediate execution) rather than through the runMain() flow.
51-
void markAsStarted() {
52-
if (_startedCompleter.isCompleted) {
53-
throw StateError('Application has already been marked as started.');
54-
}
55-
_startedCompleter.complete();
56-
}
5747
}

dwds/lib/src/handlers/injector.dart

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -30,23 +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 `_runMainAtStart` flag determines whether main() execution should be
34-
/// deferred or run immediately:
35-
/// - When `true`, main() is executed immediately when the app is loaded.
36-
/// - When `false`, main() execution is deferred, allowing for setup or
37-
/// debugging initialization before main() runs.
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 _runMainAtStart;
41+
final bool _useDwdsWebSocketConnection;
4642

47-
DwdsInjector({Future<String>? extensionUri, bool runMainAtStart = true})
48-
: _extensionUri = extensionUri,
49-
_runMainAtStart = runMainAtStart;
43+
DwdsInjector({
44+
Future<String>? extensionUri,
45+
bool useDwdsWebSocketConnection = false,
46+
}) : _extensionUri = extensionUri,
47+
_useDwdsWebSocketConnection = useDwdsWebSocketConnection;
5048

5149
/// Returns the embedded dev handler paths.
5250
///
@@ -115,7 +113,7 @@ class DwdsInjector {
115113
devHandlerPath,
116114
entrypoint,
117115
await _extensionUri,
118-
_runMainAtStart,
116+
_useDwdsWebSocketConnection,
119117
);
120118
body += await globalToolConfiguration.loadStrategy.bootstrapFor(
121119
entrypoint,
@@ -152,7 +150,7 @@ Future<String> _injectClientAndHoistMain(
152150
String devHandlerPath,
153151
String entrypointPath,
154152
String? extensionUri,
155-
bool runMainAtStart,
153+
bool useDwdsWebSocketConnection,
156154
) async {
157155
final bodyLines = body.split('\n');
158156
final extensionIndex = bodyLines.indexWhere(
@@ -171,7 +169,7 @@ Future<String> _injectClientAndHoistMain(
171169
devHandlerPath,
172170
entrypointPath,
173171
extensionUri,
174-
runMainAtStart,
172+
useDwdsWebSocketConnection,
175173
);
176174
result += '''
177175
// Injected by dwds for debugging support.
@@ -203,7 +201,7 @@ Future<String> _injectedClientSnippet(
203201
String devHandlerPath,
204202
String entrypointPath,
205203
String? extensionUri,
206-
bool runMainAtStart,
204+
bool useDwdsWebSocketConnection,
207205
) async {
208206
final loadStrategy = globalToolConfiguration.loadStrategy;
209207
final buildSettings = loadStrategy.buildSettings;
@@ -222,7 +220,7 @@ Future<String> _injectedClientSnippet(
222220
'window.\$dartEmitDebugEvents = ${debugSettings.emitDebugEvents};\n'
223221
'window.\$isInternalBuild = ${appMetadata.isInternalBuild};\n'
224222
'window.\$isFlutterApp = ${buildSettings.isFlutterApp};\n'
225-
'window.\$runMainAtStart = $runMainAtStart;\n'
223+
'window.\$useDwdsWebSocketConnection = $useDwdsWebSocketConnection;\n'
226224
'${loadStrategy is DdcLibraryBundleStrategy ? 'window.\$hotReloadSourcesPath = "${loadStrategy.hotReloadSourcesUri.toString()}";\n' : ''}'
227225
'${loadStrategy.loadClientSnippet(_clientScript)}';
228226

0 commit comments

Comments
 (0)