Skip to content

armgit / dbx

Public Imported from GitHub
0

25 MB lightweight cross-platform database client for 100+ databases, including MySQL, PostgreSQL, SQLite, Redis, MongoDB, DuckDB, SQL Server, and Dameng. Built-in AI, MCP Server, CLI, desktop and Docker. | 轻量级跨平台数据库管理工具,支持 MySQL、PostgreSQL、SQLite、Redis、MongoDB、达梦等 100+ 数据库,提供桌面端、Docker、CLI、内置 AI 助手和 MCP。

fix(plugins): release dock terminal plugin connections on close

Jinpy8c45af6bdd96
diff --git a/apps/desktop/src/components/plugins/PluginWorkbenchHost.vue b/apps/desktop/src/components/plugins/PluginWorkbenchHost.vue
index 58e7a8a34f..33ddc8c67d 100644
--- a/apps/desktop/src/components/plugins/PluginWorkbenchHost.vue
+++ b/apps/desktop/src/components/plugins/PluginWorkbenchHost.vue
@@ -540,6 +540,7 @@ function createBridge() {
listConnections: (ownerPluginId) => {
const providerIds = new Set((props.plugin.manifest.contributions || []).filter((candidate) => candidate.type === "connection-provider").map((candidate) => candidate.id));
if (ownerPluginId !== props.plugin.manifest.id) return [];
+ const queryStore = useQueryStore();
return useConnectionStore()
.connections.filter((connection) => providerIds.has(connection.plugin_connection_provider ?? ""))
.map((connection) => ({
@@ -548,6 +549,8 @@ function createBridge() {
providerId: connection.plugin_connection_provider ?? "",
connectionType: connection.plugin_connection_type,
readOnly: connection.read_only === true,
+ // #193b — dock/tab titles bound to the connection (dock first), so plugins can label session rows after renamed terminals.
+ workbenchTitles: queryStore.pluginWorkbenchTitles(connection.id),
}));
},
// Both plan calls carry the plugin's declared `host.plans:read` gate in the
diff --git a/apps/desktop/src/lib/plugins/pluginConnectionSurfaces.spec.ts b/apps/desktop/src/lib/plugins/pluginConnectionSurfaces.spec.ts
new file mode 100644
index 0000000000..c009f2b93c
--- /dev/null
+++ b/apps/desktop/src/lib/plugins/pluginConnectionSurfaces.spec.ts
@@ -0,0 +1,69 @@
+import { describe, expect, it } from "vitest";
+import { anySurfaceReferencesPluginConnection, dockEntryReferencesPluginConnection, pluginWorkbenchTitlesForConnection, tabReferencesPluginConnection, type PluginConnectionSurfaceDockEntry, type PluginConnectionSurfaceTab } from "./pluginConnectionSurfaces";
+
+const workbenchTab = (overrides: Partial<PluginConnectionSurfaceTab> = {}): PluginConnectionSurfaceTab => ({
+ mode: "plugin-workbench",
+ title: "tab",
+ ...overrides,
+});
+
+const dockEntry = (overrides: Partial<PluginConnectionSurfaceDockEntry> = {}): PluginConnectionSurfaceDockEntry => ({
+ title: "dock",
+ context: { connectionId: "conn-1" },
+ ...overrides,
+});
+
+describe("tabReferencesPluginConnection", () => {
+ it("prefers the top-level connectionId", () => {
+ expect(tabReferencesPluginConnection(workbenchTab({ connectionId: "conn-1" }), "conn-1")).toBe(true);
+ expect(tabReferencesPluginConnection(workbenchTab({ connectionId: "conn-1" }), "conn-2")).toBe(false);
+ });
+
+ it("falls back to the workbench context connectionId", () => {
+ const tab = workbenchTab({ pluginWorkbench: { context: { connectionId: "conn-1" } } });
+ expect(tabReferencesPluginConnection(tab, "conn-1")).toBe(true);
+ expect(tabReferencesPluginConnection(workbenchTab({ pluginWorkbench: { context: {} } }), "conn-1")).toBe(false);
+ expect(tabReferencesPluginConnection(workbenchTab({ pluginWorkbench: { context: { connectionId: 42 } } }), "conn-1")).toBe(false);
+ });
+});
+
+describe("dockEntryReferencesPluginConnection", () => {
+ it("matches string context connectionId and rejects other shapes", () => {
+ expect(dockEntryReferencesPluginConnection(dockEntry(), "conn-1")).toBe(true);
+ expect(dockEntryReferencesPluginConnection(dockEntry({ context: {} }), "conn-1")).toBe(false);
+ expect(dockEntryReferencesPluginConnection(dockEntry({ context: { connectionId: null } }), "conn-1")).toBe(false);
+ // Local-shell dock entries carry no connectionId at all.
+ expect(dockEntryReferencesPluginConnection(dockEntry({ context: { workbenchId: "w1" } }), "conn-1")).toBe(false);
+ });
+});
+
+describe("anySurfaceReferencesPluginConnection (#193a regression lock)", () => {
+ it("keeps the connection alive while a dock terminal still references it", () => {
+ // The exact #193 shape: last tab closed, dock entry survives.
+ expect(anySurfaceReferencesPluginConnection([], [dockEntry()], "conn-1")).toBe(true);
+ });
+
+ it("counts plugin tabs on either surface mode", () => {
+ const tabs = [workbenchTab({ connectionId: "conn-1" }), workbenchTab({ mode: "plugin-filesystem", connectionId: "conn-1" })];
+ expect(anySurfaceReferencesPluginConnection(tabs, [], "conn-1")).toBe(true);
+ });
+
+ it("ignores non-plugin tabs and unreferenced surfaces", () => {
+ const tabs = [workbenchTab({ mode: "database", connectionId: "conn-1" })];
+ expect(anySurfaceReferencesPluginConnection(tabs, [dockEntry({ context: { connectionId: "conn-2" } })], "conn-1")).toBe(false);
+ });
+});
+
+describe("pluginWorkbenchTitlesForConnection (#193b)", () => {
+ it("puts dock entry titles first, then tabs, deduplicated in order", () => {
+ const tabs = [workbenchTab({ title: "prod", connectionId: "conn-1" }), workbenchTab({ title: "other", connectionId: "conn-2" })];
+ const entries = [dockEntry({ title: "prod-db" }), dockEntry({ title: "prod" })];
+ expect(pluginWorkbenchTitlesForConnection(tabs, entries, "conn-1")).toEqual(["prod-db", "prod"]);
+ });
+
+ it("skips titles of surfaces bound to other connections and empty titles", () => {
+ const tabs = [workbenchTab({ title: "", connectionId: "conn-1" })];
+ const entries = [dockEntry({ title: "elsewhere", context: { connectionId: "conn-2" } })];
+ expect(pluginWorkbenchTitlesForConnection(tabs, entries, "conn-1")).toEqual([]);
+ });
+});
diff --git a/apps/desktop/src/lib/plugins/pluginConnectionSurfaces.ts b/apps/desktop/src/lib/plugins/pluginConnectionSurfaces.ts
new file mode 100644
index 0000000000..4665a3928b
--- /dev/null
+++ b/apps/desktop/src/lib/plugins/pluginConnectionSurfaces.ts
@@ -0,0 +1,61 @@
+// #193 — plugin connection surfaces live on more than one host registry.
+// Workbench tabs are tracked in the query store, but bottom-dock terminal
+// entries (VS Code-style terminal panel) live in pluginBottomDock and floating
+// windows would live in Tauri's window registry. The tab-close auto-release in
+// queryStore used to count tabs only, so closing the last tab while a dock
+// terminal still held the connection tore the connection down under it and
+// force-reconnected every surviving dock terminal.
+import type { PluginDockEntry } from "./pluginBottomDock";
+
+/** Structural subset of a query tab the connection-surface scan needs. */
+export interface PluginConnectionSurfaceTab {
+ mode: string;
+ title: string;
+ connectionId?: string;
+ pluginWorkbench?: { context?: Record<string, unknown> } | null;
+}
+
+/** Dock entry / tab shapes accepted here — picks keep the caller's real types compatible. */
+export type PluginConnectionSurfaceDockEntry = Pick<PluginDockEntry, "title" | "context">;
+
+const PLUGIN_SURFACE_TAB_MODES = new Set(["plugin-workbench", "plugin-filesystem"]);
+
+/** Mirrors queryStore's pluginTabConnectionId: top-level connectionId wins, then the workbench context. */
+export function tabReferencesPluginConnection(tab: PluginConnectionSurfaceTab, connectionId: string): boolean {
+ if (tab.connectionId) return tab.connectionId === connectionId;
+ const contextConnectionId = tab.pluginWorkbench?.context?.connectionId;
+ return typeof contextConnectionId === "string" && contextConnectionId === connectionId;
+}
+
+export function dockEntryReferencesPluginConnection(entry: PluginConnectionSurfaceDockEntry, connectionId: string): boolean {
+ const referenced = entry.context.connectionId;
+ return typeof referenced === "string" && referenced === connectionId;
+}
+
+/** True while any surface (tab or dock entry) still references the connection — release must wait. */
+export function anySurfaceReferencesPluginConnection(tabs: ReadonlyArray<PluginConnectionSurfaceTab>, dockEntries: ReadonlyArray<PluginConnectionSurfaceDockEntry>, connectionId: string): boolean {
+ if (tabs.some((tab) => PLUGIN_SURFACE_TAB_MODES.has(tab.mode) && tabReferencesPluginConnection(tab, connectionId))) return true;
+ return dockEntries.some((entry) => dockEntryReferencesPluginConnection(entry, connectionId));
+}
+
+/**
+ * Display titles of plugin surfaces bound to the connection: dock terminal
+ * entries first (the user-renamable terminals a batch-send panel should
+ * follow), then workbench tabs, deduplicated in order.
+ */
+export function pluginWorkbenchTitlesForConnection(tabs: ReadonlyArray<PluginConnectionSurfaceTab>, dockEntries: ReadonlyArray<PluginConnectionSurfaceDockEntry>, connectionId: string): string[] {
+ const titles: string[] = [];
+ const seen = new Set<string>();
+ const push = (title: string) => {
+ if (!title || seen.has(title)) return;
+ seen.add(title);
+ titles.push(title);
+ };
+ for (const entry of dockEntries) {
+ if (dockEntryReferencesPluginConnection(entry, connectionId)) push(entry.title);
+ }
+ for (const tab of tabs) {
+ if (PLUGIN_SURFACE_TAB_MODES.has(tab.mode) && tabReferencesPluginConnection(tab, connectionId)) push(tab.title);
+ }
+ return titles;
+}
diff --git a/apps/desktop/src/lib/plugins/pluginHostBridge.ts b/apps/desktop/src/lib/plugins/pluginHostBridge.ts
index df08ba3cf6..d56ea5ea6e 100644
--- a/apps/desktop/src/lib/plugins/pluginHostBridge.ts
+++ b/apps/desktop/src/lib/plugins/pluginHostBridge.ts
@@ -196,7 +196,7 @@ export interface PluginHostBridgeApi {
* connection-providers, so plugins can implement their own connection switching inside panels/workbenches and
* their own business (the host stays unaware of the purpose).
*/
- listConnections?(pluginId: string): Array<{ id: string; name: string; providerId: string; connectionType?: string; readOnly: boolean }>;
+ listConnections?(pluginId: string): Array<{ id: string; name: string; providerId: string; connectionType?: string; readOnly: boolean; workbenchTitles?: string[] }>;
/**
* Estimated plan capability metadata for one connection. Requires the plugin
* to declare `host.plans:read`. The host only reads the stored connection
diff --git a/apps/desktop/src/stores/queryStore.ts b/apps/desktop/src/stores/queryStore.ts
index 17afeba685..1272cd01f5 100644
--- a/apps/desktop/src/stores/queryStore.ts
+++ b/apps/desktop/src/stores/queryStore.ts
@@ -127,6 +127,8 @@ import { decodeQueryResultArchive, encodeQueryResultArchive, type DecodedQueryRe
import * as api from "@/lib/backend/api";
import { createFrontendPluginRegistry } from "@/lib/plugins/frontendPlugin";
import { snapshotPluginWorkbenchContext } from "@/lib/plugins/pluginData";
+import { usePluginBottomDock } from "@/lib/plugins/pluginBottomDock";
+import { anySurfaceReferencesPluginConnection, pluginWorkbenchTitlesForConnection } from "@/lib/plugins/pluginConnectionSurfaces";
import { useConnectionStore } from "@/stores/connectionStore";
import { useSettingsStore } from "@/stores/settingsStore";
import { useSavedSqlStore } from "@/stores/savedSqlStore";
@@ -4693,6 +4695,16 @@ export const useQueryStore = defineStore("query", () => {
* Fire-and-forget; concurrent releases for the same connection coalesce, and
* a reopen racing the release wins.
*/
+ /**
+ * #193b — display titles of plugin surfaces bound to the connection, exposed
+ * to plugins via host.listConnections(workbenchTitles). Dock terminal
+ * entries come first (the user-renamable terminals a batch-send panel should
+ * follow), then workbench tabs.
+ */
+ function pluginWorkbenchTitles(connectionId: string): string[] {
+ return pluginWorkbenchTitlesForConnection(tabs.value, usePluginBottomDock().entries.value, connectionId);
+ }
+
function releasePluginConnectionsAfterClose(closedTabs: ReadonlyArray<QueryTab>) {
const closedPluginTabsByConnection = new Map<string, Set<string>>();
for (const tab of closedTabs) {
@@ -4713,7 +4725,12 @@ export const useQueryStore = defineStore("query", () => {
// Yield one microtask so a same-tick reopen registers its
// replacement plugin tab before we tear the connection down.
await Promise.resolve();
- if (tabs.value.some((tab) => (tab.mode === "plugin-workbench" || tab.mode === "plugin-filesystem") && pluginTabConnectionId(tab) === connectionId)) return;
+ // #193: dock terminal entries live outside `tabs` — closing the last
+ // tab while a dock terminal still holds the connection must not tear
+ // it down under the surviving terminals. Floating windows (surface
+ // "window", reserved) have no synchronous registry yet and remain a
+ // known blind spot on this path.
+ if (anySurfaceReferencesPluginConnection(tabs.value, usePluginBottomDock().entries.value, connectionId)) return;
const connectionStore = useConnectionStore();
const config = connectionStore.getConfig(connectionId);
// A connection reference is not ownership: only a plugin-backed
@@ -10705,6 +10722,7 @@ export const useQueryStore = defineStore("query", () => {
openMqttAdmin,
openNacosAdmin,
openPluginWorkbench,
+ pluginWorkbenchTitles,
localizePluginTabTitles,
openPluginFilesystem,
reconnectRestoredPluginTabs,