Skip to content

Commit

Permalink
[Debug extension] Minor dep updates and cleanup (#2507)
Browse files Browse the repository at this point in the history
  • Loading branch information
parlough authored Oct 23, 2024
1 parent 341e6d3 commit 0e78eca
Show file tree
Hide file tree
Showing 15 changed files with 108 additions and 158 deletions.
1 change: 0 additions & 1 deletion _analysis_config/lib/analysis_options.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ linter:
- literal_only_boolean_expressions
- omit_local_variable_types
- only_throw_errors
- package_api_docs
- package_prefixed_library_names
- prefer_final_in_for_each
- prefer_final_locals
Expand Down
28 changes: 14 additions & 14 deletions dwds/debug_extension/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,27 +1,27 @@
name: mv3_extension
publish_to: none
version: 2.1.4
version: 2.1.5-wip
description: >-
A Chrome extension for Dart debugging.
environment:
sdk: ^3.2.0
sdk: ^3.5.0

dependencies:
built_value: ^8.3.0
collection: ^1.15.0
js: ^0.6.1+1
built_value: ^8.9.0
collection: ^1.19.0
js: ^0.6.7

dev_dependencies:
args: ^2.3.1
build: ^2.0.0
build_runner: ^2.4.0
built_collection: ^5.0.0
built_value_generator: ^8.3.0
build_web_compilers: ^4.0.4
dwds: ^16.0.0
path: ^1.8.1
sse: ^4.1.2
args: ^2.5.0
build: ^2.4.1
build_runner: ^2.4.12
build_web_compilers: ^4.0.11
built_collection: ^5.1.1
built_value_generator: ^8.9.2
dwds: ^24.1.0
path: ^1.9.0
sse: ^4.1.4
web_socket_channel: '>=2.2.0 <4.0.0'

dependency_overrides:
Expand Down
4 changes: 2 additions & 2 deletions dwds/debug_extension/web/background.dart
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ void _registerListeners() {
chrome.windows.onFocusChanged.addListener(
allowInterop((_) async {
final currentTab = await activeTab;
if (currentTab?.id != null) {
await _updateIcon(currentTab!.id);
if (currentTab?.id case final tabId?) {
await _updateIcon(tabId);
}
}),
);
Expand Down
3 changes: 2 additions & 1 deletion dwds/debug_extension/web/chrome_api.dart
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,8 @@ class Runtime {

external String get id;

// Note: Not checking the lastError when one occurs throws a runtime exception.
// Note: Not checking the lastError when one occurs
// throws a runtime exception.
external ChromeError? get lastError;

external ConnectionHandler get onConnect;
Expand Down
4 changes: 2 additions & 2 deletions dwds/debug_extension/web/cider_connection.dart
Original file line number Diff line number Diff line change
Expand Up @@ -175,8 +175,8 @@ Future<void> _sendInspectorUrl({String? appId}) async {
if (!alreadyDebugging) {
sendErrorMessageToCider(
errorType: CiderErrorType.invalidRequest,
errorDetails:
'Cannot send the inspector URL before the debugger has been attached.',
errorDetails: 'Cannot send the inspector URL before '
'the debugger has been attached.',
);
return;
}
Expand Down
9 changes: 5 additions & 4 deletions dwds/debug_extension/web/data_types.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ abstract class ConnectFailure
static Serializer<ConnectFailure> get serializer =>
_$connectFailureSerializer;

factory ConnectFailure([Function(ConnectFailureBuilder) updates]) =
factory ConnectFailure([void Function(ConnectFailureBuilder) updates]) =
_$ConnectFailure;

ConnectFailure._();
Expand All @@ -27,7 +27,7 @@ abstract class DevToolsOpener
static Serializer<DevToolsOpener> get serializer =>
_$devToolsOpenerSerializer;

factory DevToolsOpener([Function(DevToolsOpenerBuilder) updates]) =
factory DevToolsOpener([void Function(DevToolsOpenerBuilder) updates]) =
_$DevToolsOpener;

DevToolsOpener._();
Expand All @@ -38,7 +38,8 @@ abstract class DevToolsOpener
abstract class DevToolsUrl implements Built<DevToolsUrl, DevToolsUrlBuilder> {
static Serializer<DevToolsUrl> get serializer => _$devToolsUrlSerializer;

factory DevToolsUrl([Function(DevToolsUrlBuilder) updates]) = _$DevToolsUrl;
factory DevToolsUrl([void Function(DevToolsUrlBuilder) updates]) =
_$DevToolsUrl;

DevToolsUrl._();

Expand All @@ -56,7 +57,7 @@ abstract class DebugStateChange
static Serializer<DebugStateChange> get serializer =>
_$debugStateChangeSerializer;

factory DebugStateChange([Function(DebugStateChangeBuilder) updates]) =
factory DebugStateChange([void Function(DebugStateChangeBuilder) updates]) =
_$DebugStateChange;

DebugStateChange._();
Expand Down
12 changes: 6 additions & 6 deletions dwds/debug_extension/web/debug_info.dart
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,14 @@ String _readDartDebugInfo() {
serializers.serialize(
DebugInfo(
(b) => b
..appEntrypointPath = windowContext['\$dartEntrypointPath']
..appId = windowContext['\$dartAppId']
..appInstanceId = windowContext['\$dartAppInstanceId']
..appEntrypointPath = windowContext['\$dartEntrypointPath'] as String?
..appId = windowContext['\$dartAppId'] as String?
..appInstanceId = windowContext['\$dartAppInstanceId'] as String?
..appOrigin = window.location.origin
..appUrl = window.location.href
..extensionUrl = windowContext['\$dartExtensionUri']
..isInternalBuild = windowContext['\$isInternalBuild']
..isFlutterApp = windowContext['\$isFlutterApp'],
..extensionUrl = windowContext['\$dartExtensionUri'] as String?
..isInternalBuild = windowContext['\$isInternalBuild'] as bool?
..isFlutterApp = windowContext['\$isFlutterApp'] as bool?,
),
),
);
Expand Down
102 changes: 41 additions & 61 deletions dwds/debug_extension/web/debug_session.dart
Original file line number Diff line number Diff line change
Expand Up @@ -79,18 +79,12 @@ enum Trigger {
extensionPanel,
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';
}
}
String get clientName => switch (this) {
Trigger.angularDartDevTools => 'acx-devtools',
Trigger.cider => 'cider',
Trigger.extensionPanel => 'embedded-devtools',
Trigger.extensionIcon => 'devtools'
};
}

enum DebuggerLocation {
Expand All @@ -99,18 +93,12 @@ enum DebuggerLocation {
dartDevTools,
ide;

String get displayName {
switch (this) {
case DebuggerLocation.angularDartDevTools:
return 'AngularDart DevTools';
case DebuggerLocation.chromeDevTools:
return 'Chrome DevTools';
case DebuggerLocation.dartDevTools:
return 'a Dart DevTools tab';
case DebuggerLocation.ide:
return 'an IDE';
}
}
String get displayName => switch (this) {
DebuggerLocation.angularDartDevTools => 'AngularDart DevTools',
DebuggerLocation.chromeDevTools => 'Chrome DevTools',
DebuggerLocation.dartDevTools => 'a Dart DevTools tab',
DebuggerLocation.ide => 'an IDE'
};
}

bool get existsActiveDebugSession => _debugSessions.isNotEmpty;
Expand Down Expand Up @@ -331,8 +319,9 @@ Future<bool> _isDartFrame({required int tabId, required int contextId}) {
Debuggee(tabId: tabId),
'Runtime.evaluate',
_InjectedParams(
expression:
'[window.\$dartAppId, window.\$dartAppInstanceId, window.\$dwdsVersion]',
expression: '[window.\$dartAppId, '
'window.\$dartAppInstanceId, '
'window.\$dwdsVersion]',
returnByValue: true,
contextId: contextId,
),
Expand Down Expand Up @@ -360,11 +349,12 @@ Future<bool> _connectToDwds({
required int dartAppTabId,
required DebugInfo debugInfo,
}) async {
if (debugInfo.extensionUrl == null) {
final extensionUrl = debugInfo.extensionUrl;
if (extensionUrl == null) {
debugWarn('Can\'t connect to DWDS without an extension URL.');
return false;
}
final uri = Uri.parse(debugInfo.extensionUrl!);
final uri = Uri.parse(extensionUrl);
// Start the client connection with DWDS:
final client = uri.isScheme('ws') || uri.isScheme('wss')
? WebSocketClient(WebSocketChannel.connect(uri))
Expand Down Expand Up @@ -497,7 +487,8 @@ void _forwardDwdsEventToChromeDebugger(
);
} catch (error) {
debugError(
'Error forwarding ${message.command} with ${message.commandParams} to chrome.debugger: $error',
'Error forwarding ${message.command} with ${message.commandParams} to '
'chrome.debugger: $error',
);
}
}
Expand Down Expand Up @@ -660,15 +651,13 @@ Future<bool> _sendStopDebuggingMessage(
);
}

_DebugSession? _debugSessionForTab(tabId, {required TabType type}) {
switch (type) {
case TabType.dartApp:
return _debugSessions
.firstWhereOrNull((session) => session.appTabId == tabId);
case TabType.devTools:
return _debugSessions
.firstWhereOrNull((session) => session.devToolsTabId == tabId);
}
_DebugSession? _debugSessionForTab(int tabId, {required TabType type}) {
return switch (type) {
TabType.dartApp =>
_debugSessions.firstWhereOrNull((session) => session.appTabId == tabId),
TabType.devTools => _debugSessions
.firstWhereOrNull((session) => session.devToolsTabId == tabId)
};
}

Future<bool> _authenticateUser(int tabId) async {
Expand Down Expand Up @@ -746,20 +735,14 @@ DebuggerLocation? _debuggerLocation(int dartAppTabId) {
final trigger = _tabIdToTrigger[dartAppTabId];
if (debugSession == null || trigger == null) return null;

switch (trigger) {
case Trigger.extensionIcon:
if (debugSession.devToolsTabId != null) {
return DebuggerLocation.dartDevTools;
} else {
return DebuggerLocation.ide;
}
case Trigger.angularDartDevTools:
return DebuggerLocation.angularDartDevTools;
case Trigger.extensionPanel:
return DebuggerLocation.chromeDevTools;
case Trigger.cider:
return DebuggerLocation.ide;
}
return switch (trigger) {
Trigger.angularDartDevTools => DebuggerLocation.angularDartDevTools,
Trigger.cider => DebuggerLocation.ide,
Trigger.extensionPanel => DebuggerLocation.chromeDevTools,
Trigger.extensionIcon => debugSession.devToolsTabId != null
? DebuggerLocation.dartDevTools
: DebuggerLocation.ide,
};
}

/// Construct an [ExtensionEvent] from [method] and [params].
Expand Down Expand Up @@ -804,7 +787,7 @@ class _DebugSession {
late final StreamSubscription<List<ExtensionEvent>> _batchSubscription;

_DebugSession({
required client,
required SocketClient client,
required this.appTabId,
required this.trigger,
required void Function(String data) onIncoming,
Expand Down Expand Up @@ -888,14 +871,11 @@ class _DebugSession {
String? _authUrl(String? extensionUrl) {
if (extensionUrl == null) return null;
final authUrl = Uri.parse(extensionUrl).replace(path: authenticationPath);
switch (authUrl.scheme) {
case 'ws':
return authUrl.replace(scheme: 'http').toString();
case 'wss':
return authUrl.replace(scheme: 'https').toString();
default:
return authUrl.toString();
}
return switch (authUrl.scheme) {
'ws' => authUrl.replace(scheme: 'http').toString(),
'wss' => authUrl.replace(scheme: 'https').toString(),
_ => authUrl.toString()
};
}

@JS()
Expand Down
2 changes: 0 additions & 2 deletions dwds/debug_extension/web/logger.dart
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,8 @@ void _log(
switch (logLevel) {
case _LogLevel.error:
_console.error(logMsg);
break;
case _LogLevel.warn:
_console.warn(logMsg);
break;
case _LogLevel.info:
_console.log(logMsg);
}
Expand Down
3 changes: 2 additions & 1 deletion dwds/debug_extension/web/messaging.dart
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,8 @@ void interceptMessage<T>({
}
} catch (error) {
debugError(
'Error intercepting $expectedType from $expectedSender to $expectedRecipient: $error',
'Error intercepting $expectedType from '
'$expectedSender to $expectedRecipient: $error',
);
}
}
Expand Down
12 changes: 4 additions & 8 deletions dwds/debug_extension/web/panel.dart
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ int get _tabId => chrome.devtools.inspectedWindow.tabId;

Future<void> main() async {
unawaited(
_registerListeners().catchError((error) {
_registerListeners().catchError((Object? error) {
debugWarn('Error registering listeners in panel: $error');
}),
);
Expand Down Expand Up @@ -93,7 +93,8 @@ void _handleRuntimeMessages(
messageHandler: (DebugStateChange debugStateChange) async {
if (debugStateChange.tabId != _tabId) {
debugWarn(
'Received debug state change request, but Dart app tab does not match current tab.',
'Received debug state change request, but '
'Dart app tab does not match current tab.',
);
return;
}
Expand Down Expand Up @@ -227,24 +228,19 @@ void _handleDebugConnectionLost(String? reason) {
case DetachReason.staleDebugSession:
case DetachReason.navigatedAwayFromApp:
_showWarningBanner(_noAppDetectedMsg);
break;
default:
_showWarningBanner(_lostConnectionMsg);
break;
}
}

void _handleConnectFailure(ConnectFailureReason reason) {
switch (reason) {
case ConnectFailureReason.authentication:
_showWarningBanner(_pleaseAuthenticateMsg);
break;
case ConnectFailureReason.noDartApp:
_showWarningBanner(_noAppDetectedMsg);
break;
case ConnectFailureReason.timeout:
_showWarningBanner(_connectionTimeoutMsg);
break;
default:
_showWarningBanner(_failedToConnectMsg);
}
Expand Down Expand Up @@ -296,7 +292,7 @@ Future<void> _launchDebugConnection(Event _) async {

Future<void> _maybeHandleConnectionTimeout() async {
_connecting = true;
await Future.delayed(Duration(seconds: 10));
await Future<void>.delayed(const Duration(seconds: 10));
if (_connecting) {
_handleConnectFailure(ConnectFailureReason.timeout);
}
Expand Down
5 changes: 3 additions & 2 deletions dwds/debug_extension/web/popup.dart
Original file line number Diff line number Diff line change
Expand Up @@ -131,10 +131,11 @@ Future<void> _launchDevTools(Event _) async {
}

void _copyAppId(Event _) {
if (_appId == null) return;
final appId = _appId;
if (appId == null) return;
final clipboard = window.navigator.clipboard;
if (clipboard == null) return;
clipboard.writeText(_appId!);
clipboard.writeText(appId);
_updateElementVisibility(_copiedSuccessId, visible: true);
}

Expand Down
Loading

0 comments on commit 0e78eca

Please sign in to comment.