mirror of
https://github.com/l0ng-ai/openidea.git
synced 2026-11-24 16:04:21 +00:00
fix(project): ask about trust before leaving the current project (#4253)
Opening a folder in this window confirmed leaving the current project (which stops its running processes) before the trust prompt, so Don't Open left the original project without its processes. Trust is now asked first; the fallback open path follows the same order. Fixes #4160.
This commit is contained in:
@@ -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");
|
||||
});
|
||||
});
|
||||
|
||||
@@ -57,6 +57,13 @@ async function openHere(path: string): Promise<boolean> {
|
||||
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);
|
||||
|
||||
@@ -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) });
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user