()
| 20 | |
| 21 | // 初始化账户系统 |
| 22 | export async function initializeAccountSystem(): Promise<void> { |
| 23 | const { account } = stores |
| 24 | |
| 25 | // 初始化持久化层(确保 appDataPath 已初始化) |
| 26 | await persistence.database.init() |
| 27 | |
| 28 | // 初始化账户 store |
| 29 | await account.init() |
| 30 | |
| 31 | // 如果没有账户,创建默认账户 |
| 32 | if (account.accounts.length === 0) { |
| 33 | const defaultAccount = createDefaultAccount() |
| 34 | await account.create({ |
| 35 | id: defaultAccount.id, |
| 36 | name: defaultAccount.name, |
| 37 | avatar: defaultAccount.avatar |
| 38 | }) |
| 39 | await account.setCurrentAccountId(defaultAccount.id) |
| 40 | } |
| 41 | |
| 42 | // 如果没有当前账户,设置为第一个账户 |
| 43 | if (!account.currentAccountId && account.accounts.length > 0) { |
| 44 | await account.setCurrentAccountId(account.accounts[0].id) |
| 45 | } |
| 46 | |
| 47 | // 设置当前账户路径 |
| 48 | const accountId = account.currentAccountId || getDefaultAccountId() |
| 49 | await persistence.database.commitContext({ |
| 50 | accountId, |
| 51 | workspacePath: null |
| 52 | }) |
| 53 | |
| 54 | // 初始化账户级 stores |
| 55 | await initAccountStores() |
| 56 | |
| 57 | // 初始化工作区系统 |
| 58 | await initializeWorkspaceSystem() |
| 59 | |
| 60 | account.setInitialized(true) |
| 61 | } |
| 62 | |
| 63 | // 切换账户 |
| 64 | export async function switchAccount(accountId: string): Promise<void> { |
no test coverage detected