mirror of
https://github.com/AutoMaker-Org/automaker.git
synced 2026-01-31 06:42:03 +00:00
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.
This commit is contained in:
@@ -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<string | null> {
|
||||
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\<user>\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<string | null> {
|
||||
|
||||
// Try to get Documents/Automaker
|
||||
const documentsPath = await getDefaultDocumentsPath();
|
||||
logger.info('Default documentsPath resolved to:', documentsPath);
|
||||
if (documentsPath) {
|
||||
return documentsPath;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user