Skip to content

Commit 50bf268

Browse files
authored
Add dwdsLaunch and dwdsAttach events (#2418)
1 parent 804eb5c commit 50bf268

9 files changed

+96
-8
lines changed

dwds/debug_extension_mv3/pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name: mv3_extension
22
publish_to: none
3-
version: 2.1.3
3+
version: 2.1.4
44
homepage: https://github.com/dart-lang/webdev
55
description: >-
66
A Chrome extension for Dart debugging.

dwds/debug_extension_mv3/web/debug_session.dart

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,20 @@ enum Trigger {
7777
angularDartDevTools,
7878
cider,
7979
extensionPanel,
80-
extensionIcon,
80+
extensionIcon;
81+
82+
String get clientName {
83+
switch (this) {
84+
case Trigger.angularDartDevTools:
85+
return 'acx-devtools';
86+
case Trigger.cider:
87+
return 'cider';
88+
case Trigger.extensionPanel:
89+
return 'embedded-devtools';
90+
case Trigger.extensionIcon:
91+
return 'devtools';
92+
}
93+
}
8194
}
8295

8396
enum DebuggerLocation {
@@ -390,7 +403,8 @@ Future<bool> _connectToDwds({
390403
..instanceId = debugInfo.appInstanceId
391404
..contextId = dartAppContextId
392405
..tabUrl = tabUrl
393-
..uriOnly = true,
406+
..uriOnly = true
407+
..client = trigger?.clientName ?? 'unknown',
394408
),
395409
);
396410
return true;

dwds/debug_extension_mv3/web/manifest_mv3.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "Dart Debug Extension",
3-
"version": "2.1.3",
3+
"version": "2.1.4",
44
"manifest_version": 3,
55
"devtools_page": "static_assets/devtools.html",
66
"action": {

dwds/lib/dart_web_debug_service.dart

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,8 @@ class Dwds {
131131
debugSettings.launchDevToolsInNewWindow,
132132
);
133133

134+
_maybeEmitDwdsLaunchEvent(toolConfiguration);
135+
134136
return Dwds._(
135137
injected.middleware,
136138
devTools,
@@ -140,6 +142,18 @@ class Dwds {
140142
);
141143
}
142144

145+
static void _maybeEmitDwdsLaunchEvent(ToolConfiguration toolConfiguration) {
146+
if (toolConfiguration.appMetadata.codeRunner != null) {
147+
emitEvent(
148+
DwdsEvent.dwdsLaunch(
149+
codeRunner: toolConfiguration.appMetadata.codeRunner!,
150+
isFlutterApp:
151+
toolConfiguration.loadStrategy.buildSettings.isFlutterApp,
152+
),
153+
);
154+
}
155+
}
156+
143157
bool shouldPauseIsolatesOnStart(String appId) =>
144158
_devHandler.shouldPauseIsolatesOnStart(appId);
145159
}

dwds/lib/data/devtools_request.dart

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,12 @@ abstract class DevToolsRequest
4646
/// Only available on requests coming from the Dart Debug Extension. Is `null`
4747
/// for local debug service.
4848
bool? get uriOnly;
49+
50+
/// Identifies the client that DWDS is attaching to.
51+
///
52+
/// This could be Cider, DevTools (as a standalone app), or DevTools (embedded
53+
/// in Chrome DevTools).
54+
String? get client;
4955
}
5056

5157
/// A response to a [DevToolsRequest].

dwds/lib/data/devtools_request.g.dart

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

dwds/lib/src/config/tool_configuration.dart

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,13 @@ class AppMetadata {
3737
final String hostname;
3838
final bool isInternalBuild;
3939
final String? workspaceName;
40+
final String? codeRunner;
4041

4142
const AppMetadata({
4243
this.hostname = 'localhost',
4344
this.isInternalBuild = false,
4445
this.workspaceName,
46+
this.codeRunner,
4547
});
4648
}
4749

dwds/lib/src/events.dart

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@ class DwdsEventKind {
4040
static const String devtoolsLaunch = 'DEVTOOLS_LAUNCH';
4141
static const String devToolsLoad = 'DEVTOOLS_LOAD';
4242
static const String debuggerReady = 'DEBUGGER_READY';
43+
static const String dwdsAttach = 'DWDS_ATTACH';
44+
static const String dwdsLaunch = 'DWDS_LAUNCH';
4345
static const String evaluate = 'EVALUATE';
4446
static const String evaluateInFrame = 'EVALUATE_IN_FRAME';
4547
static const String fullReload = 'FULL_RELOAD';
@@ -60,6 +62,18 @@ class DwdsEvent {
6062

6163
DwdsEvent(this.type, this.payload);
6264

65+
DwdsEvent.dwdsLaunch({required String codeRunner, bool? isFlutterApp})
66+
: this(DwdsEventKind.dwdsLaunch, {
67+
'codeRunner': codeRunner,
68+
'isFlutterApp': isFlutterApp ?? false,
69+
});
70+
71+
DwdsEvent.dwdsAttach({required String client, bool? isFlutterApp})
72+
: this(DwdsEventKind.dwdsAttach, {
73+
'client': client,
74+
'isFlutterApp': isFlutterApp ?? false,
75+
});
76+
6377
DwdsEvent.compilerUpdateDependencies(String entrypoint)
6478
: this(DwdsEventKind.compilerUpdateDependencies, {
6579
'entrypoint': entrypoint,

dwds/lib/src/handlers/dev_handler.dart

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -617,6 +617,9 @@ class DevHandler {
617617
extensionDebugConnections.add(DebugConnection(appServices));
618618
_servicesByAppId[appId] = appServices;
619619
}
620+
621+
_maybeEmitDwdsAttachEvent(devToolsRequest);
622+
620623
// If we don't have a DevTools instance, then are connecting to an IDE.
621624
// Therefore return early instead of opening DevTools:
622625
if (_devTools == null) return;
@@ -680,6 +683,18 @@ class DevHandler {
680683
},
681684
).toString();
682685
}
686+
687+
static void _maybeEmitDwdsAttachEvent(DevToolsRequest request) {
688+
if (request.client != null) {
689+
emitEvent(
690+
DwdsEvent.dwdsAttach(
691+
client: request.client!,
692+
isFlutterApp:
693+
globalToolConfiguration.loadStrategy.buildSettings.isFlutterApp,
694+
),
695+
);
696+
}
697+
}
683698
}
684699

685700
class AppConnectionException implements Exception {

0 commit comments

Comments
 (0)