@@ -215,21 +215,54 @@ onUnmounted(() => {
215
215
rpc .functions .off (DevToolsMessagingEvents .INSPECTOR_TREE_UPDATED , onInspectorTreeUpdated )
216
216
})
217
217
218
- function inspectComponentInspector() {
218
+ // #region toggle app
219
+ const devtoolsState = useDevToolsState ()
220
+ const appRecords = computed (() => devtoolsState .appRecords .value .map (app => ({
221
+ label: app .name + (app .version ? ` (${app .version }) ` : ' ' ),
222
+ value: app .id ,
223
+ })))
224
+
225
+ const normalizedAppRecords = computed (() => appRecords .value .map (app => ({
226
+ label: app .label ,
227
+ id: app .value ,
228
+ })))
229
+
230
+ const activeAppRecordId = ref (devtoolsState .activeAppRecordId .value )
231
+ watchEffect (() => {
232
+ activeAppRecordId .value = devtoolsState .activeAppRecordId .value
233
+ })
234
+
235
+ async function toggleApp(id : string , options : { inspectingComponent? : boolean } = {}) {
236
+ await rpc .value .toggleApp (id , options )
237
+ activeComponentId .value = ' '
238
+ await getComponentsInspectorTree ()
239
+ }
240
+ // #endregion
241
+
242
+ async function inspectComponentInspector() {
219
243
inspectComponentTipVisible .value = true
220
244
emit (' onInspectComponentStart' )
221
- rpc .value .inspectComponentInspector ().then ((_data ) => {
222
- const data = JSON .parse (_data ! as unknown as string )
245
+
246
+ try {
247
+ const data = JSON .parse (await rpc .value .inspectComponentInspector ())
248
+
249
+ const appId = data .id .split (' :' )[0 ]
250
+ if (activeAppRecordId .value !== data .appId ) {
251
+ await toggleApp (appId , { inspectingComponent: true })
252
+ }
253
+
223
254
activeComponentId .value = data .id
224
- if (! expandedTreeNodes .value .includes (data .id ))
255
+ if (! expandedTreeNodes .value .includes (data .id )) {
225
256
expandedTreeNodes .value .push (data .id )
257
+ }
226
258
227
259
expandedTreeNodes .value = [... new Set ([... expandedTreeNodes .value , ... getTargetLinkedNodes (treeNodeLinkedList .value , data .id )])]
228
260
scrollToActiveTreeNode ()
229
- }).finally (() => {
261
+ }
262
+ finally {
230
263
inspectComponentTipVisible .value = false
231
264
emit (' onInspectComponentEnd' )
232
- })
265
+ }
233
266
}
234
267
235
268
function cancelInspectComponentInspector() {
@@ -280,32 +313,6 @@ function closeComponentRenderCode() {
280
313
componentRenderCode .value = ' '
281
314
componentRenderCodeVisible .value = false
282
315
}
283
-
284
- // #region toggle app
285
- const devtoolsState = useDevToolsState ()
286
- const appRecords = computed (() => devtoolsState .appRecords .value .map (app => ({
287
- label: app .name + (app .version ? ` (${app .version }) ` : ' ' ),
288
- value: app .id ,
289
- })))
290
-
291
- const normalizedAppRecords = computed (() => appRecords .value .map (app => ({
292
- label: app .label ,
293
- id: app .value ,
294
- })))
295
-
296
- const activeAppRecordId = ref (devtoolsState .activeAppRecordId .value )
297
- watchEffect (() => {
298
- activeAppRecordId .value = devtoolsState .activeAppRecordId .value
299
- })
300
-
301
- function toggleApp(id : string ) {
302
- rpc .value .toggleApp (id ).then (() => {
303
- activeComponentId .value = ' '
304
- getComponentsInspectorTree ()
305
- })
306
- }
307
-
308
- // #endregion
309
316
</script >
310
317
311
318
<template >
0 commit comments