refactor(database): unify database connections and add retry logic
Some checks failed
Frontend CI / build-and-push-web (push) Successful in 3m18s
Frontend CI / ota-android (push) Successful in 12m16s
Frontend CI / build-android-apk (push) Has been cancelled

Refactor LocalDataSource to reuse the shared database connection from database.ts, avoiding OPFS file handle conflicts. Add retry logic with exponential backoff for database open operations, particularly important for Web/OPFS environments. Also add dynamic theme support to chat input and message bubble styles, using theme colors instead of hardcoded values for better light/dark mode support.

BREAKING CHANGE: Database initialization now requires userId to be passed explicitly for user-specific databases
This commit is contained in:
lafay
2026-04-04 00:02:22 +08:00
parent e8651215f7
commit 775deeb9c4
7 changed files with 573 additions and 952 deletions

View File

@@ -258,11 +258,11 @@ export const useAuthStore = create<AuthState>((set) => ({
const savedUserId = await loadUserId();
if (savedUserId) {
// 2. 用已知的 userId 提前初始化 DB
// 2. 用已知的 userId 提前初始化 DB(数据库模块内部已处理重试)
try {
await initDatabase(savedUserId);
} catch (dbErr) {
console.warn('[AuthStore] DB 预初始化失败:', dbErr);
console.warn('[AuthStore] DB 预初始化失败,将尝试在 API 成功后重新初始化:', dbErr);
}
}