mirror of
https://github.com/farion1231/cc-switch.git
synced 2026-07-29 09:37:37 +08:00
feat(providers): seed an official preset on startup for Claude/Codex/Gemini
New and existing users now see a built-in "Claude Official" / "OpenAI Official" / "Google Official" entry in their provider list, so switching back to the official endpoint is one click away instead of buried in the README. - New providers_seed.rs holds the three seeds (id, name, settings_config, icon) keyed by AppType, with a single is_official_seed_id() helper that scans OFFICIAL_SEEDS so the id list has one source of truth. - Database::init_default_official_providers() runs once per database (gated by an official_providers_seeded setting flag), appends each seed to the end of the sort order, and never touches is_current. - Startup also auto-imports the live config (settings.json / auth.json / .env) as a "default" provider before seeding, so users with an existing manual config don't lose it when they click the official preset. - Database::has_non_official_seed_provider() replaces the get_all_providers call in import_default_config's gating check with an id-only scan, dropping the N+1 endpoint sub-queries from every startup.
This commit is contained in:
@@ -999,11 +999,12 @@ pub fn import_default_config(state: &AppState, app_type: AppType) -> Result<bool
|
||||
return Ok(false);
|
||||
}
|
||||
|
||||
{
|
||||
let providers = state.db.get_all_providers(app_type.as_str())?;
|
||||
if !providers.is_empty() {
|
||||
return Ok(false); // 已有供应商,跳过
|
||||
}
|
||||
// 允许 "只有官方 seed 预设" 的情况下继续导入 live:
|
||||
// - 启动编排顺序是先 import 后 seed,新用户启动时 providers 为空,导入照常
|
||||
// - 老用户已有非 seed provider,跳过导入(正确)
|
||||
// - 用户手动点 ProviderEmptyState 的导入按钮时,与官方 seed 共存而不被阻塞
|
||||
if state.db.has_non_official_seed_provider(app_type.as_str())? {
|
||||
return Ok(false);
|
||||
}
|
||||
|
||||
let settings_config = match app_type {
|
||||
|
||||
Reference in New Issue
Block a user