@@ -117,63 +117,75 @@ export function useWorkspaceManagement({
117117 workspaceId : string ,
118118 options ?: { force ?: boolean }
119119 ) : Promise < { success : boolean ; error ?: string } > => {
120- const result = await window . api . workspace . remove ( workspaceId , options ) ;
121- if ( result . success ) {
122- // Clean up workspace-specific localStorage keys
123- deleteWorkspaceStorage ( workspaceId ) ;
124-
125- // Backend has already updated the config - reload projects to get updated state
126- const projectsList = await window . api . projects . list ( ) ;
127- const loadedProjects = new Map < string , ProjectConfig > ( projectsList ) ;
128- onProjectsUpdate ( loadedProjects ) ;
129-
130- // Reload workspace metadata
131- await loadWorkspaceMetadata ( ) ;
132-
133- // Clear selected workspace if it was removed
134- if ( selectedWorkspace ?. workspaceId === workspaceId ) {
135- onSelectedWorkspaceUpdate ( null ) ;
120+ try {
121+ const result = await window . api . workspace . remove ( workspaceId , options ) ;
122+ if ( result . success ) {
123+ // Clean up workspace-specific localStorage keys
124+ deleteWorkspaceStorage ( workspaceId ) ;
125+
126+ // Backend has already updated the config - reload projects to get updated state
127+ const projectsList = await window . api . projects . list ( ) ;
128+ const loadedProjects = new Map < string , ProjectConfig > ( projectsList ) ;
129+ onProjectsUpdate ( loadedProjects ) ;
130+
131+ // Reload workspace metadata
132+ await loadWorkspaceMetadata ( ) ;
133+
134+ // Clear selected workspace if it was removed
135+ if ( selectedWorkspace ?. workspaceId === workspaceId ) {
136+ onSelectedWorkspaceUpdate ( null ) ;
137+ }
138+ return { success : true } ;
139+ } else {
140+ console . error ( "Failed to remove workspace:" , result . error ) ;
141+ return { success : false , error : result . error } ;
136142 }
137- return { success : true } ;
138- } else {
139- console . error ( "Failed to remove workspace:" , result . error ) ;
140- return { success : false , error : result . error } ;
143+ } catch ( error ) {
144+ const errorMessage = error instanceof Error ? error . message : String ( error ) ;
145+ console . error ( "Failed to remove workspace:" , errorMessage ) ;
146+ return { success : false , error : errorMessage } ;
141147 }
142148 } ,
143149 [ loadWorkspaceMetadata , onProjectsUpdate , onSelectedWorkspaceUpdate , selectedWorkspace ]
144150 ) ;
145151
146152 const renameWorkspace = useCallback (
147153 async ( workspaceId : string , newName : string ) : Promise < { success : boolean ; error ?: string } > => {
148- const result = await window . api . workspace . rename ( workspaceId , newName ) ;
149- if ( result . success ) {
150- // Backend has already updated the config - reload projects to get updated state
151- const projectsList = await window . api . projects . list ( ) ;
152- const loadedProjects = new Map < string , ProjectConfig > ( projectsList ) ;
153- onProjectsUpdate ( loadedProjects ) ;
154-
155- // Reload workspace metadata
156- await loadWorkspaceMetadata ( ) ;
157-
158- // Update selected workspace if it was renamed
159- if ( selectedWorkspace ?. workspaceId === workspaceId ) {
160- const newWorkspaceId = result . data . newWorkspaceId ;
161-
162- // Get updated workspace metadata from backend
163- const newMetadata = await window . api . workspace . getInfo ( newWorkspaceId ) ;
164- if ( newMetadata ) {
165- onSelectedWorkspaceUpdate ( {
166- projectPath : selectedWorkspace . projectPath ,
167- projectName : newMetadata . projectName ,
168- namedWorkspacePath : newMetadata . namedWorkspacePath ,
169- workspaceId : newWorkspaceId ,
170- } ) ;
154+ try {
155+ const result = await window . api . workspace . rename ( workspaceId , newName ) ;
156+ if ( result . success ) {
157+ // Backend has already updated the config - reload projects to get updated state
158+ const projectsList = await window . api . projects . list ( ) ;
159+ const loadedProjects = new Map < string , ProjectConfig > ( projectsList ) ;
160+ onProjectsUpdate ( loadedProjects ) ;
161+
162+ // Reload workspace metadata
163+ await loadWorkspaceMetadata ( ) ;
164+
165+ // Update selected workspace if it was renamed
166+ if ( selectedWorkspace ?. workspaceId === workspaceId ) {
167+ const newWorkspaceId = result . data . newWorkspaceId ;
168+
169+ // Get updated workspace metadata from backend
170+ const newMetadata = await window . api . workspace . getInfo ( newWorkspaceId ) ;
171+ if ( newMetadata ) {
172+ onSelectedWorkspaceUpdate ( {
173+ projectPath : selectedWorkspace . projectPath ,
174+ projectName : newMetadata . projectName ,
175+ namedWorkspacePath : newMetadata . namedWorkspacePath ,
176+ workspaceId : newWorkspaceId ,
177+ } ) ;
178+ }
171179 }
180+ return { success : true } ;
181+ } else {
182+ console . error ( "Failed to rename workspace:" , result . error ) ;
183+ return { success : false , error : result . error } ;
172184 }
173- return { success : true } ;
174- } else {
175- console . error ( "Failed to rename workspace:" , result . error ) ;
176- return { success : false , error : result . error } ;
185+ } catch ( error ) {
186+ const errorMessage = error instanceof Error ? error . message : String ( error ) ;
187+ console . error ( "Failed to rename workspace:" , errorMessage ) ;
188+ return { success : false , error : errorMessage } ;
177189 }
178190 } ,
179191 [ loadWorkspaceMetadata , onProjectsUpdate , onSelectedWorkspaceUpdate , selectedWorkspace ]
0 commit comments