refactor(provider): replace startup auto-import with manual import button

Remove the startup loop in lib.rs that auto-imported default providers
for Claude/Codex/Gemini. Move config snippet extraction logic into the
import_default_config command so it works when triggered manually.

Add an "Import Current Config" button to ProviderEmptyState, wired via
useMutation in ProviderList (shown only for standard apps). Update i18n
keys (zh/en/ja) with new button labels and revised empty state text.
This commit is contained in:
Jason
2026-02-20 22:01:18 +08:00
parent 5a72888852
commit 4c88174cb0
7 changed files with 81 additions and 59 deletions
+23 -1
View File
@@ -93,7 +93,29 @@ pub fn switch_provider(
}
fn import_default_config_internal(state: &AppState, app_type: AppType) -> Result<bool, AppError> {
ProviderService::import_default_config(state, app_type)
let imported = ProviderService::import_default_config(state, app_type.clone())?;
if imported {
// Extract common config snippet (mirrors old startup logic in lib.rs)
if state
.db
.get_config_snippet(app_type.as_str())
.ok()
.flatten()
.is_none()
{
match ProviderService::extract_common_config_snippet(state, app_type.clone()) {
Ok(snippet) if !snippet.is_empty() && snippet != "{}" => {
let _ = state
.db
.set_config_snippet(app_type.as_str(), Some(snippet));
}
_ => {}
}
}
}
Ok(imported)
}
#[cfg_attr(not(feature = "test-hooks"), doc(hidden))]