mirror of
https://github.com/farion1231/cc-switch.git
synced 2026-05-03 09:31:48 +08:00
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:
19
src/App.tsx
19
src/App.tsx
@@ -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 () => {
|
||||
|
||||
Reference in New Issue
Block a user