Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions src-tauri/src/bin/codex_monitor_daemon.rs
Original file line number Diff line number Diff line change
Expand Up @@ -126,12 +126,20 @@ impl DaemonState {
result
}

async fn is_workspace_path_dir(&self, path: String) -> bool {
PathBuf::from(&path).is_dir()
}

async fn add_workspace(
&self,
path: String,
codex_bin: Option<String>,
client_version: String,
) -> Result<WorkspaceInfo, String> {
if !PathBuf::from(&path).is_dir() {
return Err("Workspace path must be a folder.".to_string());
}

let name = PathBuf::from(&path)
.file_name()
.and_then(|s| s.to_str())
Expand Down Expand Up @@ -1499,6 +1507,11 @@ async fn handle_rpc_request(
let workspaces = state.list_workspaces().await;
serde_json::to_value(workspaces).map_err(|err| err.to_string())
}
"is_workspace_path_dir" => {
let path = parse_string(&params, "path")?;
let is_dir = state.is_workspace_path_dir(path).await;
serde_json::to_value(is_dir).map_err(|err| err.to_string())
}
"add_workspace" => {
let path = parse_string(&params, "path")?;
let codex_bin = parse_optional_string(&params, "codex_bin");
Expand Down
1 change: 1 addition & 0 deletions src-tauri/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ pub fn run() {
menu::menu_set_accelerators,
codex::codex_doctor,
workspaces::list_workspaces,
workspaces::is_workspace_path_dir,
workspaces::add_workspace,
workspaces::add_clone,
workspaces::add_worktree,
Expand Down
23 changes: 23 additions & 0 deletions src-tauri/src/workspaces.rs
Original file line number Diff line number Diff line change
Expand Up @@ -415,6 +415,25 @@ pub(crate) async fn list_workspaces(
Ok(result)
}

#[tauri::command]
pub(crate) async fn is_workspace_path_dir(
path: String,
state: State<'_, AppState>,
app: AppHandle,
) -> Result<bool, String> {
if remote_backend::is_remote_mode(&*state).await {
let response = remote_backend::call_remote(
&*state,
app,
"is_workspace_path_dir",
json!({ "path": path }),
)
.await?;
return serde_json::from_value(response).map_err(|err| err.to_string());
}
Ok(PathBuf::from(&path).is_dir())
}

#[tauri::command]
pub(crate) async fn add_workspace(
path: String,
Expand All @@ -433,6 +452,10 @@ pub(crate) async fn add_workspace(
return serde_json::from_value(response).map_err(|err| err.to_string());
}

if !PathBuf::from(&path).is_dir() {
return Err("Workspace path must be a folder.".to_string());
}

let name = PathBuf::from(&path)
.file_name()
.and_then(|s| s.to_str())
Expand Down
2 changes: 1 addition & 1 deletion src-tauri/tauri.conf.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"height": 700,
"minWidth": 360,
"minHeight": 600,
"dragDropEnabled": false,
"dragDropEnabled": true,
"titleBarStyle": "Overlay",
"hiddenTitle": true,
"transparent": true,
Expand Down
39 changes: 39 additions & 0 deletions src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import { AppLayout } from "./features/app/components/AppLayout";
import { AppModals } from "./features/app/components/AppModals";
import { MainHeaderActions } from "./features/app/components/MainHeaderActions";
import { useLayoutNodes } from "./features/layout/hooks/useLayoutNodes";
import { useWorkspaceDropZone } from "./features/workspaces/hooks/useWorkspaceDropZone";
import { useThreads } from "./features/threads/hooks/useThreads";
import { useWindowDrag } from "./features/layout/hooks/useWindowDrag";
import { useGitPanelController } from "./features/app/hooks/useGitPanelController";
Expand Down Expand Up @@ -154,6 +155,7 @@ function MainApp() {
activeWorkspaceId,
setActiveWorkspaceId,
addWorkspace,
addWorkspaceFromPath,
addCloneAgent,
addWorktreeAgent,
connectWorkspace,
Expand Down Expand Up @@ -1040,13 +1042,15 @@ function MainApp() {

const {
handleAddWorkspace,
handleAddWorkspaceFromPath,
handleAddAgent,
handleAddWorktreeAgent,
handleAddCloneAgent,
} = useWorkspaceActions({
activeWorkspace,
isCompact,
addWorkspace,
addWorkspaceFromPath,
connectWorkspace,
startThreadForWorkspace,
setActiveThreadId,
Expand All @@ -1059,6 +1063,32 @@ function MainApp() {
onDebug: addDebugEntry,
});

const handleDropWorkspacePaths = useCallback(
async (paths: string[]) => {
const uniquePaths = Array.from(
new Set(paths.filter((path) => path.length > 0)),
);
if (uniquePaths.length === 0) {
return;
}
uniquePaths.forEach((path) => {
void handleAddWorkspaceFromPath(path);
});
},
[handleAddWorkspaceFromPath],
);

const {
dropTargetRef: workspaceDropTargetRef,
isDragOver: isWorkspaceDropActive,
handleDragOver: handleWorkspaceDragOver,
handleDragEnter: handleWorkspaceDragEnter,
handleDragLeave: handleWorkspaceDragLeave,
handleDrop: handleWorkspaceDrop,
} = useWorkspaceDropZone({
onDropPaths: handleDropWorkspacePaths,
});

const {
handleSelectPullRequest,
resetPullRequestSelection,
Expand Down Expand Up @@ -1201,6 +1231,8 @@ function MainApp() {
useMenuAcceleratorController({ appSettings, onDebug: addDebugEntry });

const isDefaultScale = Math.abs(uiScale - 1) < 0.001;
const dropOverlayActive = isWorkspaceDropActive;
const dropOverlayText = "Drop Project Here";
const appClassName = `app ${isCompact ? "layout-compact" : "layout-desktop"}${
isPhone ? " layout-phone" : ""
}${isTablet ? " layout-tablet" : ""}${
Expand Down Expand Up @@ -1550,6 +1582,13 @@ function MainApp() {
setCenterMode("chat");
},
onGoProjects: () => setActiveTab("projects"),
workspaceDropTargetRef,
isWorkspaceDropActive: dropOverlayActive,
workspaceDropText: dropOverlayText,
onWorkspaceDragOver: handleWorkspaceDragOver,
onWorkspaceDragEnter: handleWorkspaceDragEnter,
onWorkspaceDragLeave: handleWorkspaceDragLeave,
onWorkspaceDrop: handleWorkspaceDrop,
});

const desktopTopbarLeftNodeWithToggle = !isCompact ? (
Expand Down
42 changes: 41 additions & 1 deletion src/features/app/components/Sidebar.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import type { RateLimitSnapshot, ThreadSummary, WorkspaceInfo } from "../../../types";
import { createPortal } from "react-dom";
import { useCallback, useEffect, useMemo, useRef, useState } from "react";
import type { RefObject } from "react";
import { FolderOpen } from "lucide-react";
import { SidebarCornerActions } from "./SidebarCornerActions";
import { SidebarFooter } from "./SidebarFooter";
import { SidebarHeader } from "./SidebarHeader";
Expand Down Expand Up @@ -67,6 +69,13 @@ type SidebarProps = {
onDeleteWorktree: (workspaceId: string) => void;
onLoadOlderThreads: (workspaceId: string) => void;
onReloadWorkspaceThreads: (workspaceId: string) => void;
workspaceDropTargetRef: RefObject<HTMLElement | null>;
isWorkspaceDropActive: boolean;
workspaceDropText: string;
onWorkspaceDragOver: (event: React.DragEvent<HTMLElement>) => void;
onWorkspaceDragEnter: (event: React.DragEvent<HTMLElement>) => void;
onWorkspaceDragLeave: (event: React.DragEvent<HTMLElement>) => void;
onWorkspaceDrop: (event: React.DragEvent<HTMLElement>) => void;
};

export function Sidebar({
Expand Down Expand Up @@ -106,6 +115,13 @@ export function Sidebar({
onDeleteWorktree,
onLoadOlderThreads,
onReloadWorkspaceThreads,
workspaceDropTargetRef,
isWorkspaceDropActive,
workspaceDropText,
onWorkspaceDragOver,
onWorkspaceDragEnter,
onWorkspaceDragLeave,
onWorkspaceDrop,
}: SidebarProps) {
const [expandedWorkspaces, setExpandedWorkspaces] = useState(
new Set<string>(),
Expand Down Expand Up @@ -264,8 +280,32 @@ export function Sidebar({
}, [addMenuAnchor]);

return (
<aside className="sidebar">
<aside
className="sidebar"
ref={workspaceDropTargetRef}
onDragOver={onWorkspaceDragOver}
onDragEnter={onWorkspaceDragEnter}
onDragLeave={onWorkspaceDragLeave}
onDrop={onWorkspaceDrop}
>
<SidebarHeader onSelectHome={onSelectHome} onAddWorkspace={onAddWorkspace} />
<div
className={`workspace-drop-overlay${
isWorkspaceDropActive ? " is-active" : ""
}`}
aria-hidden
>
<div
className={`workspace-drop-overlay-text${
workspaceDropText === "Adding Project..." ? " is-busy" : ""
}`}
>
{workspaceDropText === "Drop Project Here" && (
<FolderOpen className="workspace-drop-overlay-icon" aria-hidden />
)}
{workspaceDropText}
</div>
</div>
<div
className={`sidebar-body${scrollFade.top ? " fade-top" : ""}${
scrollFade.bottom ? " fade-bottom" : ""
Expand Down
42 changes: 37 additions & 5 deletions src/features/app/hooks/useWorkspaceActions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ type Params = {
activeWorkspace: WorkspaceInfo | null;
isCompact: boolean;
addWorkspace: () => Promise<WorkspaceInfo | null>;
addWorkspaceFromPath: (path: string) => Promise<WorkspaceInfo | null>;
connectWorkspace: (workspace: WorkspaceInfo) => Promise<void>;
startThreadForWorkspace: (workspaceId: string) => Promise<string | null>;
setActiveThreadId: (threadId: string | null, workspaceId: string) => void;
Expand All @@ -23,6 +24,7 @@ export function useWorkspaceActions({
activeWorkspace,
isCompact,
addWorkspace,
addWorkspaceFromPath,
connectWorkspace,
startThreadForWorkspace,
setActiveThreadId,
Expand All @@ -34,14 +36,21 @@ export function useWorkspaceActions({
composerInputRef,
onDebug,
}: Params) {
const handleWorkspaceAdded = useCallback(
(workspace: WorkspaceInfo) => {
setActiveThreadId(null, workspace.id);
if (isCompact) {
setActiveTab("codex");
}
},
[isCompact, setActiveTab, setActiveThreadId],
);

const handleAddWorkspace = useCallback(async () => {
try {
const workspace = await addWorkspace();
if (workspace) {
setActiveThreadId(null, workspace.id);
if (isCompact) {
setActiveTab("codex");
}
handleWorkspaceAdded(workspace);
}
} catch (error) {
const message = error instanceof Error ? error.message : String(error);
Expand All @@ -54,7 +63,29 @@ export function useWorkspaceActions({
});
alert(`Failed to add workspace.\n\n${message}`);
}
}, [addWorkspace, isCompact, onDebug, setActiveTab, setActiveThreadId]);
}, [addWorkspace, handleWorkspaceAdded, onDebug]);

const handleAddWorkspaceFromPath = useCallback(
async (path: string) => {
try {
const workspace = await addWorkspaceFromPath(path);
if (workspace) {
handleWorkspaceAdded(workspace);
}
} catch (error) {
const message = error instanceof Error ? error.message : String(error);
onDebug({
id: `${Date.now()}-client-add-workspace-error`,
timestamp: Date.now(),
source: "error",
label: "workspace/add error",
payload: message,
});
alert(`Failed to add workspace.\n\n${message}`);
}
},
[addWorkspaceFromPath, handleWorkspaceAdded, onDebug],
);

const handleAddAgent = useCallback(
async (workspace: WorkspaceInfo) => {
Expand Down Expand Up @@ -107,6 +138,7 @@ export function useWorkspaceActions({

return {
handleAddWorkspace,
handleAddWorkspaceFromPath,
handleAddAgent,
handleAddWorktreeAgent,
handleAddCloneAgent,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,8 @@ import { describe, expect, it, vi } from "vitest";
import { useComposerImages } from "../hooks/useComposerImages";
import { ComposerInput } from "./ComposerInput";

vi.mock("@tauri-apps/api/window", () => ({
getCurrentWindow: () => ({
onDragDropEvent: vi.fn().mockResolvedValue(() => {}),
}),
vi.mock("../../../services/dragDrop", () => ({
subscribeWindowDragDrop: vi.fn(() => () => {}),
}));

vi.mock("@tauri-apps/api/core", () => ({
Expand Down
14 changes: 6 additions & 8 deletions src/features/composer/hooks/useComposerImageDrop.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,16 @@ let mockOnDragDropEvent:
payload: {
type: "enter" | "over" | "leave" | "drop";
position: { x: number; y: number };
paths: string[];
paths?: string[];
};
}) => void)
| null = null;

vi.mock("@tauri-apps/api/window", () => ({
getCurrentWindow: () => ({
onDragDropEvent: (handler: typeof mockOnDragDropEvent) => {
mockOnDragDropEvent = handler;
return Promise.resolve(() => {});
},
}),
vi.mock("../../../services/dragDrop", () => ({
subscribeWindowDragDrop: (handler: typeof mockOnDragDropEvent) => {
mockOnDragDropEvent = handler;
return () => {};
},
}));

type HookResult = ReturnType<typeof useComposerImageDrop>;
Expand Down
Loading