()
| 72 | * 在账户初始化后调用 |
| 73 | */ |
| 74 | export async function initializeWorkspaceSystem(): Promise<void> { |
| 75 | const { workspace } = stores |
| 76 | |
| 77 | // 初始化工作区 store |
| 78 | await workspace.init() |
| 79 | |
| 80 | // 如果没有工作区,创建默认工作区 |
| 81 | if (workspace.workspaces.length === 0) { |
| 82 | const defaultWorkspace = await workspace.initDefaultWorkspace() |
| 83 | await workspace.setCurrentWorkspaceId(defaultWorkspace.id) |
| 84 | } |
| 85 | |
| 86 | // 如果没有当前工作区,设置为第一个工作区 |
| 87 | if (!workspace.currentWorkspaceId && workspace.workspaces.length > 0) { |
| 88 | await workspace.setCurrentWorkspaceId(workspace.workspaces[0].id) |
| 89 | } |
| 90 | |
| 91 | if (workspace.currentWorkspace) { |
| 92 | await commitWorkspaceContext(workspace.currentWorkspace.accountId, workspace.currentWorkspace.path) |
| 93 | } else { |
| 94 | const accountId = persistence.database.getActiveContext().accountId |
| 95 | if (!accountId) { |
| 96 | throw new Error('No active account context') |
| 97 | } |
| 98 | await commitWorkspaceContext(accountId, null) |
| 99 | } |
| 100 | await cleanupWorkspaceTempAttachments() |
| 101 | |
| 102 | // 初始化工作区级 stores |
| 103 | await initWorkspaceStores() |
| 104 | } |
| 105 | |
| 106 | // ==================== 工作区切换 ==================== |
| 107 |
no test coverage detected