Skip to content

Commit 0e78eca

Browse files
authored
[Debug extension] Minor dep updates and cleanup (#2507)
1 parent 341e6d3 commit 0e78eca

15 files changed

+108
-158
lines changed

_analysis_config/lib/analysis_options.yaml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ linter:
2727
- literal_only_boolean_expressions
2828
- omit_local_variable_types
2929
- only_throw_errors
30-
- package_api_docs
3130
- package_prefixed_library_names
3231
- prefer_final_in_for_each
3332
- prefer_final_locals

dwds/debug_extension/pubspec.yaml

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,27 @@
11
name: mv3_extension
22
publish_to: none
3-
version: 2.1.4
3+
version: 2.1.5-wip
44
description: >-
55
A Chrome extension for Dart debugging.
66
77
environment:
8-
sdk: ^3.2.0
8+
sdk: ^3.5.0
99

1010
dependencies:
11-
built_value: ^8.3.0
12-
collection: ^1.15.0
13-
js: ^0.6.1+1
11+
built_value: ^8.9.0
12+
collection: ^1.19.0
13+
js: ^0.6.7
1414

1515
dev_dependencies:
16-
args: ^2.3.1
17-
build: ^2.0.0
18-
build_runner: ^2.4.0
19-
built_collection: ^5.0.0
20-
built_value_generator: ^8.3.0
21-
build_web_compilers: ^4.0.4
22-
dwds: ^16.0.0
23-
path: ^1.8.1
24-
sse: ^4.1.2
16+
args: ^2.5.0
17+
build: ^2.4.1
18+
build_runner: ^2.4.12
19+
build_web_compilers: ^4.0.11
20+
built_collection: ^5.1.1
21+
built_value_generator: ^8.9.2
22+
dwds: ^24.1.0
23+
path: ^1.9.0
24+
sse: ^4.1.4
2525
web_socket_channel: '>=2.2.0 <4.0.0'
2626

2727
dependency_overrides:

dwds/debug_extension/web/background.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,8 @@ void _registerListeners() {
4545
chrome.windows.onFocusChanged.addListener(
4646
allowInterop((_) async {
4747
final currentTab = await activeTab;
48-
if (currentTab?.id != null) {
49-
await _updateIcon(currentTab!.id);
48+
if (currentTab?.id case final tabId?) {
49+
await _updateIcon(tabId);
5050
}
5151
}),
5252
);

dwds/debug_extension/web/chrome_api.dart

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,8 @@ class Runtime {
193193

194194
external String get id;
195195

196-
// Note: Not checking the lastError when one occurs throws a runtime exception.
196+
// Note: Not checking the lastError when one occurs
197+
// throws a runtime exception.
197198
external ChromeError? get lastError;
198199

199200
external ConnectionHandler get onConnect;

dwds/debug_extension/web/cider_connection.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -175,8 +175,8 @@ Future<void> _sendInspectorUrl({String? appId}) async {
175175
if (!alreadyDebugging) {
176176
sendErrorMessageToCider(
177177
errorType: CiderErrorType.invalidRequest,
178-
errorDetails:
179-
'Cannot send the inspector URL before the debugger has been attached.',
178+
errorDetails: 'Cannot send the inspector URL before '
179+
'the debugger has been attached.',
180180
);
181181
return;
182182
}

dwds/debug_extension/web/data_types.dart

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ abstract class ConnectFailure
1212
static Serializer<ConnectFailure> get serializer =>
1313
_$connectFailureSerializer;
1414

15-
factory ConnectFailure([Function(ConnectFailureBuilder) updates]) =
15+
factory ConnectFailure([void Function(ConnectFailureBuilder) updates]) =
1616
_$ConnectFailure;
1717

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

30-
factory DevToolsOpener([Function(DevToolsOpenerBuilder) updates]) =
30+
factory DevToolsOpener([void Function(DevToolsOpenerBuilder) updates]) =
3131
_$DevToolsOpener;
3232

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

41-
factory DevToolsUrl([Function(DevToolsUrlBuilder) updates]) = _$DevToolsUrl;
41+
factory DevToolsUrl([void Function(DevToolsUrlBuilder) updates]) =
42+
_$DevToolsUrl;
4243

4344
DevToolsUrl._();
4445

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

59-
factory DebugStateChange([Function(DebugStateChangeBuilder) updates]) =
60+
factory DebugStateChange([void Function(DebugStateChangeBuilder) updates]) =
6061
_$DebugStateChange;
6162

6263
DebugStateChange._();

dwds/debug_extension/web/debug_info.dart

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,14 @@ String _readDartDebugInfo() {
2525
serializers.serialize(
2626
DebugInfo(
2727
(b) => b
28-
..appEntrypointPath = windowContext['\$dartEntrypointPath']
29-
..appId = windowContext['\$dartAppId']
30-
..appInstanceId = windowContext['\$dartAppInstanceId']
28+
..appEntrypointPath = windowContext['\$dartEntrypointPath'] as String?
29+
..appId = windowContext['\$dartAppId'] as String?
30+
..appInstanceId = windowContext['\$dartAppInstanceId'] as String?
3131
..appOrigin = window.location.origin
3232
..appUrl = window.location.href
33-
..extensionUrl = windowContext['\$dartExtensionUri']
34-
..isInternalBuild = windowContext['\$isInternalBuild']
35-
..isFlutterApp = windowContext['\$isFlutterApp'],
33+
..extensionUrl = windowContext['\$dartExtensionUri'] as String?
34+
..isInternalBuild = windowContext['\$isInternalBuild'] as bool?
35+
..isFlutterApp = windowContext['\$isFlutterApp'] as bool?,
3636
),
3737
),
3838
);

dwds/debug_extension/web/debug_session.dart

Lines changed: 41 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -79,18 +79,12 @@ enum Trigger {
7979
extensionPanel,
8080
extensionIcon;
8181

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-
}
82+
String get clientName => switch (this) {
83+
Trigger.angularDartDevTools => 'acx-devtools',
84+
Trigger.cider => 'cider',
85+
Trigger.extensionPanel => 'embedded-devtools',
86+
Trigger.extensionIcon => 'devtools'
87+
};
9488
}
9589

9690
enum DebuggerLocation {
@@ -99,18 +93,12 @@ enum DebuggerLocation {
9993
dartDevTools,
10094
ide;
10195

102-
String get displayName {
103-
switch (this) {
104-
case DebuggerLocation.angularDartDevTools:
105-
return 'AngularDart DevTools';
106-
case DebuggerLocation.chromeDevTools:
107-
return 'Chrome DevTools';
108-
case DebuggerLocation.dartDevTools:
109-
return 'a Dart DevTools tab';
110-
case DebuggerLocation.ide:
111-
return 'an IDE';
112-
}
113-
}
96+
String get displayName => switch (this) {
97+
DebuggerLocation.angularDartDevTools => 'AngularDart DevTools',
98+
DebuggerLocation.chromeDevTools => 'Chrome DevTools',
99+
DebuggerLocation.dartDevTools => 'a Dart DevTools tab',
100+
DebuggerLocation.ide => 'an IDE'
101+
};
114102
}
115103

116104
bool get existsActiveDebugSession => _debugSessions.isNotEmpty;
@@ -331,8 +319,9 @@ Future<bool> _isDartFrame({required int tabId, required int contextId}) {
331319
Debuggee(tabId: tabId),
332320
'Runtime.evaluate',
333321
_InjectedParams(
334-
expression:
335-
'[window.\$dartAppId, window.\$dartAppInstanceId, window.\$dwdsVersion]',
322+
expression: '[window.\$dartAppId, '
323+
'window.\$dartAppInstanceId, '
324+
'window.\$dwdsVersion]',
336325
returnByValue: true,
337326
contextId: contextId,
338327
),
@@ -360,11 +349,12 @@ Future<bool> _connectToDwds({
360349
required int dartAppTabId,
361350
required DebugInfo debugInfo,
362351
}) async {
363-
if (debugInfo.extensionUrl == null) {
352+
final extensionUrl = debugInfo.extensionUrl;
353+
if (extensionUrl == null) {
364354
debugWarn('Can\'t connect to DWDS without an extension URL.');
365355
return false;
366356
}
367-
final uri = Uri.parse(debugInfo.extensionUrl!);
357+
final uri = Uri.parse(extensionUrl);
368358
// Start the client connection with DWDS:
369359
final client = uri.isScheme('ws') || uri.isScheme('wss')
370360
? WebSocketClient(WebSocketChannel.connect(uri))
@@ -497,7 +487,8 @@ void _forwardDwdsEventToChromeDebugger(
497487
);
498488
} catch (error) {
499489
debugError(
500-
'Error forwarding ${message.command} with ${message.commandParams} to chrome.debugger: $error',
490+
'Error forwarding ${message.command} with ${message.commandParams} to '
491+
'chrome.debugger: $error',
501492
);
502493
}
503494
}
@@ -660,15 +651,13 @@ Future<bool> _sendStopDebuggingMessage(
660651
);
661652
}
662653

663-
_DebugSession? _debugSessionForTab(tabId, {required TabType type}) {
664-
switch (type) {
665-
case TabType.dartApp:
666-
return _debugSessions
667-
.firstWhereOrNull((session) => session.appTabId == tabId);
668-
case TabType.devTools:
669-
return _debugSessions
670-
.firstWhereOrNull((session) => session.devToolsTabId == tabId);
671-
}
654+
_DebugSession? _debugSessionForTab(int tabId, {required TabType type}) {
655+
return switch (type) {
656+
TabType.dartApp =>
657+
_debugSessions.firstWhereOrNull((session) => session.appTabId == tabId),
658+
TabType.devTools => _debugSessions
659+
.firstWhereOrNull((session) => session.devToolsTabId == tabId)
660+
};
672661
}
673662

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

749-
switch (trigger) {
750-
case Trigger.extensionIcon:
751-
if (debugSession.devToolsTabId != null) {
752-
return DebuggerLocation.dartDevTools;
753-
} else {
754-
return DebuggerLocation.ide;
755-
}
756-
case Trigger.angularDartDevTools:
757-
return DebuggerLocation.angularDartDevTools;
758-
case Trigger.extensionPanel:
759-
return DebuggerLocation.chromeDevTools;
760-
case Trigger.cider:
761-
return DebuggerLocation.ide;
762-
}
738+
return switch (trigger) {
739+
Trigger.angularDartDevTools => DebuggerLocation.angularDartDevTools,
740+
Trigger.cider => DebuggerLocation.ide,
741+
Trigger.extensionPanel => DebuggerLocation.chromeDevTools,
742+
Trigger.extensionIcon => debugSession.devToolsTabId != null
743+
? DebuggerLocation.dartDevTools
744+
: DebuggerLocation.ide,
745+
};
763746
}
764747

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

806789
_DebugSession({
807-
required client,
790+
required SocketClient client,
808791
required this.appTabId,
809792
required this.trigger,
810793
required void Function(String data) onIncoming,
@@ -888,14 +871,11 @@ class _DebugSession {
888871
String? _authUrl(String? extensionUrl) {
889872
if (extensionUrl == null) return null;
890873
final authUrl = Uri.parse(extensionUrl).replace(path: authenticationPath);
891-
switch (authUrl.scheme) {
892-
case 'ws':
893-
return authUrl.replace(scheme: 'http').toString();
894-
case 'wss':
895-
return authUrl.replace(scheme: 'https').toString();
896-
default:
897-
return authUrl.toString();
898-
}
874+
return switch (authUrl.scheme) {
875+
'ws' => authUrl.replace(scheme: 'http').toString(),
876+
'wss' => authUrl.replace(scheme: 'https').toString(),
877+
_ => authUrl.toString()
878+
};
899879
}
900880

901881
@JS()

dwds/debug_extension/web/logger.dart

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,10 +51,8 @@ void _log(
5151
switch (logLevel) {
5252
case _LogLevel.error:
5353
_console.error(logMsg);
54-
break;
5554
case _LogLevel.warn:
5655
_console.warn(logMsg);
57-
break;
5856
case _LogLevel.info:
5957
_console.log(logMsg);
6058
}

dwds/debug_extension/web/messaging.dart

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,8 @@ void interceptMessage<T>({
113113
}
114114
} catch (error) {
115115
debugError(
116-
'Error intercepting $expectedType from $expectedSender to $expectedRecipient: $error',
116+
'Error intercepting $expectedType from '
117+
'$expectedSender to $expectedRecipient: $error',
117118
);
118119
}
119120
}

0 commit comments

Comments
 (0)