@@ -106,26 +106,9 @@ int? get latestAppBeingDebugged =>
106106
107107Future <void > attachDebugger (int dartAppTabId,
108108 {required Trigger trigger}) async {
109- // Check if a debugger is already attached:
110- final existingDebuggerLocation = _debuggerLocation (dartAppTabId);
111- if (existingDebuggerLocation != null ) {
112- return _showWarningNotification (
113- 'Already debugging in ${existingDebuggerLocation .displayName }.' ,
114- );
115- }
116- // Determine if there are multiple apps in the tab:
117- final multipleApps = await fetchStorageObject <String >(
118- type: StorageObject .multipleAppsDetected,
119- tabId: dartAppTabId,
120- );
121- if (multipleApps != null ) {
122- return _showWarningNotification (
123- 'Dart debugging is not supported in a multi-app environment.' ,
124- );
125- }
126- // Verify that the user is authenticated:
127- final isAuthenticated = await _authenticateUser (dartAppTabId);
128- if (! isAuthenticated) return ;
109+ // Validate that the tab can be debugged:
110+ final tabIsDebuggable = await _validateTabIsDebuggable (dartAppTabId);
111+ if (! tabIsDebuggable) return ;
129112
130113 _tabIdToTrigger[dartAppTabId] = trigger;
131114 _registerDebugEventListeners ();
@@ -177,6 +160,40 @@ Future<void> clearStaleDebugSession(int tabId) async {
177160 }
178161}
179162
163+ Future <bool > _validateTabIsDebuggable (int dartAppTabId) async {
164+ // Check if a debugger is already attached:
165+ final existingDebuggerLocation = _debuggerLocation (dartAppTabId);
166+ if (existingDebuggerLocation != null ) {
167+ await _showWarningNotification (
168+ 'Already debugging in ${existingDebuggerLocation .displayName }.' ,
169+ );
170+ return false ;
171+ }
172+ // Determine if this is a Dart app:
173+ final debugInfo = await fetchStorageObject <DebugInfo >(
174+ type: StorageObject .debugInfo,
175+ tabId: dartAppTabId,
176+ );
177+ if (debugInfo == null ) {
178+ await _showWarningNotification ('Not a Dart app.' );
179+ return false ;
180+ }
181+ // Determine if there are multiple apps in the tab:
182+ final multipleApps = await fetchStorageObject <String >(
183+ type: StorageObject .multipleAppsDetected,
184+ tabId: dartAppTabId,
185+ );
186+ if (multipleApps != null ) {
187+ await _showWarningNotification (
188+ 'Dart debugging is not supported in a multi-app environment.' ,
189+ );
190+ return false ;
191+ }
192+ // Verify that the user is authenticated:
193+ final isAuthenticated = await _authenticateUser (dartAppTabId);
194+ return isAuthenticated;
195+ }
196+
180197void _registerDebugEventListeners () {
181198 chrome.debugger.onEvent.addListener (allowInterop (_onDebuggerEvent));
182199 chrome.debugger.onDetach.addListener (allowInterop ((source, _) async {
@@ -548,7 +565,7 @@ Future<bool> _authenticateUser(int tabId) async {
548565 );
549566 final authUrl = debugInfo? .authUrl;
550567 if (authUrl == null ) {
551- _showWarningNotification ('Cannot authenticate user.' );
568+ await _showWarningNotification ('Cannot authenticate user.' );
552569 return false ;
553570 }
554571 final isAuthenticated = await _sendAuthRequest (authUrl);
@@ -582,7 +599,8 @@ Future<bool> _sendAuthRequest(String authUrl) async {
582599 return responseBody.contains ('Dart Debug Authentication Success!' );
583600}
584601
585- void _showWarningNotification (String message) {
602+ Future <bool > _showWarningNotification (String message) {
603+ final completer = Completer <bool >();
586604 chrome.notifications.create (
587605 /*notificationId*/ null ,
588606 NotificationOptions (
@@ -591,8 +609,11 @@ void _showWarningNotification(String message) {
591609 iconUrl: 'static_assets/dart.png' ,
592610 type: 'basic' ,
593611 ),
594- /*callback*/ null ,
612+ allowInterop ((_) {
613+ completer.complete (true );
614+ }),
595615 );
616+ return completer.future;
596617}
597618
598619DebuggerLocation ? _debuggerLocation (int dartAppTabId) {
0 commit comments