@@ -8,13 +8,11 @@ library cider_connection;
8
8
import 'dart:convert' ;
9
9
import 'dart:js_util' ;
10
10
11
- import 'package:dwds/data/debug_info.dart' ;
12
11
import 'package:js/js.dart' ;
13
12
14
13
import 'chrome_api.dart' ;
15
14
import 'debug_session.dart' ;
16
15
import 'logger.dart' ;
17
- import 'storage.dart' ;
18
16
19
17
/// Used to identify messages passed to/from Cider.
20
18
///
@@ -38,12 +36,9 @@ enum CiderMessageType {
38
36
/// The types must match those defined by ChromeExtensionErrorType in the
39
37
/// Cider extension.
40
38
enum CiderErrorType {
41
- chromeError,
42
39
internalError,
43
40
invalidRequest,
44
- multipleDartTabs,
45
- noDartTab,
46
- noWorkspace,
41
+ noAppId,
47
42
}
48
43
49
44
const _ciderPortName = 'cider' ;
@@ -115,36 +110,32 @@ Future<void> _handleMessageFromCider(dynamic message, Port _) async {
115
110
final messageBody = decoded['messageBody' ] as String ? ;
116
111
117
112
if (messageType == CiderMessageType .startDebugRequest.name) {
118
- await _startDebugging (workspaceName : messageBody);
113
+ await _startDebugging (appId : messageBody);
119
114
} else if (messageType == CiderMessageType .stopDebugRequest.name) {
120
- await _stopDebugging (workspaceName : messageBody);
115
+ await _stopDebugging (appId : messageBody);
121
116
}
122
117
}
123
118
124
- Future <void > _startDebugging ({String ? workspaceName }) async {
125
- if (workspaceName == null ) {
126
- _sendNoWorkspaceError ();
119
+ Future <void > _startDebugging ({String ? appId }) async {
120
+ if (appId == null ) {
121
+ _sendNoAppIdError ();
127
122
return ;
128
123
}
129
-
130
- final dartTab = await _findDartTabIdForWorkspace (workspaceName);
131
- if (dartTab != null ) {
132
- // TODO(https://github.com/dart-lang/webdev/issues/2198): When debugging
133
- // with Cider, disable debugging with DevTools.
134
- await attachDebugger (dartTab, trigger: Trigger .cider);
135
- }
124
+ final tabId = _tabId (appId);
125
+ // TODO(https://github.com/dart-lang/webdev/issues/2198): When debugging
126
+ // with Cider, disable debugging with DevTools.
127
+ await attachDebugger (tabId, trigger: Trigger .cider);
136
128
}
137
129
138
- Future <void > _stopDebugging ({String ? workspaceName }) async {
139
- if (workspaceName == null ) {
140
- _sendNoWorkspaceError ();
130
+ Future <void > _stopDebugging ({String ? appId }) async {
131
+ if (appId == null ) {
132
+ _sendNoAppIdError ();
141
133
return ;
142
134
}
135
+ final tabId = _tabId (appId);
143
136
144
- final dartTab = await _findDartTabIdForWorkspace (workspaceName);
145
- if (dartTab == null ) return ;
146
137
final successfullyDetached = await detachDebugger (
147
- dartTab ,
138
+ tabId ,
148
139
type: TabType .dartApp,
149
140
reason: DetachReason .canceledByUser,
150
141
);
@@ -159,48 +150,14 @@ Future<void> _stopDebugging({String? workspaceName}) async {
159
150
}
160
151
}
161
152
162
- void _sendNoWorkspaceError () {
163
- sendErrorMessageToCider (
164
- errorType: CiderErrorType .noWorkspace,
165
- errorDetails: 'Cannot find a debuggable Dart tab without a workspace' ,
166
- );
153
+ int _tabId (String appId) {
154
+ final tabId = appId.split ('-' ).last;
155
+ return int .parse (tabId);
167
156
}
168
157
169
- Future <int ?> _findDartTabIdForWorkspace (String workspaceName) async {
170
- final allTabsInfo = await fetchAllStorageObjectsOfType <DebugInfo >(
171
- type: StorageObject .debugInfo,
158
+ void _sendNoAppIdError () {
159
+ sendErrorMessageToCider (
160
+ errorType: CiderErrorType .noAppId,
161
+ errorDetails: 'Cannot find a debuggable Dart tab without an app ID' ,
172
162
);
173
- final dartTabIds = allTabsInfo
174
- .where (
175
- (debugInfo) => debugInfo.workspaceName == workspaceName,
176
- )
177
- .map (
178
- (info) => info.tabId,
179
- )
180
- .toList ();
181
-
182
- if (dartTabIds.isEmpty) {
183
- sendErrorMessageToCider (
184
- errorType: CiderErrorType .noDartTab,
185
- errorDetails: 'No debuggable Dart tabs found.' ,
186
- );
187
- return null ;
188
- }
189
- if (dartTabIds.length > 1 ) {
190
- sendErrorMessageToCider (
191
- errorType: CiderErrorType .multipleDartTabs,
192
- errorDetails: 'Too many debuggable Dart tabs found.' ,
193
- );
194
- return null ;
195
- }
196
- final tabId = dartTabIds.first;
197
- if (tabId == null ) {
198
- sendErrorMessageToCider (
199
- errorType: CiderErrorType .chromeError,
200
- errorDetails: 'Debuggable Dart tab is null.' ,
201
- );
202
- return null ;
203
- }
204
-
205
- return tabId;
206
163
}
0 commit comments