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(updater): allow relaunch and draft flush during preparation

t8y22ca99a540b3c
diff --git a/apps/desktop/src/lib/app/__tests__/updatePreparation.spec.ts b/apps/desktop/src/lib/app/__tests__/updatePreparation.spec.ts
index ece334c434..9ffeb8cbec 100644
--- a/apps/desktop/src/lib/app/__tests__/updatePreparation.spec.ts
+++ b/apps/desktop/src/lib/app/__tests__/updatePreparation.spec.ts
@@ -83,6 +83,13 @@ describe("update restart preparation", () => {
expect(() => assertUpdateAllowsCommand("unknown_future_mutation")).toThrow();
expect(() => assertUpdateAllowsCommand("save_open_tabs_state")).not.toThrow();
expect(() => assertUpdateAllowsCommand("install_downloaded_update")).not.toThrow();
+ // Restart happens after preparation succeeds while the barrier is still up.
+ expect(() => assertUpdateAllowsCommand("relaunch_app")).not.toThrow();
+ // The preparation persist() pass must be able to flush durable drafts.
+ expect(() => assertUpdateAllowsCommand("save_default_query_content")).not.toThrow();
+ expect(() => assertUpdateAllowsCommand("save_saved_sql_editor_positions")).not.toThrow();
+ expect(() => assertUpdateAllowsCommand("sync_saved_sql_directory")).not.toThrow();
+ expect(() => assertUpdateAllowsCommand("load_saved_sql_files_for_sync")).not.toThrow();
const event = new Event("beforeinput", { cancelable: true });
window.dispatchEvent(event);
expect(event.defaultPrevented).toBe(true);
diff --git a/apps/desktop/src/lib/app/updatePreparation.ts b/apps/desktop/src/lib/app/updatePreparation.ts
index bf8e787336..4999765ccf 100644
--- a/apps/desktop/src/lib/app/updatePreparation.ts
+++ b/apps/desktop/src/lib/app/updatePreparation.ts
@@ -29,11 +29,31 @@ export function assertUpdateSafe(): void {
}
}
+// While the barrier is up the installer/relauncher may kill the process, so only
+// the updater handoff and the durable-draft writes issued by the preparation
+// persist() callback are allowed. Everything else is rejected fail-closed.
+const PREPARATION_ALLOWED_COMMANDS = new Set([
+ "save_open_tabs_state",
+ "save_detached_tab_handoff",
+ "load_detached_tab_handoff",
+ "save_tab_result_snapshot",
+ // Draft flush: default-query content, its optional directory mirror, and the
+ // saved-SQL editor positions queued by the same persist pass.
+ "save_default_query_content",
+ "save_saved_sql_editor_positions",
+ "sync_saved_sql_directory",
+ "load_saved_sql_files_for_sync",
+ "get_downloaded_update",
+ "install_downloaded_update",
+ "discard_downloaded_update",
+ // The macOS/Linux restart is a frontend command invoked after preparation
+ // succeeds, while the barrier is intentionally still held.
+ "relaunch_app",
+]);
+
export function assertUpdateAllowsCommand(command: string): void {
if (!barrierDepth) return;
- // During the short install barrier only updater and durable-draft I/O are allowed.
- const allowed = new Set(["save_open_tabs_state", "save_detached_tab_handoff", "load_detached_tab_handoff", "save_tab_result_snapshot", "get_downloaded_update", "install_downloaded_update", "discard_downloaded_update"]);
- if (!allowed.has(command)) throw new Error("Update preparation is in progress. Please wait.");
+ if (!PREPARATION_ALLOWED_COMMANDS.has(command)) throw new Error("Update preparation is in progress. Please wait.");
}
export function isUpdatePreparationActive(): boolean {
diff --git a/apps/desktop/src/lib/backend/__tests__/updatePreparationBarrier.spec.ts b/apps/desktop/src/lib/backend/__tests__/updatePreparationBarrier.spec.ts
new file mode 100644
index 0000000000..b6035d6702
--- /dev/null
+++ b/apps/desktop/src/lib/backend/__tests__/updatePreparationBarrier.spec.ts
@@ -0,0 +1,46 @@
+import { beforeEach, describe, expect, it, vi } from "vitest";
+
+const mocks = vi.hoisted(() => ({
+ invoke: vi.fn(),
+}));
+
+vi.mock("@tauri-apps/api/core", () => ({
+ invoke: mocks.invoke,
+}));
+
+vi.mock("@tauri-apps/api/event", () => ({
+ listen: vi.fn(),
+}));
+
+describe("update preparation command barrier", () => {
+ beforeEach(() => {
+ vi.resetModules();
+ mocks.invoke.mockReset();
+ mocks.invoke.mockResolvedValue(undefined);
+ });
+
+ it("lets the macOS/Linux restart reach Tauri while the barrier is held", async () => {
+ const { relaunchApp } = await import("@/lib/backend/tauri");
+ const { acquireUpdateBarrier } = await import("@/lib/app/updatePreparation");
+ // prepare() succeeded and deliberately keeps every window frozen until exit.
+ const release = acquireUpdateBarrier();
+ try {
+ await expect(relaunchApp()).resolves.toBeUndefined();
+ expect(mocks.invoke).toHaveBeenCalledWith("relaunch_app", undefined);
+ } finally {
+ release();
+ }
+ });
+
+ it("still rejects non-durable commands while the barrier is held", async () => {
+ const { loadOpenTabsState } = await import("@/lib/backend/tauri");
+ const { acquireUpdateBarrier } = await import("@/lib/app/updatePreparation");
+ const release = acquireUpdateBarrier();
+ try {
+ await expect(loadOpenTabsState()).rejects.toThrow("Update preparation is in progress. Please wait.");
+ expect(mocks.invoke).not.toHaveBeenCalled();
+ } finally {
+ release();
+ }
+ });
+});