|
1 | 1 | <script setup lang="ts"> |
2 | 2 | import type { DevframeConnectionStatus, DevframeRpcClient } from 'devframe/client' |
3 | | -import type { DevframeMessageEntry } from '../types' |
| 3 | +import type { DevframeMessageAction, DevframeMessageEntry } from '../types' |
4 | 4 | import LayoutToolbar from '@antfu/design/components/Layout/LayoutToolbar.vue' |
5 | | -import { computed, onBeforeUnmount, ref } from 'vue' |
| 5 | +import { computed, onBeforeUnmount, onMounted, ref } from 'vue' |
6 | 6 | import { |
7 | 7 | button, |
8 | 8 | connectionBody, |
@@ -46,6 +46,29 @@ function reload(): void { |
46 | 46 | // an editor with. |
47 | 47 | const canOpenFile = computed(() => props.rpc.connectionMeta.backend !== 'static') |
48 | 48 |
|
| 49 | +// Message actions that navigate to another dock only work under a hub host |
| 50 | +// (the `hub:docks:activate` RPC + `devframe:docks` registry). Probe the docks |
| 51 | +// shared state so the affordance is hidden when there's no hub. |
| 52 | +const canActivate = ref(false) |
| 53 | +onMounted(() => { |
| 54 | + props.rpc.sharedState |
| 55 | + .get('devframe:docks', { initialValue: null }) |
| 56 | + .then((state: { value: () => unknown, on: (e: string, cb: (v: unknown) => void) => void }) => { |
| 57 | + canActivate.value = state.value() != null |
| 58 | + state.on('updated', v => (canActivate.value = v != null)) |
| 59 | + }) |
| 60 | + .catch(() => {}) |
| 61 | +}) |
| 62 | +
|
| 63 | +async function onActivate(action: DevframeMessageAction): Promise<void> { |
| 64 | + if (action.kind !== 'activate') |
| 65 | + return |
| 66 | + await (props.rpc.callOptional as (name: string, ...args: unknown[]) => Promise<unknown>)( |
| 67 | + 'hub:docks:activate', |
| 68 | + action.activate, |
| 69 | + ) |
| 70 | +} |
| 71 | +
|
49 | 72 | async function onDismiss(id: string): Promise<void> { |
50 | 73 | await props.rpc.call('devframes:plugin:messages:remove', id) |
51 | 74 | } |
@@ -124,11 +147,13 @@ async function onOpenFile(entry: DevframeMessageEntry): Promise<void> { |
124 | 147 | v-else |
125 | 148 | :entries="state.entries" |
126 | 149 | :can-open-file="canOpenFile" |
| 150 | + :can-activate="canActivate" |
127 | 151 | @dismiss="onDismiss" |
128 | 152 | @dismiss-many="onDismissMany" |
129 | 153 | @clear="onClear" |
130 | 154 | @persist="onPersist" |
131 | 155 | @open-file="onOpenFile" |
| 156 | + @activate="onActivate" |
132 | 157 | /> |
133 | 158 | </div> |
134 | 159 | </div> |
|
0 commit comments