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
2 changes: 1 addition & 1 deletion ui/desktop/src/components/ChatInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -1239,7 +1239,7 @@ export default function ChatInput({
{/* Secondary actions and controls row below input */}
<div className="flex flex-row items-center gap-1 p-2 relative">
{/* Directory path */}
<DirSwitcher hasMessages={messages.length > 0} className="mr-0" />
<DirSwitcher className="mr-0" />
<div className="w-px h-4 bg-border-default mx-2" />

{/* Attach button */}
Expand Down
12 changes: 2 additions & 10 deletions ui/desktop/src/components/bottom_menu/DirSwitcher.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,14 @@ import { FolderDot } from 'lucide-react';
import { Tooltip, TooltipContent, TooltipProvider, TooltipTrigger } from '../ui/Tooltip';

interface DirSwitcherProps {
hasMessages?: boolean;
className?: string;
}

export const DirSwitcher: React.FC<DirSwitcherProps> = ({
hasMessages = false,
className = '',
}) => {
export const DirSwitcher: React.FC<DirSwitcherProps> = ({ className = '' }) => {
const [isTooltipOpen, setIsTooltipOpen] = useState(false);

const handleDirectoryChange = async () => {
if (hasMessages) {
window.electron.directoryChooser();
} else {
window.electron.directoryChooser(true);
}
window.electron.directoryChooser(true);
};

return (
Expand Down
52 changes: 52 additions & 0 deletions ui/desktop/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -944,8 +944,60 @@ const buildRecentFilesMenu = () => {
const openDirectoryDialog = async (
replaceWindow: boolean = false
): Promise<OpenDialogReturnValue> => {
// Get the current working directory from the focused window
let defaultPath: string | undefined;
const currentWindow = BrowserWindow.getFocusedWindow();

if (currentWindow) {
try {
const currentWorkingDir = await currentWindow.webContents.executeJavaScript(
`window.appConfig ? window.appConfig.get('GOOSE_WORKING_DIR') : null`
);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hmm, what's happening here? where does this working dir come from? is that what the server thinks it is?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah its set from the server when the session starts so it should match the server but this is just for the open file dialog so it really doesn't matter if it matches the server or not its just the default path that opens when the os directory browser shows


if (currentWorkingDir && typeof currentWorkingDir === 'string') {
// Verify the directory exists before using it as default
try {
const stats = fsSync.lstatSync(currentWorkingDir);
if (stats.isDirectory()) {
defaultPath = currentWorkingDir;
}
} catch (error) {
if (error && typeof error === 'object' && 'code' in error) {
const fsError = error as { code?: string; message?: string };
if (
fsError.code === 'ENOENT' ||
fsError.code === 'EACCES' ||
fsError.code === 'EPERM'
) {
console.warn(
`Current working directory not accessible (${fsError.code}): ${currentWorkingDir}, falling back to home directory`
);
defaultPath = os.homedir();
} else {
console.warn(
`Unexpected filesystem error (${fsError.code}) for directory ${currentWorkingDir}:`,
fsError.message
);
defaultPath = os.homedir();
}
} else {
console.warn(`Unexpected error checking directory ${currentWorkingDir}:`, error);
defaultPath = os.homedir();
}
}
}
} catch (error) {
console.warn('Failed to get current working directory from window:', error);
}
}

if (!defaultPath) {
defaultPath = os.homedir();
}

const result = (await dialog.showOpenDialog({
properties: ['openFile', 'openDirectory', 'createDirectory'],
defaultPath: defaultPath,
})) as unknown as OpenDialogReturnValue;

if (!result.canceled && result.filePaths.length > 0) {
Expand Down
Loading