mirror of
https://github.com/block/goose.git
synced 2026-07-17 12:56:20 +02:00
Fix directory switcher not working in active chat sessions and file browser not defaulting to current session directory path (#3791)
This commit is contained in:
@@ -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 */}
|
||||
|
||||
@@ -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 (
|
||||
|
||||
@@ -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`
|
||||
);
|
||||
|
||||
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) {
|
||||
|
||||
Reference in New Issue
Block a user