|
1 | 1 | import type { DevframeClientCommand, DevframeDockEntry, DevframeDockPanelState, DevframeDockUserEntry, DevframeRpcClientFunctions, DevframeViewIframe } from '@devframes/hub' |
2 | | -import type { CommandsContext, DevframeClientContext, DevframeRpcClient, DockClientScriptContext, DockEntryState, DockPanelStorage, DockRegistration, DockRendererManifest, DocksContext, DockSessionStorage } from '@devframes/hub/client' |
| 2 | +import type { CommandsContext, DevframeClientContext, DevframeRpcClient, DockClientScriptContext, DockEntryState, DockPanelStorage, DockRegistration, DockRendererManifest, DocksContext, DockSessionStorage, DocksPanelEvents } from '@devframes/hub/client' |
3 | 3 | import type { SharedState } from 'devframe/utils/shared-state' |
4 | 4 | import type { WhenContext } from 'devframe/utils/when' |
5 | 5 | import type { Ref } from 'vue' |
6 | 6 | import type { DevframeDocksUserSettings } from './dock-settings' |
7 | | -import { attachFrameNavClient, createDockRenderersContext, reportDockPanelState } from '@devframes/hub/client' |
| 7 | +import { attachFrameNavClient, createDockRenderersContext } from '@devframes/hub/client' |
8 | 8 | import { DEFAULT_STATE_USER_SETTINGS, DOCK_RENDERERS_STATE_KEY, HUB_EVENTS } from '@devframes/hub/constants' |
9 | 9 | import { DEVFRAME_EVENTS } from 'devframe/constants' |
| 10 | +import { createEventEmitter } from 'devframe/utils/events' |
10 | 11 | import { computed, markRaw, reactive, ref, toRefs, watch, watchEffect } from 'vue' |
11 | 12 | import { BUILTIN_ENTRIES, BUILTIN_ENTRY_SETTINGS, DEFAULT_CATEGORIES_ORDER, HUB_UI_HIDE_EVENT } from '../constants' |
12 | 13 | import { useBranding } from './branding' |
@@ -193,6 +194,7 @@ export async function createDocksContext( |
193 | 194 | } |
194 | 195 |
|
195 | 196 | panelStore ||= ref(DEFAULT_DOCK_PANEL_STORE()) |
| 197 | + const panelEvents = createEventEmitter<DocksPanelEvents>() |
196 | 198 | let docksContext: DocksContext |
197 | 199 |
|
198 | 200 | let _settingsStorePromise: Promise<SharedState<DevframeDocksUserSettings>> | undefined |
@@ -598,6 +600,14 @@ export async function createDocksContext( |
598 | 600 |
|
599 | 601 | docksContext = reactive({ |
600 | 602 | panel: { |
| 603 | + get state() { |
| 604 | + return createDockPanelState( |
| 605 | + panelVisible.value !== false, |
| 606 | + sessionStore.value.open, |
| 607 | + selectedDockId.value, |
| 608 | + ) |
| 609 | + }, |
| 610 | + events: markRaw(panelEvents), |
601 | 611 | store: panelStore, |
602 | 612 | session: sessionStore, |
603 | 613 | isDragging: false, |
@@ -692,20 +702,26 @@ export async function createDocksContext( |
692 | 702 | initialRestorePending.value = false |
693 | 703 | await switchEntry(restoreDockId) |
694 | 704 | } |
695 | | - const reportPanelStateAfterInitialization = async (): Promise<void> => { |
696 | | - await restoreAfterInitialization() |
| 705 | + const startPanelStateEvents = (): void => { |
| 706 | + let previousPanelState = docksContext.panel.state |
697 | 707 | watch( |
698 | 708 | [panelVisible, () => sessionStore.value.open, selectedDockId], |
699 | | - ([visible, open, currentSelectedDockId]) => { |
700 | | - if (visible === undefined) |
| 709 | + () => { |
| 710 | + const panelState = docksContext.panel.state |
| 711 | + if ( |
| 712 | + panelState.state === previousPanelState.state |
| 713 | + && panelState.selectedDockId === previousPanelState.selectedDockId |
| 714 | + ) { |
701 | 715 | return |
702 | | - const panelState = createDockPanelState(visible, open, currentSelectedDockId) |
703 | | - void reportDockPanelState(rpc, panelState).catch(() => {}) |
| 716 | + } |
| 717 | + |
| 718 | + previousPanelState = panelState |
| 719 | + panelEvents.emit(HUB_EVENTS.client.docksPanelStateChanged, panelState) |
704 | 720 | }, |
705 | | - { immediate: true }, |
| 721 | + { flush: 'post' }, |
706 | 722 | ) |
707 | 723 | } |
708 | | - void reportPanelStateAfterInitialization() |
| 724 | + void restoreAfterInitialization().then(startPanelStateEvents, startPanelStateEvents) |
709 | 725 |
|
710 | 726 | docksContextByRpc.set(rpc, docksContext) |
711 | 727 | return docksContext |
|
0 commit comments