Skip to content

Commit c0a9d6e

Browse files
committed
fix: wait for app selected
1 parent f2da262 commit c0a9d6e

File tree

4 files changed

+38
-8
lines changed

4 files changed

+38
-8
lines changed

packages/app-frontend/src/features/apps/index.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,20 @@ function fetchApps () {
7171
getBridge().send(BridgeEvents.TO_BACK_APP_LIST, {})
7272
}
7373

74+
export const pendingSelectAppId = ref<string>(null)
75+
76+
const pendingSelectPromises: (() => void)[] = []
77+
78+
export function waitForAppSelect (): Promise<void> {
79+
if (!pendingSelectAppId.value) {
80+
return Promise.resolve()
81+
} else {
82+
return new Promise(resolve => {
83+
pendingSelectPromises.push(resolve)
84+
})
85+
}
86+
}
87+
7488
export function setupAppsBridgeEvents (bridge: Bridge) {
7589
bridge.on(BridgeEvents.TO_FRONT_APP_ADD, ({ appRecord }) => {
7690
addApp(appRecord)
@@ -85,5 +99,14 @@ export function setupAppsBridgeEvents (bridge: Bridge) {
8599
apps.value = list
86100
})
87101

102+
bridge.on(BridgeEvents.TO_FRONT_APP_SELECTED, ({ id }) => {
103+
if (pendingSelectAppId.value === id) {
104+
pendingSelectAppId.value = null
105+
for (const resolve of pendingSelectPromises) {
106+
resolve()
107+
}
108+
}
109+
})
110+
88111
fetchApps()
89112
}

packages/app-frontend/src/features/components/composable/components.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import {
1111
openInEditor
1212
} from '@vue-devtools/shared-utils'
1313
import { getBridge, useBridge } from '@front/features/bridge'
14-
import { AppRecord } from '@front/features/apps'
14+
import { AppRecord, waitForAppSelect } from '@front/features/apps'
1515
import { useRoute, useRouter } from '@front/util/router'
1616

1717
export const rootInstances = ref<ComponentTreeNode[]>([])
@@ -95,7 +95,8 @@ export function useComponents () {
9595
deep: true
9696
})
9797

98-
onBridge(BridgeEvents.TO_FRONT_APP_SELECTED, ({ id }) => {
98+
onBridge(BridgeEvents.TO_FRONT_APP_SELECTED, async ({ id }) => {
99+
await waitForAppSelect()
99100
requestComponentTree()
100101
selectedComponentData.value = null
101102
if (lastSelectedApp !== null) {
@@ -255,7 +256,7 @@ export function resetComponents () {
255256

256257
export const requestedComponentTree = new Set()
257258

258-
export function requestComponentTree (instanceId: ComponentTreeNode['id'] = null) {
259+
export async function requestComponentTree (instanceId: ComponentTreeNode['id'] = null) {
259260
if (!instanceId) {
260261
instanceId = '_root'
261262
}
@@ -268,6 +269,7 @@ export function requestComponentTree (instanceId: ComponentTreeNode['id'] = null
268269
if (instanceId === '_root') {
269270
resetComponentsQueued.value = true
270271
}
272+
await waitForAppSelect()
271273
getBridge().send(BridgeEvents.TO_BACK_COMPONENT_TREE, {
272274
instanceId,
273275
filter: treeFilter.value
@@ -305,10 +307,11 @@ export function addToComponentsMap (instance: ComponentTreeNode) {
305307
}
306308
}
307309

308-
export function loadComponent (id: ComponentTreeNode['id']) {
310+
export async function loadComponent (id: ComponentTreeNode['id']) {
309311
if (!id || selectedComponentPendingId.value === id) return
310312
lastSelectedComponentId = id
311313
selectedComponentPendingId.value = id
314+
await waitForAppSelect()
312315
getBridge().send(BridgeEvents.TO_BACK_COMPONENT_SELECTED_DATA, id)
313316
}
314317

packages/app-frontend/src/features/header/AppSelect.vue

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import AppHeaderSelect from './AppHeaderSelect.vue'
44
import { watch, defineComponent } from '@vue/composition-api'
55
import { BridgeEvents } from '@vue-devtools/shared-utils'
66
import SharedData from '@vue-devtools/shared-utils/lib/shared-data'
7-
import { useApps } from '@front/features/apps'
7+
import { useApps, pendingSelectAppId } from '@front/features/apps'
88
import { useOrientation } from '@front/features/layout/orientation'
99
import { useRouter } from '@front/util/router'
1010
import { useBridge } from '../bridge'
@@ -26,7 +26,10 @@ export default defineComponent({
2626
} = useApps()
2727
2828
watch(currentAppId, value => {
29-
bridge.send(BridgeEvents.TO_BACK_APP_SELECT, value)
29+
if (pendingSelectAppId.value !== value) {
30+
pendingSelectAppId.value = value
31+
bridge.send(BridgeEvents.TO_BACK_APP_SELECT, value)
32+
}
3033
}, {
3134
immediate: true
3235
})

packages/app-frontend/src/features/timeline/composable/layers.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import Vue from 'vue'
22
import { computed } from '@vue/composition-api'
33
import { BridgeEvents, setStorage } from '@vue-devtools/shared-utils'
4-
import { useApps } from '@front/features/apps'
4+
import { useApps, waitForAppSelect } from '@front/features/apps'
55
import { getBridge } from '@front/features/bridge'
66
import {
77
layersPerApp,
@@ -110,6 +110,7 @@ export function useLayers () {
110110
}
111111
}
112112

113-
export function fetchLayers () {
113+
export async function fetchLayers () {
114+
await waitForAppSelect()
114115
getBridge().send(BridgeEvents.TO_BACK_TIMELINE_LAYER_LIST, {})
115116
}

0 commit comments

Comments
 (0)