Skip to content

Commit 824f54d

Browse files
committed
feat(vue2): scan apps button
1 parent 9022113 commit 824f54d

File tree

7 files changed

+45
-11
lines changed

7 files changed

+45
-11
lines changed

packages/app-backend-core/src/app.ts

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -226,20 +226,25 @@ export async function removeApp (app: App, ctx: BackendContext) {
226226
}
227227
}
228228

229+
let scanTimeout: any
230+
229231
// eslint-disable-next-line camelcase
230-
export function _legacy_getAndRegisterApps (ctx: BackendContext) {
232+
export function _legacy_getAndRegisterApps (ctx: BackendContext, clear = false) {
231233
setTimeout(() => {
232-
// Remove apps that are legacy
233-
ctx.appRecords.forEach(appRecord => {
234-
if (appRecord.meta.Vue) {
235-
removeAppRecord(appRecord, ctx)
236-
}
237-
})
234+
if (clear) {
235+
// Remove apps that are legacy
236+
ctx.appRecords.forEach(appRecord => {
237+
if (appRecord.meta.Vue) {
238+
removeAppRecord(appRecord, ctx)
239+
}
240+
})
241+
}
238242

239243
const apps = scan()
240244

245+
clearTimeout(scanTimeout)
241246
if (!apps.length) {
242-
setTimeout(() => _legacy_getAndRegisterApps(ctx), 1000)
247+
scanTimeout = setTimeout(() => _legacy_getAndRegisterApps(ctx), 1000)
243248
}
244249

245250
apps.forEach(app => {

packages/app-backend-core/src/index.ts

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,12 +59,15 @@ export async function initBackend (bridge: Bridge) {
5959
hook,
6060
})
6161

62+
SharedData.legacyApps = false
6263
if (hook.Vue) {
6364
connect()
64-
_legacy_getAndRegisterApps(ctx)
65+
_legacy_getAndRegisterApps(ctx, true)
66+
SharedData.legacyApps = true
6567
}
6668
hook.on(HookEvents.INIT, () => {
67-
_legacy_getAndRegisterApps(ctx)
69+
_legacy_getAndRegisterApps(ctx, true)
70+
SharedData.legacyApps = true
6871
})
6972

7073
hook.on(HookEvents.APP_ADD, async app => {
@@ -356,6 +359,12 @@ function connectBridge () {
356359
}
357360
})
358361

362+
ctx.bridge.on(BridgeEvents.TO_BACK_SCAN_LEGACY_APPS, () => {
363+
if (hook.Vue) {
364+
_legacy_getAndRegisterApps(ctx)
365+
}
366+
})
367+
359368
// Components
360369

361370
ctx.bridge.on(BridgeEvents.TO_BACK_COMPONENT_TREE, ({ instanceId, filter }) => {

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,10 @@ export function waitForAppSelect (): Promise<void> {
8585
}
8686
}
8787

88+
export function scanLegacyApps () {
89+
getBridge().send(BridgeEvents.TO_BACK_SCAN_LEGACY_APPS, {})
90+
}
91+
8892
export function setupAppsBridgeEvents (bridge: Bridge) {
8993
bridge.on(BridgeEvents.TO_FRONT_APP_ADD, ({ appRecord }) => {
9094
addApp(appRecord)

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,8 @@ export default defineComponent({
197197
@mouseleave="queueClose()"
198198
@wheel="onMouseWheel"
199199
>
200+
<slot name="before" />
201+
200202
<VueDropdownButton
201203
v-for="(item, index) of items"
202204
:key="index"

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

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import AppSelectItem from './AppSelectItem.vue'
44
55
import { watch, defineComponent, computed } from '@vue/composition-api'
66
import { BridgeEvents, SharedData } from '@vue-devtools/shared-utils'
7-
import { useApps, pendingSelectAppId } from '@front/features/apps'
7+
import { useApps, pendingSelectAppId, scanLegacyApps } from '@front/features/apps'
88
import { useOrientation } from '@front/features/layout/orientation'
99
import { useRouter } from '@front/util/router'
1010
import { useBridge } from '../bridge'
@@ -72,6 +72,7 @@ export default defineComponent({
7272
selectApp,
7373
orientation,
7474
hasNewVueVersion,
75+
scanLegacyApps,
7576
}
7677
},
7778
})
@@ -119,6 +120,17 @@ export default defineComponent({
119120
:app="item"
120121
/>
121122
</template>
123+
124+
<template #before>
125+
<VueButton
126+
v-if="$shared.legacyApps"
127+
class="flat m-1"
128+
icon-left="cached"
129+
@click="scanLegacyApps()"
130+
>
131+
Scan apps
132+
</VueButton>
133+
</template>
122134
</AppHeaderSelect>
123135
</template>
124136

packages/shared-utils/src/consts.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ export enum BridgeEvents {
2828
TO_FRONT_APP_REMOVE = 'f:app:remove',
2929
TO_BACK_APP_SELECT = 'b:app:select',
3030
TO_FRONT_APP_SELECTED = 'f:app:selected',
31+
TO_BACK_SCAN_LEGACY_APPS = 'b:app:scan-legacy',
3132

3233
// Components
3334
TO_BACK_COMPONENT_TREE = 'b:component:tree',

packages/shared-utils/src/shared-data.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ const internalSharedData = {
2727
pluginPermissions: {} as any,
2828
pluginSettings: {} as any,
2929
pageConfig: {} as any,
30+
legacyApps: false,
3031
debugInfo: false,
3132
}
3233

0 commit comments

Comments
 (0)