mirror of
https://github.com/farion1231/cc-switch.git
synced 2026-08-04 11:43:57 +08:00
refactor(startup): improve first-launch import logic with per-table detection
- Replace global `is_empty_for_first_import()` with independent checks: - `is_mcp_table_empty()` for MCP server imports - `is_prompts_table_empty()` for prompt imports - Skills and providers already have built-in idempotency checks - Fix misleading logs in provider import: - Change `import_default_config` return type from `Result<()>` to `Result<bool>` - Return `true` when actually imported, `false` when skipped - Only log success message when import actually occurred - Add idempotency protection to `import_from_file_on_first_launch` This allows each data type to be independently recovered if deleted, rather than requiring all tables to be empty for any import to trigger.
This commit is contained in:
@@ -86,7 +86,7 @@ pub fn switch_provider(
|
||||
.map_err(|e| e.to_string())
|
||||
}
|
||||
|
||||
fn import_default_config_internal(state: &AppState, app_type: AppType) -> Result<(), AppError> {
|
||||
fn import_default_config_internal(state: &AppState, app_type: AppType) -> Result<bool, AppError> {
|
||||
ProviderService::import_default_config(state, app_type)
|
||||
}
|
||||
|
||||
@@ -94,7 +94,7 @@ fn import_default_config_internal(state: &AppState, app_type: AppType) -> Result
|
||||
pub fn import_default_config_test_hook(
|
||||
state: &AppState,
|
||||
app_type: AppType,
|
||||
) -> Result<(), AppError> {
|
||||
) -> Result<bool, AppError> {
|
||||
import_default_config_internal(state, app_type)
|
||||
}
|
||||
|
||||
@@ -102,9 +102,7 @@ pub fn import_default_config_test_hook(
|
||||
#[tauri::command]
|
||||
pub fn import_default_config(state: State<'_, AppState>, app: String) -> Result<bool, String> {
|
||||
let app_type = AppType::from_str(&app).map_err(|e| e.to_string())?;
|
||||
import_default_config_internal(&state, app_type)
|
||||
.map(|_| true)
|
||||
.map_err(Into::into)
|
||||
import_default_config_internal(&state, app_type).map_err(Into::into)
|
||||
}
|
||||
|
||||
/// 查询供应商用量
|
||||
|
||||
Reference in New Issue
Block a user