feat(plugin): add plugin framework workflow

This commit is contained in:
t8y2 authored and GitHub committed 2026-09-13 10:39:17 +08:00
1 parent 3767f4a83b
commit b5072f1a3e
247 files changed
+33841 -2256

No files matched your search

@@ -0,0 +1,47 @@
import { beforeEach, describe, expect, it, vi } from "vitest";
const listeners = new Map<string, (event: { payload: unknown }) => void>();
const unlisten = vi.fn();
vi.mock("@tauri-apps/api/event", () => ({
listen: vi.fn(async (event: string, handler: (event: { payload: unknown }) => void) => {
listeners.set(event, handler);
return unlisten;
}),
}));
vi.mock("@/stores/connectionStore", () => ({
useConnectionStore: () => ({ connections: [], initFromDisk: vi.fn(), getConfig: vi.fn(), ensureConnected: vi.fn() }),
}));
vi.mock("@/stores/queryStore", () => ({
useQueryStore: () => ({ createTab: vi.fn(), showExecutedQueryResults: vi.fn() }),
}));
import { useTauriEvents } from "@/composables/useTauriEvents";
describe("useTauriEvents", () => {
beforeEach(() => {
listeners.clear();
unlisten.mockClear();
});
it("routes the native macOS close-tab menu event to the active surface", async () => {
const closeActiveSurface = vi.fn();
const events = useTauriEvents({
openTableTarget: vi.fn(),
openSqlFilePath: vi.fn(),
openDbFilePath: vi.fn(),
openConnectionDeepLink: vi.fn(),
closeActiveSurface,
});
events.setupTauriListeners();
await vi.waitFor(() => expect(listeners.has("dbx-close-active-tab")).toBe(true));
listeners.get("dbx-close-active-tab")!({ payload: undefined });
expect(closeActiveSurface).toHaveBeenCalledOnce();
events.cleanupTauriListeners();
expect(unlisten).toHaveBeenCalled();
});
});
@@ -9,6 +9,7 @@ export function useTauriEvents(deps: {
openDbFilePath: (path: string) => Promise<void>;
openConnectionDeepLink: (url: string) => Promise<void>;
openAiConfigDeepLink: (url: string) => Promise<void>;
closeActiveSurface: () => void;
}) {
const connectionStore = useConnectionStore();
const queryStore = useQueryStore();
@@ -116,6 +117,10 @@ export function useTauriEvents(deps: {
console.error("[DBX] dbx-open-ai-config-links error:", e);
}
}).then((unlisten) => unlistenHandles.push(unlisten));
listen("dbx-close-active-tab", () => {
deps.closeActiveSurface();
}).then((unlisten) => unlistenHandles.push(unlisten));
})
.catch(() => {});
}