@@ -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
9690enum 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
116104bool 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
674663Future <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 {
888871String ? _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 ()
0 commit comments