(workspaceId: string)
| 197 | * 注意:只从列表中移除,不删除文件 |
| 198 | */ |
| 199 | export async function deleteWorkspace(workspaceId: string): Promise<void> { |
| 200 | const { workspace } = stores |
| 201 | |
| 202 | const targetWorkspace = await workspace.getById(workspaceId) |
| 203 | if (!targetWorkspace) { |
| 204 | throw new Error(`Workspace not found: ${workspaceId}`) |
| 205 | } |
| 206 | |
| 207 | // 不能删除默认工作区 |
| 208 | if (targetWorkspace.type === 'default') { |
| 209 | throw new Error('Cannot delete default workspace') |
| 210 | } |
| 211 | |
| 212 | // 如果删除的是当前工作区,切换到默认工作区 |
| 213 | if (workspace.currentWorkspaceId === workspaceId) { |
| 214 | const defaultWs = workspace.workspaces.find((w) => w.type === 'default') |
| 215 | if (defaultWs) { |
| 216 | await switchWorkspace(defaultWs.id) |
| 217 | } |
| 218 | } |
| 219 | |
| 220 | await workspace.delete(workspaceId) |
| 221 | const activeContext = persistence.database.getActiveContext() |
| 222 | if (!activeContext.accountId) { |
| 223 | throw new Error('No active account context') |
| 224 | } |
| 225 | await commitWorkspaceContext(activeContext.accountId, activeContext.workspacePath) |
| 226 | } |
| 227 | |
| 228 | /** |
| 229 | * 获取当前工作区 |
no test coverage detected