Skip to content

Commit

Permalink
Add dwdsLaunch and dwdsAttach events (#2418)
Browse files Browse the repository at this point in the history
  • Loading branch information
elliette committed Apr 24, 2024
1 parent 804eb5c commit 50bf268
Show file tree
Hide file tree
Showing 9 changed files with 96 additions and 8 deletions.
2 changes: 1 addition & 1 deletion dwds/debug_extension_mv3/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: mv3_extension
publish_to: none
version: 2.1.3
version: 2.1.4
homepage: https://github.com/dart-lang/webdev
description: >-
A Chrome extension for Dart debugging.
Expand Down
18 changes: 16 additions & 2 deletions dwds/debug_extension_mv3/web/debug_session.dart
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,20 @@ enum Trigger {
angularDartDevTools,
cider,
extensionPanel,
extensionIcon,
extensionIcon;

String get clientName {
switch (this) {
case Trigger.angularDartDevTools:
return 'acx-devtools';
case Trigger.cider:
return 'cider';
case Trigger.extensionPanel:
return 'embedded-devtools';
case Trigger.extensionIcon:
return 'devtools';
}
}
}

enum DebuggerLocation {
Expand Down Expand Up @@ -390,7 +403,8 @@ Future<bool> _connectToDwds({
..instanceId = debugInfo.appInstanceId
..contextId = dartAppContextId
..tabUrl = tabUrl
..uriOnly = true,
..uriOnly = true
..client = trigger?.clientName ?? 'unknown',
),
);
return true;
Expand Down
2 changes: 1 addition & 1 deletion dwds/debug_extension_mv3/web/manifest_mv3.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "Dart Debug Extension",
"version": "2.1.3",
"version": "2.1.4",
"manifest_version": 3,
"devtools_page": "static_assets/devtools.html",
"action": {
Expand Down
14 changes: 14 additions & 0 deletions dwds/lib/dart_web_debug_service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,8 @@ class Dwds {
debugSettings.launchDevToolsInNewWindow,
);

_maybeEmitDwdsLaunchEvent(toolConfiguration);

return Dwds._(
injected.middleware,
devTools,
Expand All @@ -140,6 +142,18 @@ class Dwds {
);
}

static void _maybeEmitDwdsLaunchEvent(ToolConfiguration toolConfiguration) {
if (toolConfiguration.appMetadata.codeRunner != null) {
emitEvent(
DwdsEvent.dwdsLaunch(
codeRunner: toolConfiguration.appMetadata.codeRunner!,
isFlutterApp:
toolConfiguration.loadStrategy.buildSettings.isFlutterApp,
),
);
}
}

bool shouldPauseIsolatesOnStart(String appId) =>
_devHandler.shouldPauseIsolatesOnStart(appId);
}
6 changes: 6 additions & 0 deletions dwds/lib/data/devtools_request.dart
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,12 @@ abstract class DevToolsRequest
/// Only available on requests coming from the Dart Debug Extension. Is `null`
/// for local debug service.
bool? get uriOnly;

/// Identifies the client that DWDS is attaching to.
///
/// This could be Cider, DevTools (as a standalone app), or DevTools (embedded
/// in Chrome DevTools).
String? get client;
}

/// A response to a [DevToolsRequest].
Expand Down
31 changes: 27 additions & 4 deletions dwds/lib/data/devtools_request.g.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions dwds/lib/src/config/tool_configuration.dart
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,13 @@ class AppMetadata {
final String hostname;
final bool isInternalBuild;
final String? workspaceName;
final String? codeRunner;

const AppMetadata({
this.hostname = 'localhost',
this.isInternalBuild = false,
this.workspaceName,
this.codeRunner,
});
}

Expand Down
14 changes: 14 additions & 0 deletions dwds/lib/src/events.dart
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ class DwdsEventKind {
static const String devtoolsLaunch = 'DEVTOOLS_LAUNCH';
static const String devToolsLoad = 'DEVTOOLS_LOAD';
static const String debuggerReady = 'DEBUGGER_READY';
static const String dwdsAttach = 'DWDS_ATTACH';
static const String dwdsLaunch = 'DWDS_LAUNCH';
static const String evaluate = 'EVALUATE';
static const String evaluateInFrame = 'EVALUATE_IN_FRAME';
static const String fullReload = 'FULL_RELOAD';
Expand All @@ -60,6 +62,18 @@ class DwdsEvent {

DwdsEvent(this.type, this.payload);

DwdsEvent.dwdsLaunch({required String codeRunner, bool? isFlutterApp})
: this(DwdsEventKind.dwdsLaunch, {
'codeRunner': codeRunner,
'isFlutterApp': isFlutterApp ?? false,
});

DwdsEvent.dwdsAttach({required String client, bool? isFlutterApp})
: this(DwdsEventKind.dwdsAttach, {
'client': client,
'isFlutterApp': isFlutterApp ?? false,
});

DwdsEvent.compilerUpdateDependencies(String entrypoint)
: this(DwdsEventKind.compilerUpdateDependencies, {
'entrypoint': entrypoint,
Expand Down
15 changes: 15 additions & 0 deletions dwds/lib/src/handlers/dev_handler.dart
Original file line number Diff line number Diff line change
Expand Up @@ -617,6 +617,9 @@ class DevHandler {
extensionDebugConnections.add(DebugConnection(appServices));
_servicesByAppId[appId] = appServices;
}

_maybeEmitDwdsAttachEvent(devToolsRequest);

// If we don't have a DevTools instance, then are connecting to an IDE.
// Therefore return early instead of opening DevTools:
if (_devTools == null) return;
Expand Down Expand Up @@ -680,6 +683,18 @@ class DevHandler {
},
).toString();
}

static void _maybeEmitDwdsAttachEvent(DevToolsRequest request) {
if (request.client != null) {
emitEvent(
DwdsEvent.dwdsAttach(
client: request.client!,
isFlutterApp:
globalToolConfiguration.loadStrategy.buildSettings.isFlutterApp,
),
);
}
}
}

class AppConnectionException implements Exception {
Expand Down

0 comments on commit 50bf268

Please sign in to comment.