@@ -79,18 +79,12 @@ enum Trigger {
79
79
extensionPanel,
80
80
extensionIcon;
81
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
- }
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
+ };
94
88
}
95
89
96
90
enum DebuggerLocation {
@@ -99,18 +93,12 @@ enum DebuggerLocation {
99
93
dartDevTools,
100
94
ide;
101
95
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
+ };
114
102
}
115
103
116
104
bool get existsActiveDebugSession => _debugSessions.isNotEmpty;
@@ -331,8 +319,9 @@ Future<bool> _isDartFrame({required int tabId, required int contextId}) {
331
319
Debuggee (tabId: tabId),
332
320
'Runtime.evaluate' ,
333
321
_InjectedParams (
334
- expression:
335
- '[window.\$ dartAppId, window.\$ dartAppInstanceId, window.\$ dwdsVersion]' ,
322
+ expression: '[window.\$ dartAppId, '
323
+ 'window.\$ dartAppInstanceId, '
324
+ 'window.\$ dwdsVersion]' ,
336
325
returnByValue: true ,
337
326
contextId: contextId,
338
327
),
@@ -360,11 +349,12 @@ Future<bool> _connectToDwds({
360
349
required int dartAppTabId,
361
350
required DebugInfo debugInfo,
362
351
}) async {
363
- if (debugInfo.extensionUrl == null ) {
352
+ final extensionUrl = debugInfo.extensionUrl;
353
+ if (extensionUrl == null ) {
364
354
debugWarn ('Can\' t connect to DWDS without an extension URL.' );
365
355
return false ;
366
356
}
367
- final uri = Uri .parse (debugInfo. extensionUrl! );
357
+ final uri = Uri .parse (extensionUrl);
368
358
// Start the client connection with DWDS:
369
359
final client = uri.isScheme ('ws' ) || uri.isScheme ('wss' )
370
360
? WebSocketClient (WebSocketChannel .connect (uri))
@@ -497,7 +487,8 @@ void _forwardDwdsEventToChromeDebugger(
497
487
);
498
488
} catch (error) {
499
489
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 ' ,
501
492
);
502
493
}
503
494
}
@@ -660,15 +651,13 @@ Future<bool> _sendStopDebuggingMessage(
660
651
);
661
652
}
662
653
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
+ };
672
661
}
673
662
674
663
Future <bool > _authenticateUser (int tabId) async {
@@ -746,20 +735,14 @@ DebuggerLocation? _debuggerLocation(int dartAppTabId) {
746
735
final trigger = _tabIdToTrigger[dartAppTabId];
747
736
if (debugSession == null || trigger == null ) return null ;
748
737
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
+ };
763
746
}
764
747
765
748
/// Construct an [ExtensionEvent] from [method] and [params] .
@@ -804,7 +787,7 @@ class _DebugSession {
804
787
late final StreamSubscription <List <ExtensionEvent >> _batchSubscription;
805
788
806
789
_DebugSession ({
807
- required client,
790
+ required SocketClient client,
808
791
required this .appTabId,
809
792
required this .trigger,
810
793
required void Function (String data) onIncoming,
@@ -888,14 +871,11 @@ class _DebugSession {
888
871
String ? _authUrl (String ? extensionUrl) {
889
872
if (extensionUrl == null ) return null ;
890
873
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
+ };
899
879
}
900
880
901
881
@JS ()
0 commit comments