diff --git a/apps/desktop/src/App.vue b/apps/desktop/src/App.vue index cf7a19a927..7c7e62992f 100644 --- a/apps/desktop/src/App.vue +++ b/apps/desktop/src/App.vue @@ -188,6 +188,7 @@ import { useBackgroundImage } from "@/composables/useBackgroundImage"; import ExternalSqlFileChangeDialog from "@/components/editor/ExternalSqlFileChangeDialog.vue"; import { resolveWindowContext } from "@/lib/app/windowContext"; import { openDetachedTabWindow } from "@/lib/app/detachedTabWindow"; +import { FLOATING_OPEN_FILESYSTEM_EVENT, FLOATING_OPEN_WORKBENCH_EVENT, type FloatingOpenFilesystemPayload, type FloatingOpenWorkbenchPayload } from "@/lib/plugins/pluginFloatingWindow"; import { OPEN_PLUGIN_AI_CONVERSATION, type AiPluginConversationRequest } from "@/lib/ai/aiPluginConversation"; import type { PluginAiRecommendationHostUpdate } from "@/lib/plugins/pluginHostBridge"; @@ -539,6 +540,7 @@ const pluginWorkbenchTabRefs = new Map(); const tabNavigationHistory = ref(createTabNavigationHistory()); let pendingTabHistoryNavigationId: string | null = null; let detachedEventUnlisteners: Array<() => void> = []; +let floatingEventUnlisteners: Array<() => void> = []; let detachedCloseInProgress = false; const detachedDropTargetTabId = ref(null); const showDetachedClosePrompt = ref(false); @@ -788,6 +790,54 @@ async function setupDetachedWindowEvents() { } } +// A floating plugin window hosts a single widget and has no shell of its own, so +// its shell-bound navigation is forwarded here (emitTo "main"): raise this window +// and open the tab the widget asked for. Payloads are validated field by field — +// they cross a window boundary, and a malformed one must not open a half-titled tab. +async function raiseMainWindow() { + const { getCurrentWindow } = await import("@tauri-apps/api/window"); + const currentWindow = getCurrentWindow(); + await currentWindow.show().catch(() => undefined); + await currentWindow.unminimize().catch(() => undefined); + await currentWindow.setFocus().catch(() => undefined); +} + +async function handleFloatingOpenWorkbench(payload: unknown) { + const data = payload as Partial | null; + if (typeof data?.pluginId !== "string" || typeof data.contributionId !== "string") return; + const context = data.context && typeof data.context === "object" ? data.context : undefined; + await raiseMainWindow(); + queryStore.openPluginWorkbench(data.pluginId, data.contributionId, { + ...(typeof data.title === "string" && data.title ? { title: data.title } : {}), + ...(context ? { context } : {}), + forceNew: data.forceNew === true, + }); +} + +async function handleFloatingOpenFilesystem(payload: unknown) { + const data = payload as Partial | null; + if (typeof data?.pluginId !== "string" || typeof data.providerId !== "string") return; + const context = data.context && typeof data.context === "object" ? data.context : undefined; + await raiseMainWindow(); + queryStore.openPluginFilesystem(data.pluginId, data.providerId, { + ...(typeof data.title === "string" && data.title ? { title: data.title } : {}), + ...(typeof data.rootUri === "string" && data.rootUri ? { rootUri: data.rootUri } : {}), + ...(typeof context?.connectionId === "string" ? { connectionId: context.connectionId } : {}), + ...(typeof context?.uri === "string" ? { currentUri: context.uri } : {}), + }); +} + +async function setupFloatingWindowEvents() { + if (!isDesktop || isDetachedWindowContext) return; + const { listen } = await import("@tauri-apps/api/event"); + floatingEventUnlisteners.push(await listen(FLOATING_OPEN_WORKBENCH_EVENT, (message) => void handleFloatingOpenWorkbench(message.payload))); + floatingEventUnlisteners.push(await listen(FLOATING_OPEN_FILESYSTEM_EVENT, (message) => void handleFloatingOpenFilesystem(message.payload))); + // A floating window whose renderer dies cannot dismiss itself (frameless, and + // nothing inside it runs), so the main window reaps silent ones. + const { startFloatingWindowReaper } = await import("@/lib/plugins/pluginFloatingWindow"); + floatingEventUnlisteners.push(startFloatingWindowReaper()); +} + async function detachTab(tab: QueryTab, position?: { x: number; y: number }) { if (isDetachedWindowContext || !isDetachableTab(tab)) return; try { @@ -4422,6 +4472,7 @@ onMounted(async () => { }); setupCloseActionPromptListener(); void setupDetachedWindowEvents(); + void setupFloatingWindowEvents(); console.log(`[STARTUP] onMounted sync done: ${(performance.now() - mountStart).toFixed(0)}ms`); }); @@ -4432,6 +4483,8 @@ onUnmounted(() => { connectionLivenessUnlisten = null; detachedEventUnlisteners.forEach((unlisten) => unlisten()); detachedEventUnlisteners = []; + floatingEventUnlisteners.forEach((unlisten) => unlisten()); + floatingEventUnlisteners = []; cleanupTauriListeners(); cleanupCloseActionPromptListener(); if (updateCheckTimer) { diff --git a/apps/desktop/src/components/plugins/PluginFloatingWindow.vue b/apps/desktop/src/components/plugins/PluginFloatingWindow.vue new file mode 100644 index 0000000000..4a7780ad16 --- /dev/null +++ b/apps/desktop/src/components/plugins/PluginFloatingWindow.vue @@ -0,0 +1,187 @@ + + + diff --git a/apps/desktop/src/components/plugins/PluginWorkbenchHost.vue b/apps/desktop/src/components/plugins/PluginWorkbenchHost.vue index dfb9feb989..c100dfd9ed 100644 --- a/apps/desktop/src/components/plugins/PluginWorkbenchHost.vue +++ b/apps/desktop/src/components/plugins/PluginWorkbenchHost.vue @@ -19,6 +19,8 @@ import { type PluginAiRecommendationHostUpdate, } from "@/lib/plugins/pluginHostBridge"; import { getCachedPluginUiHtml, getOrLoadPluginUiHtml } from "@/lib/plugins/pluginUiHtmlCache"; +import { beginFloatingWindowDrag, closeFloatingWindows, endFloatingWindowDrag, openFloatingWindow, setFloatingWindowSize } from "@/lib/plugins/pluginFloatingWindow"; +import { isFloatingPluginWindow } from "@/lib/app/windowContext"; import { buildPluginEditorAppearance } from "@/lib/plugins/pluginAppearance"; import { createFrontendPluginRegistry } from "@/lib/plugins/frontendPlugin"; import { executePluginCommand } from "@/lib/plugins/pluginCommandRegistry"; @@ -469,6 +471,19 @@ function onHostFileDrop(event: Event): void { const title = computed(() => `${props.plugin.manifest.name} · ${props.contribution.label}`); +/** + * The §8.3 surface this host renders on. The tab surface keeps a minimum height + * (a workbench needs room to be usable); the dock and floating-window surfaces + * are sized by their own container, where a floor would make the frame taller + * than the visible area and swallow clicks near its bottom edge. The floating + * surface is transparent: the widget paints its own shape. + */ +const surface = computed(() => (typeof props.context?.surface === "string" ? props.context.surface : "tab")); +const hostSurfaceClass = computed(() => (surface.value === "tab" ? "min-h-40 bg-background" : surface.value === "window" ? "min-h-0 bg-transparent" : "min-h-0 bg-background")); +/** The loading overlays must not paint an opaque box inside a transparent floating window. */ +const overlayClass = computed(() => (surface.value === "window" ? "bg-transparent" : "bg-background")); +const isFloatingSurface = isFloatingPluginWindow(); + /** Collect resolved DBX design tokens so the sandbox can theme itself with the same values. */ function currentBridgeTheme(): PluginBridgeTheme { const tokens: Record = {}; @@ -509,8 +524,12 @@ function createBridge() { // the single-plugin registry is equivalent here because findCommand / // findWorkbench / enablement never cross plugins. Panel commands dock, // tab commands open tabs, §4.1 reuse with `instance_key` placeholder - // scoping — identical to menu execution. - executeCommand: (pluginId, commandId, context) => executePluginCommand(createFrontendPluginRegistry([props.plugin], appLocale.value), useQueryStore(), pluginId, commandId, context), + // scoping — identical to menu execution. Not offered on the floating + // surface: every command action opens a shell surface (a dock entry or a + // workbench tab) that a floating widget window does not have, so it would + // resolve successfully and show nothing. There, plugins navigate with + // openWorkbench / floating.open, which the host routes to the main window. + ...(isFloatingSurface ? {} : { executeCommand: (pluginId: string, commandId: string, context?: Record) => executePluginCommand(createFrontendPluginRegistry([props.plugin], appLocale.value), useQueryStore(), pluginId, commandId, context) }), openFilesystem: async (pluginId, providerId, context) => emit("openFilesystem", pluginId, providerId, context), reopenConnection: (pluginId, connectionId) => useConnectionStore().reopenPluginConnection(connectionId, pluginId), // PR-A4 generic extension point: a read-only, secret-free, plugin-scoped connection list (for in-panel connection switching). @@ -541,6 +560,16 @@ function createBridge() { await api.setPluginDataGrant(pluginId, connectionId, true); }, closeTab: () => emit("closeTab"), + // Floating widget windows (§8.3 surface "window"). Desktop-only: the web + // host omits them so capabilities.floating stays false and the plugin can + // fall back to an in-shell surface. Opening and closing work from any + // window; the geometry calls act on the window that hosts the caller and + // reject elsewhere, so a tab can never move a window it is not inside. + openFloatingWindow: isTauriRuntime() ? (request) => openFloatingWindow(request) : undefined, + closeFloatingWindows: isTauriRuntime() ? (labels) => closeFloatingWindows(labels) : undefined, + beginFloatingDrag: isTauriRuntime() ? () => beginFloatingWindowDrag() : undefined, + endFloatingDrag: isTauriRuntime() ? (snap) => endFloatingWindowDrag(snap) : undefined, + setFloatingSize: isTauriRuntime() ? (width, height) => setFloatingWindowSize(width, height) : undefined, saveFile: (_pluginId, request, data) => savePluginFile(request, data), downloadFile: isTauriRuntime() ? downloadPluginFile : undefined, cancelDownload: isTauriRuntime() ? cancelPluginDownload : undefined, @@ -794,8 +823,8 @@ onBeforeUnmount(() => {