feat(migration): enable silent JSON to SQLite migration with toast notification

- Remove environment variable feature gate (CC_SWITCH_ENABLE_JSON_DB_MIGRATION)
- Automatically migrate config.json to SQLite when db doesn't exist
- Archive migrated config.json as config.json.migrated for recovery
- Add migration success flag in init_status.rs (one-time consumption)
- Add get_migration_result command for frontend to query
- Show toast notification on successful migration in App.tsx
This commit is contained in:
Jason
2025-11-25 16:07:54 +08:00
parent 014a7c0e30
commit 2526dbc58f
4 changed files with 72 additions and 53 deletions

View File

@@ -1,6 +1,7 @@
import { useEffect, useMemo, useState, useRef } from "react";
import { useTranslation } from "react-i18next";
import { toast } from "sonner";
import { invoke } from "@tauri-apps/api/core";
import {
Plus,
Settings,
@@ -123,6 +124,24 @@ function App() {
checkEnvOnStartup();
}, []);
// 应用启动时检查是否刚完成了配置迁移
useEffect(() => {
const checkMigration = async () => {
try {
const migrated = await invoke<boolean>("get_migration_result");
if (migrated) {
toast.success(
t("migration.success", { defaultValue: "配置迁移成功" }),
);
}
} catch (error) {
console.error("[App] Failed to check migration result:", error);
}
};
checkMigration();
}, [t]);
// 切换应用时检测当前应用的环境变量冲突
useEffect(() => {
const checkEnvOnSwitch = async () => {