@@ -106,26 +106,9 @@ int? get latestAppBeingDebugged =>
106
106
107
107
Future <void > attachDebugger (int dartAppTabId,
108
108
{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 ;
129
112
130
113
_tabIdToTrigger[dartAppTabId] = trigger;
131
114
_registerDebugEventListeners ();
@@ -177,6 +160,40 @@ Future<void> clearStaleDebugSession(int tabId) async {
177
160
}
178
161
}
179
162
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
+
180
197
void _registerDebugEventListeners () {
181
198
chrome.debugger.onEvent.addListener (allowInterop (_onDebuggerEvent));
182
199
chrome.debugger.onDetach.addListener (allowInterop ((source, _) async {
@@ -548,7 +565,7 @@ Future<bool> _authenticateUser(int tabId) async {
548
565
);
549
566
final authUrl = debugInfo? .authUrl;
550
567
if (authUrl == null ) {
551
- _showWarningNotification ('Cannot authenticate user.' );
568
+ await _showWarningNotification ('Cannot authenticate user.' );
552
569
return false ;
553
570
}
554
571
final isAuthenticated = await _sendAuthRequest (authUrl);
@@ -582,7 +599,8 @@ Future<bool> _sendAuthRequest(String authUrl) async {
582
599
return responseBody.contains ('Dart Debug Authentication Success!' );
583
600
}
584
601
585
- void _showWarningNotification (String message) {
602
+ Future <bool > _showWarningNotification (String message) {
603
+ final completer = Completer <bool >();
586
604
chrome.notifications.create (
587
605
/*notificationId*/ null ,
588
606
NotificationOptions (
@@ -591,8 +609,11 @@ void _showWarningNotification(String message) {
591
609
iconUrl: 'static_assets/dart.png' ,
592
610
type: 'basic' ,
593
611
),
594
- /*callback*/ null ,
612
+ allowInterop ((_) {
613
+ completer.complete (true );
614
+ }),
595
615
);
616
+ return completer.future;
596
617
}
597
618
598
619
DebuggerLocation ? _debuggerLocation (int dartAppTabId) {
0 commit comments