From 50bf268794a4cb70b3a82d8177e55160ee4227df Mon Sep 17 00:00:00 2001 From: Elliott Brooks <21270878+elliette@users.noreply.github.com> Date: Wed, 24 Apr 2024 12:25:41 -0700 Subject: [PATCH] Add `dwdsLaunch` and `dwdsAttach` events (#2418) --- dwds/debug_extension_mv3/pubspec.yaml | 2 +- .../web/debug_session.dart | 18 +++++++++-- .../debug_extension_mv3/web/manifest_mv3.json | 2 +- dwds/lib/dart_web_debug_service.dart | 14 +++++++++ dwds/lib/data/devtools_request.dart | 6 ++++ dwds/lib/data/devtools_request.g.dart | 31 ++++++++++++++++--- dwds/lib/src/config/tool_configuration.dart | 2 ++ dwds/lib/src/events.dart | 14 +++++++++ dwds/lib/src/handlers/dev_handler.dart | 15 +++++++++ 9 files changed, 96 insertions(+), 8 deletions(-) diff --git a/dwds/debug_extension_mv3/pubspec.yaml b/dwds/debug_extension_mv3/pubspec.yaml index ff14de6ab..82d1cd109 100644 --- a/dwds/debug_extension_mv3/pubspec.yaml +++ b/dwds/debug_extension_mv3/pubspec.yaml @@ -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. diff --git a/dwds/debug_extension_mv3/web/debug_session.dart b/dwds/debug_extension_mv3/web/debug_session.dart index 93609ac3e..d7ffaf058 100644 --- a/dwds/debug_extension_mv3/web/debug_session.dart +++ b/dwds/debug_extension_mv3/web/debug_session.dart @@ -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 { @@ -390,7 +403,8 @@ Future _connectToDwds({ ..instanceId = debugInfo.appInstanceId ..contextId = dartAppContextId ..tabUrl = tabUrl - ..uriOnly = true, + ..uriOnly = true + ..client = trigger?.clientName ?? 'unknown', ), ); return true; diff --git a/dwds/debug_extension_mv3/web/manifest_mv3.json b/dwds/debug_extension_mv3/web/manifest_mv3.json index f08fef622..83ecae394 100644 --- a/dwds/debug_extension_mv3/web/manifest_mv3.json +++ b/dwds/debug_extension_mv3/web/manifest_mv3.json @@ -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": { diff --git a/dwds/lib/dart_web_debug_service.dart b/dwds/lib/dart_web_debug_service.dart index 45aedc6df..4d4aee11d 100644 --- a/dwds/lib/dart_web_debug_service.dart +++ b/dwds/lib/dart_web_debug_service.dart @@ -131,6 +131,8 @@ class Dwds { debugSettings.launchDevToolsInNewWindow, ); + _maybeEmitDwdsLaunchEvent(toolConfiguration); + return Dwds._( injected.middleware, devTools, @@ -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); } diff --git a/dwds/lib/data/devtools_request.dart b/dwds/lib/data/devtools_request.dart index e5c48438f..8b4115ecd 100644 --- a/dwds/lib/data/devtools_request.dart +++ b/dwds/lib/data/devtools_request.dart @@ -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]. diff --git a/dwds/lib/data/devtools_request.g.dart b/dwds/lib/data/devtools_request.g.dart index ba11296ea..dd875b076 100644 --- a/dwds/lib/data/devtools_request.g.dart +++ b/dwds/lib/data/devtools_request.g.dart @@ -50,6 +50,13 @@ class _$DevToolsRequestSerializer ..add( serializers.serialize(value, specifiedType: const FullType(bool))); } + value = object.client; + if (value != null) { + result + ..add('client') + ..add(serializers.serialize(value, + specifiedType: const FullType(String))); + } return result; } @@ -85,6 +92,10 @@ class _$DevToolsRequestSerializer result.uriOnly = serializers.deserialize(value, specifiedType: const FullType(bool)) as bool?; break; + case 'client': + result.client = serializers.deserialize(value, + specifiedType: const FullType(String)) as String?; + break; } } @@ -163,6 +174,8 @@ class _$DevToolsRequest extends DevToolsRequest { final String? tabUrl; @override final bool? uriOnly; + @override + final String? client; factory _$DevToolsRequest([void Function(DevToolsRequestBuilder)? updates]) => (new DevToolsRequestBuilder()..update(updates))._build(); @@ -172,7 +185,8 @@ class _$DevToolsRequest extends DevToolsRequest { required this.instanceId, this.contextId, this.tabUrl, - this.uriOnly}) + this.uriOnly, + this.client}) : super._() { BuiltValueNullFieldError.checkNotNull(appId, r'DevToolsRequest', 'appId'); BuiltValueNullFieldError.checkNotNull( @@ -195,7 +209,8 @@ class _$DevToolsRequest extends DevToolsRequest { instanceId == other.instanceId && contextId == other.contextId && tabUrl == other.tabUrl && - uriOnly == other.uriOnly; + uriOnly == other.uriOnly && + client == other.client; } @override @@ -206,6 +221,7 @@ class _$DevToolsRequest extends DevToolsRequest { _$hash = $jc(_$hash, contextId.hashCode); _$hash = $jc(_$hash, tabUrl.hashCode); _$hash = $jc(_$hash, uriOnly.hashCode); + _$hash = $jc(_$hash, client.hashCode); _$hash = $jf(_$hash); return _$hash; } @@ -217,7 +233,8 @@ class _$DevToolsRequest extends DevToolsRequest { ..add('instanceId', instanceId) ..add('contextId', contextId) ..add('tabUrl', tabUrl) - ..add('uriOnly', uriOnly)) + ..add('uriOnly', uriOnly) + ..add('client', client)) .toString(); } } @@ -246,6 +263,10 @@ class DevToolsRequestBuilder bool? get uriOnly => _$this._uriOnly; set uriOnly(bool? uriOnly) => _$this._uriOnly = uriOnly; + String? _client; + String? get client => _$this._client; + set client(String? client) => _$this._client = client; + DevToolsRequestBuilder(); DevToolsRequestBuilder get _$this { @@ -256,6 +277,7 @@ class DevToolsRequestBuilder _contextId = $v.contextId; _tabUrl = $v.tabUrl; _uriOnly = $v.uriOnly; + _client = $v.client; _$v = null; } return this; @@ -284,7 +306,8 @@ class DevToolsRequestBuilder instanceId, r'DevToolsRequest', 'instanceId'), contextId: contextId, tabUrl: tabUrl, - uriOnly: uriOnly); + uriOnly: uriOnly, + client: client); replace(_$result); return _$result; } diff --git a/dwds/lib/src/config/tool_configuration.dart b/dwds/lib/src/config/tool_configuration.dart index 01e0e92a8..9a9a5185a 100644 --- a/dwds/lib/src/config/tool_configuration.dart +++ b/dwds/lib/src/config/tool_configuration.dart @@ -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, }); } diff --git a/dwds/lib/src/events.dart b/dwds/lib/src/events.dart index 98a624732..d120f94e7 100644 --- a/dwds/lib/src/events.dart +++ b/dwds/lib/src/events.dart @@ -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'; @@ -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, diff --git a/dwds/lib/src/handlers/dev_handler.dart b/dwds/lib/src/handlers/dev_handler.dart index 63e93adb0..753f0e7de 100644 --- a/dwds/lib/src/handlers/dev_handler.dart +++ b/dwds/lib/src/handlers/dev_handler.dart @@ -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; @@ -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 {