@@ -215,21 +215,54 @@ onUnmounted(() => {
215215 rpc .functions .off (DevToolsMessagingEvents .INSPECTOR_TREE_UPDATED , onInspectorTreeUpdated )
216216})
217217
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() {
219243 inspectComponentTipVisible .value = true
220244 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+
223254 activeComponentId .value = data .id
224- if (! expandedTreeNodes .value .includes (data .id ))
255+ if (! expandedTreeNodes .value .includes (data .id )) {
225256 expandedTreeNodes .value .push (data .id )
257+ }
226258
227259 expandedTreeNodes .value = [... new Set ([... expandedTreeNodes .value , ... getTargetLinkedNodes (treeNodeLinkedList .value , data .id )])]
228260 scrollToActiveTreeNode ()
229- }).finally (() => {
261+ }
262+ finally {
230263 inspectComponentTipVisible .value = false
231264 emit (' onInspectComponentEnd' )
232- })
265+ }
233266}
234267
235268function cancelInspectComponentInspector() {
@@ -280,32 +313,6 @@ function closeComponentRenderCode() {
280313 componentRenderCode .value = ' '
281314 componentRenderCodeVisible .value = false
282315}
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
309316 </script >
310317
311318<template >
0 commit comments