Skip to content

Commit 47a6634

Browse files
committed
added method to mark application as completed to avoid calling main() twice
1 parent dd16b7d commit 47a6634

File tree

4 files changed

+35
-30
lines changed

4 files changed

+35
-30
lines changed

dwds/lib/dart_web_debug_service.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ class Dwds {
6666
required Stream<BuildResult> buildResults,
6767
required ConnectionProvider chromeConnection,
6868
required ToolConfiguration toolConfiguration,
69+
// ignore: avoid-unused-parameters
6970
@Deprecated(
7071
'Use runMainAtStart instead. This parameter is ignored and will be removed in a future version.',
7172
)

dwds/lib/src/connections/app_connection.dart

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,4 +44,14 @@ 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+
}
4757
}

dwds/lib/src/injected/client.js

Lines changed: 10 additions & 14 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dwds/web/client.dart

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -240,22 +240,16 @@ Future<void>? main() {
240240
});
241241
}
242242

243-
if (_isChromium) {
244-
_trySendEvent(
245-
client.sink,
246-
jsonEncode(
247-
serializers.serialize(
248-
ConnectRequest(
249-
(b) =>
250-
b
251-
..appId = dartAppId
252-
..instanceId = dartAppInstanceId
253-
..entrypointPath = dartEntrypointPath,
254-
),
255-
),
256-
),
257-
);
258-
}
243+
_sendConnectRequest(
244+
client.sink,
245+
ConnectRequest(
246+
(b) =>
247+
b
248+
..appId = dartAppId
249+
..instanceId = dartAppInstanceId
250+
..entrypointPath = dartEntrypointPath,
251+
),
252+
);
259253

260254
if (runMainAtStart) {
261255
runMain();
@@ -293,6 +287,10 @@ void _trySendEvent<T>(StreamSink<T> sink, T serialized) {
293287
}
294288
}
295289

290+
void _sendConnectRequest(StreamSink clientSink, ConnectRequest request) {
291+
_trySendEvent(clientSink, jsonEncode(serializers.serialize(request)));
292+
}
293+
296294
/// Returns [url] modified if necessary so that, if the current page is served
297295
/// over `https`, then the URL is converted to `https`.
298296
String _fixProtocol(String url) {

0 commit comments

Comments
 (0)