diff --git a/src-tauri/src/commands/window.rs b/src-tauri/src/commands/window.rs index 73f3d0be3..8c10c3158 100644 --- a/src-tauri/src/commands/window.rs +++ b/src-tauri/src/commands/window.rs @@ -199,6 +199,8 @@ pub struct OpenProject { pub root: PathBuf, /// Open in the calling window. pub current: bool, + /// Where the project lives when the window is connected to a remote host (`root` is then a path there). + pub remote: Option, } /// Projects open in project windows, in window order (title bar project widget). @@ -212,11 +214,19 @@ pub fn window_open_projects( Ok(windows::project_window_labels(&app) .into_iter() .filter_map(|label| { + let current = label == window.label(); + // A remote window's project lives on the server: it has no local project here. + if let Some(c) = state.remote_dev.get(&label) { + let root = PathBuf::from(&c.root); + let name = c.root.trim_end_matches('/').rsplit('/').next().unwrap_or_default().to_owned(); + return Some(OpenProject { name, root, current, remote: Some(c.target.clone()) }); + } let project = state.project(&label).ok().filter(|p| !p.light)?; Some(OpenProject { name: project.root.file_name().map(|n| n.to_string_lossy().into_owned()).unwrap_or_default(), root: project.root.clone(), - current: label == window.label(), + current, + remote: None, }) }) .collect()) diff --git a/src/bindings.ts b/src/bindings.ts index 6c45f205b..1a5f1db47 100644 --- a/src/bindings.ts +++ b/src/bindings.ts @@ -8426,6 +8426,8 @@ export type OpenProject = { root: string, /** Open in the calling window. */ current: boolean, + /** Where the project lives when the window is connected to a remote host (`root` is then a path there). */ + remote: RemoteTarget | null, }; /** A node of a document outline (Structure tool window, breadcrumbs). */ diff --git a/src/features/welcome/ProjectPopup.test.tsx b/src/features/welcome/ProjectPopup.test.tsx new file mode 100644 index 000000000..9b1cb9a35 --- /dev/null +++ b/src/features/welcome/ProjectPopup.test.tsx @@ -0,0 +1,59 @@ +import { describe, expect, it, vi } from "vitest"; +import { createRef } from "react"; +import { render, screen, within } from "@testing-library/react"; +import type { OpenProject, RecentProject } from "@/platform/ipc"; +import { remoteLocation } from "@/platform/remote"; + +const wsl = { kind: "wsl", distro: "Ubuntu-24.04" } as const; +let open: OpenProject[] = []; +let recent: RecentProject[] = []; + +vi.mock("@/platform/ipc", async (importOriginal) => { + const real = await importOriginal(); + return { + ...real, + isTauri: () => true, + commands: { + ...real.commands, + recentProjects: async () => recent, + recentProjectGroups: async () => [], + windowOpenProjects: async () => ({ status: "ok", data: open }), + }, + }; +}); +vi.mock("@tauri-apps/api/path", () => ({ homeDir: async () => "/Users/me" })); + +import { ProjectPopup } from "./ProjectPopup"; + +describe("ProjectPopup", () => { + it("lists remote windows under Open Projects, not again under Recent Projects", async () => { + open = [ + { name: "FastAPIProject", root: "/root/projetos/FastAPIProject", current: true, remote: wsl }, + { name: "datahub-front", root: "/root/projetos/datahub-front", current: false, remote: wsl }, + ]; + recent = [ + { + path: remoteLocation(wsl, "/root/projetos/FastAPIProject"), + name: "FastAPIProject", + openedAtMs: 2, + branch: null, + }, + { path: remoteLocation(wsl, "/root/projetos/datahub-front"), name: "datahub-front", openedAtMs: 1, branch: null }, + { path: remoteLocation(wsl, "/root/projetos/other"), name: "other", openedAtMs: 0, branch: null }, + ]; + const anchor = createRef(); + render( + <> +