diff --git a/src/features/app/__tests__/windows.test.ts b/src/features/app/__tests__/windows.test.ts index a7c8d1085..260777237 100644 --- a/src/features/app/__tests__/windows.test.ts +++ b/src/features/app/__tests__/windows.test.ts @@ -192,6 +192,20 @@ describe("replacing a project in this window", () => { expect(useProject.getState().project?.root).toBe("/local"); }); + it("asks about trust before leaving, so Don't Open keeps the current project running", async () => { + useProject.setState({ + ...projectState("/a"), + settings: { general: { openProjectIn: "same" } }, + } as never); + windowOpenProject.mockResolvedValue(ok({ kind: "current" })); + vi.mocked(confirmProjectTrust).mockRejectedValueOnce(new IpcError({ kind: "cancelled", message: "Cancelled" })); + await openProjectWithPolicy("/b"); + expect(confirmProjectTrust).toHaveBeenCalledWith("/b", "local"); + expect(confirmLeaveProject).not.toHaveBeenCalled(); + expect(openProject).not.toHaveBeenCalled(); + expect(notify).not.toHaveBeenCalled(); + }); + it("opens the local project when its path matches the remote root", async () => { useProject.setState({ ...projectState("/same"), @@ -792,11 +806,14 @@ describe("trust is asked before a new project window opens", () => { expect(windowOpenProject).toHaveBeenCalled(); }); - it("asks only once, from openProject, when the project opens in this window", async () => { + it("asks once this window takes the project, before leaving its current one", async () => { windowOpenProject.mockResolvedValue(ok({ kind: "current" })); await openProjectInWindow("/p/b", false); expect(windowOpenProject).toHaveBeenCalledWith("/p/b", false, []); - expect(confirmProjectTrust).not.toHaveBeenCalled(); + expect(confirmProjectTrust).toHaveBeenCalledOnce(); + expect(vi.mocked(confirmProjectTrust).mock.invocationCallOrder[0]).toBeLessThan( + vi.mocked(confirmLeaveProject).mock.invocationCallOrder[0]!, + ); expect(openProject).toHaveBeenCalledWith("/p/b"); }); }); diff --git a/src/features/app/windows.ts b/src/features/app/windows.ts index eff7843c8..7df38084d 100644 --- a/src/features/app/windows.ts +++ b/src/features/app/windows.ts @@ -57,6 +57,13 @@ async function openHere(path: string): Promise { if (!isRemoteWindow() && useProject.getState().project?.root === path) return true; // A folder of a WSL distro runs there, not as a network folder; the window then drops untitled buffers. const wsl = await commands.wslResolve(path).catch(() => null); + try { + // Asked before leaving, so Don't Open keeps the current project and its processes running. + if (!wsl) await confirmProjectTrust(path, "local"); + } catch (e) { + openFailed(path, e); + return false; + } if (!(await confirmLeaveProject(!wsl))) return false; try { if (wsl) await connectRemote(wsl.target, wsl.path); diff --git a/src/workbench/shellActions.ts b/src/workbench/shellActions.ts index 097555bd0..b2c9c9a87 100644 --- a/src/workbench/shellActions.ts +++ b/src/workbench/shellActions.ts @@ -1,6 +1,7 @@ import { showBackgroundTasks } from "./StatusBar"; import { executeAction, getAction, registerActions } from "@/platform/actions"; -import { isTauri } from "@/platform/ipc"; +import { isCancelled, isTauri } from "@/platform/ipc"; +import { confirmProjectTrust } from "@/platform/projectTrust"; import { closeProject, confirmLeaveProject, openProject, useProject } from "@/platform/project"; import { runSearchFieldCommand, showContextMenu } from "@/ui"; import { showCustomizeToolbar } from "./MainToolbarDialog"; @@ -32,10 +33,12 @@ export async function openProjectDialog() { await executeAction("file.openProjectPath", path); return; } - if (!(await confirmLeaveProject())) return; try { + await confirmProjectTrust(path, "local"); + if (!(await confirmLeaveProject())) return; await openProject(path); } catch (e) { + if (isCancelled(e)) return; notify({ level: "error", title: "Could not open project", body: e instanceof Error ? e.message : String(e) }); } }