()
| 62 | } |
| 63 | |
| 64 | export function setupFileSystemHandlers(): void { |
| 65 | // 获取应用数据目录 |
| 66 | ipcMain.handle('fs:get-app-data-path', () => { |
| 67 | return getAppDataPath() |
| 68 | }) |
| 69 | |
| 70 | ipcMain.handle('fs:sync-workspace-access', (_event, context: WorkspaceAccessContext) => { |
| 71 | syncWorkspaceAccessContext(context) |
| 72 | }) |
| 73 | |
| 74 | ipcMain.handle('fs:approve-workspace-path', (_event, workspacePath: string) => { |
| 75 | approveWorkspacePath(workspacePath) |
| 76 | }) |
| 77 | |
| 78 | // 选择目录 |
| 79 | ipcMain.handle( |
| 80 | 'fs:select-directory', |
| 81 | async ( |
| 82 | _event, |
| 83 | options?: { |
| 84 | title?: string |
| 85 | defaultPath?: string |
| 86 | } |
| 87 | ) => { |
| 88 | try { |
| 89 | const result = await dialog.showOpenDialog({ |
| 90 | title: options?.title || '选择目录', |
| 91 | defaultPath: options?.defaultPath, |
| 92 | properties: ['openDirectory', 'createDirectory'] |
| 93 | }) |
| 94 | |
| 95 | if (!result.canceled && result.filePaths[0]) { |
| 96 | approveWorkspacePath(result.filePaths[0]) |
| 97 | } |
| 98 | |
| 99 | return { |
| 100 | success: !result.canceled, |
| 101 | cancelled: result.canceled, |
| 102 | path: result.filePaths[0] |
| 103 | } |
| 104 | } catch (error) { |
| 105 | console.error('Select directory error:', error) |
| 106 | return { |
| 107 | success: false, |
| 108 | error: error instanceof Error ? error.message : '未知错误' |
| 109 | } |
| 110 | } |
| 111 | } |
| 112 | ) |
| 113 | |
| 114 | // 读取文本文件 |
| 115 | ipcMain.handle( |
| 116 | 'fs:read-text', |
| 117 | async ( |
| 118 | _event, |
| 119 | filePath: string, |
| 120 | options?: { allowCustomPath?: boolean } |
| 121 | ): Promise<{ success: boolean; content?: string; error?: string }> => { |
no test coverage detected