From f6738ff26cc9aa2b360b4562e3c39bba5476de4b Mon Sep 17 00:00:00 2001 From: Kacper Date: Fri, 9 Jan 2026 00:04:28 +0100 Subject: [PATCH] fix: update getDefaultDocumentsPath to use window.electronAPI for Electron mode - Removed dependency on getElectronAPI and directly accessed window.electronAPI for retrieving the documents path in Electron mode. - Added handling for web mode to return null when the documents path cannot be accessed. - Included logging for the resolved documents path to aid in debugging. --- apps/ui/src/lib/workspace-config.ts | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/apps/ui/src/lib/workspace-config.ts b/apps/ui/src/lib/workspace-config.ts index d92bd671..e1d32837 100644 --- a/apps/ui/src/lib/workspace-config.ts +++ b/apps/ui/src/lib/workspace-config.ts @@ -5,7 +5,6 @@ import { createLogger } from '@automaker/utils/logger'; import { getHttpApiClient } from './http-api-client'; -import { getElectronAPI } from './electron'; import { useAppStore } from '@/store/app-store'; const logger = createLogger('WorkspaceConfig'); @@ -33,9 +32,17 @@ function joinPath(...parts: string[]): string { */ async function getDefaultDocumentsPath(): Promise { try { - const api = getElectronAPI(); - const documentsPath = await api.getPath('documents'); - return joinPath(documentsPath, 'Automaker'); + // In Electron mode, use the native getPath API directly from the preload script + // This returns the actual system Documents folder (e.g., C:\Users\\Documents on Windows) + // Note: The HTTP client's getPath returns incorrect Unix-style paths for 'documents' + if (typeof window !== 'undefined' && (window as any).electronAPI?.getPath) { + const documentsPath = await (window as any).electronAPI.getPath('documents'); + return joinPath(documentsPath, 'Automaker'); + } + + // In web mode (no Electron), we can't access the user's Documents folder + // Return null to let the caller use other fallback mechanisms (like server's DATA_DIR) + return null; } catch (error) { logger.error('Failed to get documents path:', error); return null; @@ -76,6 +83,7 @@ export async function getDefaultWorkspaceDirectory(): Promise { // Try to get Documents/Automaker const documentsPath = await getDefaultDocumentsPath(); + logger.info('Default documentsPath resolved to:', documentsPath); if (documentsPath) { return documentsPath; }